【架构优化】从 Engine.applyObservation 中拆出节点活动文案推导 observationActivity

Aperta
#453 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@fx-kurumi ci sta già lavorando.

Dal 13/11/2026.

  • #456 di @fx-kurumi — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
15/100
Tipo di issue
Refactoring
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
go
Ambito
backend

Direzione di ricerca

The activity-text switch sits inside Engine.applyObservation in internal/engine/engine_observe.go; start by reading that switch and the branches the issue lists. Move it unchanged into a package-level observationActivity function and add a table-driven test file in the same package. Done means gofmt, go vet ./internal/engine/ and go test ./internal/engine/ pass. Note that PR #456 is already open against this issue, so the work is claimed.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

现状问题

internal/engine/engine_observe.go 中 Engine.applyObservation 约 120 行,同时负责:幂等去重、字段补全、日志记录、节点属性回填、节点活动文案推导、工具调用计数、用量累计、遥测合并与截断。

其中根据 observation.Category/Name/Phase/Level 推导节点 Activity 文案的 switch 有 6 个分支、约 35 行,内含多层嵌套(tool/sandbox 分支在某些条件下不更新文案,process 分支要拼接 provider/model 标签),是一段纯计算逻辑却嵌在有副作用的大函数里,目前也没有直接的单元测试。

重构方案

  • 把该 switch 原样抽成包级纯函数 observationActivity(observation domain.TelemetryEvent) (string, bool),返回新的活动文案以及是否需要更新(对应原来 tool 非匹配、sandbox.closed 不更新文案的情形)。
  • applyObservation 中改为:if activity, ok := observationActivity(observation); ok { nr.Activity = activity }。
  • 分支逻辑、文案逐字不变,不改其它代码。

影响范围

仅 internal/engine/engine_observe.go 一个函数内部,加一个新测试文件;无对外接口、无行为变化。

验证方式

  • 新增表驱动单测覆盖每个分支(reasoning/output/tool 开始、结束、结束报错/sandbox 普通与 closed/process.started 含与不含 provider、model/其它 process/default 有无 message)。
  • gofmt、go vet ./internal/engine/、go test ./internal/engine/ 通过。
Lingua principale
Go
Stelle
141
Fork
28
Merge medio
1g 15h
PR unite (30g)
113

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di Tencent/LoopForge

Tutte le issue di Tencent/LoopForge

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.