Skip to content

fix(trace): 评估运行的 trace input 不再回退成 answer - #161

Open
wxrbyte wants to merge 1 commit into
helsome:mainfrom
wxrbyte:codex/fix-trace-input-projection
Open

wxrbyte wants to merge 1 commit into
helsome:mainfrom
wxrbyte:codex/fix-trace-input-projection

Conversation

@wxrbyte

@wxrbyte wxrbyte commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

问题

projectTrace()packages/core/src/trace-projection.ts)组装 FolioTrace.input 时:

input: run?.input ?? evaluationRun?.answer ?? ''

EvaluationRunpackages/core/src/evaluation.ts)没有 input 字段——评估运行的输入
在 benchmark case 的 input.prompt 里。于是评估类 trace 把 agent 的输出当成
输入投影出去。

实际 / 预期

projectTrace({ evaluationRun, evaluationCase }).input
  • 实际:'NVDA looks fine'(= evaluationRun.answer
  • 预期:'Research NVDA'(= evaluationCase.input.prompt

没有 case 定义时:实际仍返回 answer,预期为空串。

UI 影响:TraceInspector.tsx:202trace.input 渲染成 "Input" 一行
{trace.input || t('trace.notRecorded')}),所以评估运行会在 Input 位置显示回答,
且"未记录"兜底永远落不到。

根因

把"输出字段"当成"输入字段"的兜底。文件头部的投影纪律明确禁止这种做法:

NEVER reconstruct historical context from current app state … anything else is
not-recorded

contextFromCase() 注释写明 benchmark case input 是权威来源(spec §9)。

修复

input: run?.input ?? evaluationCase?.input.prompt ?? ''
  • 会话运行:仍用 run.input(未变)
  • 评估运行:用 case 的 prompt
  • 两者都没有:空串 → UI 显示"未记录"

范围

projectTrace()input 字段赋值一行,其余投影逻辑(tools / steps / context /
evaluation / completeness / latency)完全未动。

有可见 UI 变化:评估类 trace 的 "Input" 行从"回答文本"变为"case prompt";
无 case 定义时显示"未记录"。

测试

packages/core/src/trace-projection.test.ts 新增 2 个用例:

用例 期望
projects the benchmark case prompt as the trace input, never the answer trace.input === 'Research NVDA' 且不等于 evalRun.answer
leaves the trace input empty when no authoritative prompt was recorded trace.input === ''

回归证明(修复前):

bun test packages/core/src/trace-projection.test.ts --isolate
  -> 11 pass / 2 fail   (两个新增用例均失败)

修复后:

bun test packages/core --isolate
  -> 51 pass / 0 fail  (Ran 51 tests across 5 files)

bun run typecheck
  -> @finagent/core / i18n / shared / ui / electron 全部 exit 0

基线说明:干净 origin/main7c9b550)上 bun run typecheck 五个工作区全部 exit 0,
无基线故障;本 PR 未引入新的 advisory 失败。

环境

  • Bun 1.4.2
  • Windows

Closes #160

`projectTrace()` 组装 `FolioTrace.input` 时:

```ts
input: run?.input ?? evaluationRun?.answer ?? ''
```

`EvaluationRun` 没有 `input` 字段(它的输入在 benchmark case 的
`input.prompt` 里),于是评估类 trace 会把 agent 的**输出**当成**输入**
投影出去。TraceInspector 里 "Input" 一行因此显示成回答文本,而且永远
落不到 `t('trace.notRecorded')` 的兜底。

这与 trace-projection 的既定纪律直接冲突——文件头写明"NEVER reconstruct
historical context from current app state … anything else is not-recorded",
且同文件 `contextFromCase()` 的注释明确"benchmark case input —
authoritative (spec §9)"。

修复:改为从权威来源取输入

```ts
input: run?.input ?? evaluationCase?.input.prompt ?? ''
```

- 会话运行:仍用 `run.input`(未变)
- 评估运行:用 case 的 `prompt`
- 两者都没有:空串,UI 显示"未记录"

范围:仅 `projectTrace()` 的 `input` 字段赋值,其余投影逻辑未动。
有可见 UI 变化:评估类 trace 的 Input 行从"回答文本"变为"case prompt"
(无 case 时显示"未记录")。

测试:`packages/core/src/trace-projection.test.ts` 新增 2 个用例
(用 case prompt;无权威输入时为空串)。旧代码下 11 pass / 2 fail,
修复后 51 pass / 0 fail(core 全量)。

@helsome helsome left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

代码与回归测试本身没有看到 correctness blocker,Issue #160 的认领/Closes 范围也一致,当前 head 的 Focused tests / Typecheck / Secret scan / advisory full suite 全绿。这里仅保留 1 个验收项:PR 明确会改变 Trace Inspector 的可见 Input 内容(answer → case prompt;无 case 时显示“未记录”),请在 PR 内补一张实际界面截图,能看出修复后的 Input 行即可(既有界面最好 Before/After,但不要求额外视频或 E2E)。补齐后即可重新审。

wxrbyte added a commit to wxrbyte/folio that referenced this pull request Sep 23, 2026
wxrbyte added a commit to wxrbyte/folio that referenced this pull request Sep 23, 2026
wxrbyte added a commit to wxrbyte/folio that referenced this pull request Sep 23, 2026
@wxrbyte

wxrbyte commented Sep 23, 2026

Copy link
Copy Markdown
Contributor Author

已按评审要求补上 Trace Inspector 的 Input 行界面截图(Before / After + 无 case 场景)。

场景

一次评测运行:evaluationRun.answer = "NVDA looks fine",对应 benchmark case 的 input.prompt = "Research NVDA",运行记录本身没有 input
界面语言 zh-CN,显示的是 Trace Inspector → 概览 页。

Before(修复前:input 回退成 answer)

before

Input 行显示 NVDA looks fine,与下面的 Answer 行完全相同 —— 输出被当成了输入。

After(修复后:取 benchmark case 的 prompt)

after

Input 行显示 Research NVDAAnswer 行仍为 NVDA looks fine,两者不再混淆。

After(无 case:留空 → 未记录)

after-nocase

没有权威输入来源时,Input 行显示「未记录」,不再用 answer 兜底。

截图是怎么产生的(可复核)

  • 渲染的是仓库里真实的 TraceInspector 组件packages/ui/src/components/trace/TraceInspector.tsx),用 Electron 应用自身的 vite + tailwind 管线(apps/electron/vite.config.ts@tailwindcss/vite@source 配置)构建,样式即生产样式。
  • 数据来自真实的 projectTrace()packages/core/src/trace-projection.ts),构造输入与本 PR 新增的两个回归用例一致。
  • Before 那张是把 trace-projection.ts 中该行临时还原成修复前的 run?.input ?? evaluationRun?.answer ?? '' 重新构建后截的;截图完成后源码已还原为本 PR 的版本(input: run?.input ?? evaluationCase?.input.prompt ?? ''),工作树 git status 干净。
  • 截图是组件级渲染,不是完整的端到端应用流程(Windows 上 e2e 套件本身无法启动,与本次改动无关)。

除补图外无其他代码改动,三项硬门禁(Typecheck / Focused tests / Secret scan)与 advisory 全量在现有 head 上仍然全绿。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

trace: 评估运行的 Trace input 回退成 answer,把输出当成输入展示

2 participants