Skip to content

Commit a3e216e

Browse files
fix(scenarios): a replay maps the row a recorded run_action created to its live id (#35064)
<!-- claude-projects-attribution: {"github_login":"os-support-ai"} --> _Requested by **Yibo Wang** · [project thread](https://claude.ai/code/project/chan_01BVUyyPie8gHwoPM18iABwB?thread=cmsg_01BVUyyPie8gHwoPM18iABwBLW6dHPW6sSheA32XPKZzPV)_ Fixes #35048 Clause-②: no Metadata-protocol: none ## 维护者速读 - **改了什么**:场景卡回放(`--driver recorded:F`)现在会把录制里 `run_action` 新建出来的记录 id(答案里的 `result.id`)映射到回放应用给的新 id,原来只认 `create_record` 顶层 `id`。 - **为什么改**:travel_expense 的 `file_and_submit_from_text` 由动作建单、再按 id 提交;回放时提交带着旧 id 被拒 RECORD_NOT_FOUND,这道操作题每次回放都读成「未测」,问数技能迭代只能离线评分。 - **风险与回滚**:只动回放驱动里一个私有函数和一个判断,不影响真实运行与评分逻辑;回滚即 revert 本 PR。 - **先看**:`packages/qa/scenarios/src/runner/driver.ts`(`createdIdOf` 与 `CREATING_TOOLS` 判断);`packages/qa/scenarios/test/runner/orchestrate.test.ts`(新增两条回放用例)。 - **两分钟验证**:`pnpm --filter @objectstack/scenarios exec vitest run test/runner/orchestrate.test.ts -t "replay re-sends"`,预期 10 条全绿。 - **需要你做的**:无,席位落地。 ## What changes `RecordedDriver` re-sends a replayed turn's recorded writes and, for a row the recorded run created, sends later writes with the id the replayed app gave that row. It learned that id only from `create_record` answers (top-level `id`). `run_action` answers what the action body returned under `result` (`{ ok, action, objectName, result: { id } }`), so a row an action created kept its recorded id, and the follow-up write naming it was refused `RECORD_NOT_FOUND` on replay. That made the turn not faithful, and the operation read NOT MEASURED. - `createdIdOf(tool, output)` reads `result.id` on a `run_action` answer and the top-level `id` on a `create_record` answer, as before. - The remap runs for an applied answer of either door (`CREATING_TOOLS`), and still only for an applied one. - No other nested create shape (for example `result.record.id`) is read: nothing in the package knows such a shape. - `createdIdOf` and `CREATING_TOOLS` are module-private, so no published export changes (`Clause-②: no`). Changeset: patch `@objectstack/scenarios`. ## Tests Two cases go into the existing driver block of `test/runner/orchestrate.test.ts` (the `runHalf` replay describe), using a stand-in door modelled on the travel_expense build. Filing creates a claim. Submitting it is refused `HOOK_ABORTED`, or `RECORD_NOT_FOUND` for an id the app never gave. - **Pin:** a recorded `run_action` files a claim (`result.id` = `cl-rec`), the live app gives `cl-live-0`, and the recorded `run_action submit_claim` (same turn) plus a later turn's `update_record` naming `cl-rec` are re-sent naming `cl-live-0`. - **Control:** a `create_record` row is still remapped from its top-level id into a later `update_record` and a later `run_action`. Ablation (`scripts/ablation-replace.mjs`, fix committed first, test imports `src/` directly so no build sits between): each of the fix's two halves, ablated on its own, turns the pin red with the live failure text. The control stays green. Both restores are proven: blob equals HEAD and `git diff HEAD` is empty. ## Acceptance notes - The live replay after the fix grades `file_and_submit_from_text` and fails it only on `status` (`read "draft", declared "submitted"`). The build's own `demotravel_submit_claim` answers `HOOK_ABORTED` (`update('demotravel_expense_claim') does not recognise option 'status'`) in the recording as on replay. That is the authored action's defect, which the score now measures. It is not the replay's. - The first live "before" attempt was a no-op. It mutated the guard to `c.name === 'create_record'`, which left `CREATING_TOOLS` unused, so the workspace build's DTS step refused (`TS6133`) before anything ran. It was redone with a compile-clean mutation (`CREATING_TOOLS` = `['create_record']`), which is the pre-fix behaviour on this path. - `node scripts/check-plugin-teardown-shape.mjs --self-test` exited 3 locally (PREREQUISITE NOT MET: its positive-control commit is not in this shallow clone). That is NOT MEASURED locally and is CI's to read. It is unrelated to this diff. ## Verification All readings were taken on head `4aa292ec`. <details><summary>Live replay, before and after (travel_expense, ask, iter2 recording, --packages workspace)</summary> Command: `run-scenarios --only travel_expense --modes ask --template /mnt/project-files/issue-34687/ask-round-2026-11-17/build/travel_expense/template.json --ask-repeats 5 --packages workspace --driver recorded:/mnt/project-files/issue-34869/skill-iter/iter2/ask.rec.json` (scratch `--work`/`--out`), under the shared verify lock. | | Run-operations | `file_and_submit_from_text` | |:---|:---|:---| | before (`CREATING_TOOLS` ablated to `create_record`; `workspace @ 4aa292e + uncommitted changes`) | 2/2 · 4 not measured · 2 started from restored rows | NOT MEASURED: `run_action` was refused HOOK_ABORTED in the recorded run and refused RECORD_NOT_FOUND on replay (x2) | | after (`workspace @ 4aa292e`) | 2/3 · 3 not measured · 2 started from restored rows | graded, fail: `state:demotravel_expense_claim[trip="t121"].status` read "draft", declared "submitted" (the only failed check) | The other five operations are the same in both runs: `fix_meal_days` pass, `over_standard_without_reason` pass, and three NOT MEASURED because the seed refused their rows. Run-问数 is 25/25 · 40 not measured in both. </details> <details><summary>Unit tests, typecheck, ablation</summary> - `pnpm --filter @objectstack/scenarios typecheck`, then `vitest run --maxWorkers=2`: VERDICT command-exit 0, Test Files 39 passed (39), Tests 1095 passed (1095). `tsc --listFiles` includes `test/runner/orchestrate.test.ts`. - Block run (`-t "replay re-sends"`): Tests 10 passed | 127 skipped. - Ablation A: anchor `const holder = tool === 'run_action' ? answer.result : answer;` was replaced with `const holder = answer;` (anchor 1 to 0, blob 8051b98 to 474a9f0f). Result: Tests 1 failed | 9 passed. The pin fails with ReplayNotFaithfulError: "`run_action` was refused HOOK_ABORTED in the recorded run and refused RECORD_NOT_FOUND on replay". Restored to blob 8051b98 == HEAD. - Ablation B: anchor `if (CREATING_TOOLS.includes(c.name) && recorded === 'applied') {` was replaced with `if (c.name === 'create_record' ...` (blob 8051b98 to b7f4e29d). Result: Tests 1 failed | 9 passed, with the same failure. Restored to blob 8051b98 == HEAD. </details> <details><summary>Gates</summary> - `pnpm --filter '@objectstack/scenarios^...' build`: VERDICT command-exit 0. - `dispatch-gates --commands` derived 64 commands. Each was run with its exit captured before any pipe. 63 exited 0 and `check-plugin-teardown-shape.mjs --self-test` exited 3 (shallow clone). `dispatch-gates --ran`: "64 derived famil(ies) accounted for — 63 run, 1 NOT-MEASURED (1 DERIVED from a recorded exit 3)". - `overlap-check`: `origin/main` merges cleanly, and no open PR head shares a file. VERDICT clean exit 0. </details> --- _Generated by [Claude Code](https://claude.ai/code/session_01WGufziH9rnXEpD9ne7yFhD)_ <!-- signed: repo:objectstack#3 · os-support-ai · session_01WGufziH9rnXEpD9ne7yFhD --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 4240719 commit a3e216e

3 files changed

Lines changed: 106 additions & 11 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'@objectstack/scenarios': patch
3+
---
4+
5+
fix(scenarios): a replay maps the row a recorded `run_action` created to the id the replayed app gave it
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
A replay (`--driver recorded:F`) re-sends each turn's recorded writes and sends a later write naming a row the recorded run created with the id the replayed app gave that row. It read that id only from a `create_record` answer (`{ id }`). `run_action` answers what the action body returned under `result` (`{ ok, action, objectName, result: { id } }`), so a row an action created, such as a claim filed from text, kept its recorded id: the next write naming it was refused `RECORD_NOT_FOUND` on replay, and the turn read not measured ("not faithful") although the recorded run had written it. The replay now reads the created row's id from `result.id` of an applied `run_action` answer as well, and maps it like a `create_record` row. A `create_record` row is remapped as before.

‎packages/qa/scenarios/src/runner/driver.ts‎

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -621,16 +621,29 @@ function answerOutcome(output: unknown, isError: boolean): string {
621621
return isError ? 'refused without a code' : 'applied';
622622
}
623623

624-
/** The id an applied create answered (`{ id }`), when its output carries one. */
625-
function createdIdOf(output: unknown): string | undefined {
624+
/** The write doors whose applied answer can name a row the write created, so a replay maps its recorded id to the live one. */
625+
const CREATING_TOOLS: readonly string[] = ['create_record', 'run_action'];
626+
627+
/**
628+
* The id of the row an applied write created, when its output names one:
629+
* `create_record` answers it at the top level (`{ id }`), and `run_action`
630+
* answers what the action body returned under `result`
631+
* (`{ ok, action, objectName, result: { id } }`), so an action that creates a
632+
* row (a claim filed from text) names it there.
633+
*/
634+
function createdIdOf(tool: string, output: unknown): string | undefined {
626635
if (typeof output !== 'string') return undefined;
636+
let v: unknown;
627637
try {
628-
const v: unknown = JSON.parse(output);
629-
const id = typeof v === 'object' && v !== null ? (v as Record<string, unknown>).id : undefined;
630-
return typeof id === 'string' && id !== '' ? id : undefined;
638+
v = JSON.parse(output);
631639
} catch {
632640
return undefined;
633641
}
642+
if (typeof v !== 'object' || v === null) return undefined;
643+
const answer = v as Record<string, unknown>;
644+
const holder = tool === 'run_action' ? answer.result : answer;
645+
const id = typeof holder === 'object' && holder !== null ? (holder as Record<string, unknown>).id : undefined;
646+
return typeof id === 'string' && id !== '' ? id : undefined;
634647
}
635648

636649
/** `value` with every string equal to a recorded id replaced by the id the replay's app gave that row. */
@@ -654,9 +667,10 @@ function remapIds(value: unknown, ids: ReadonlyMap<string, string>): unknown {
654667
* persona ({@link AskTask.callTool}), before the turn is handed back: the
655668
* runner's read-back then finds what the recorded run wrote. Reads are never
656669
* re-sent. A refused write is re-sent too, and must be refused again with the
657-
* same code. A row the recorded run created is known to the replay's app
658-
* under a new id, so a later write naming the recorded id is sent with the
659-
* new one. The replay is not faithful, and the turn's grade measures nothing
670+
* same code. A row the recorded run created (by `create_record`, or by a
671+
* `run_action` whose action answered the row's id, {@link createdIdOf}) is
672+
* known to the replay's app under a new id, so a later write naming the
673+
* recorded id is sent with the new one. The replay is not faithful, and the turn's grade measures nothing
660674
* ({@link ReplayNotFaithfulError}), when a recorded write has no recorded
661675
* answer (nothing is re-sent for that turn: whether it ran is unknown), or
662676
* when the app answers a re-sent write otherwise than it answered the run.
@@ -790,9 +804,9 @@ export class RecordedDriver implements AgentDriver {
790804
broken.push(`\`${c.name}\`${target} was ${recorded} in the recorded run and ${replayed} on replay`);
791805
continue;
792806
}
793-
if (c.name === 'create_record' && recorded === 'applied') {
794-
const was = createdIdOf(c.output);
795-
const now = createdIdOf(answer?.output);
807+
if (CREATING_TOOLS.includes(c.name) && recorded === 'applied') {
808+
const was = createdIdOf(c.name, c.output);
809+
const now = createdIdOf(c.name, answer?.output);
796810
if (was !== undefined && now !== undefined && was !== now) this.ids.set(was, now);
797811
}
798812
}

‎packages/qa/scenarios/test/runner/orchestrate.test.ts‎

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2086,6 +2086,77 @@ describe('runHalf — a replay re-sends the turn\'s recorded writes before the r
20862086
]);
20872087
});
20882088

2089+
// The action door answers what the action body returned under `result`; a filed claim names its row there.
2090+
const actionAnswer = (action: string, result: Record<string, unknown>) => JSON.stringify({ ok: true, action, objectName: 'claim', result });
2091+
const refusal = (code: string) => JSON.stringify({ error: { code, message: `${code} (stand-in)` } });
2092+
/** The build's own action pair, as the travel_expense recording shows it: filing creates a claim; submitting it is refused HOOK_ABORTED, and RECORD_NOT_FOUND for an id the app never gave. */
2093+
const claimDoor = () => {
2094+
const sent: Array<[string, Record<string, unknown>]> = [];
2095+
const live = new Set<string>();
2096+
let n = 0;
2097+
const callTool: AskTask['callTool'] = async (tool, args) => {
2098+
sent.push([tool, args]);
2099+
if (tool === 'run_action' && args.actionName === 'file_claim') {
2100+
const id = `cl-live-${n++}`;
2101+
live.add(id);
2102+
return { output: actionAnswer('file_claim', { id, name: 'EC-0001' }), isError: false };
2103+
}
2104+
if (tool === 'create_record') {
2105+
const id = `new-${n++}`;
2106+
live.add(id);
2107+
return { output: JSON.stringify({ id }), isError: false };
2108+
}
2109+
const known = live.has(String(args.recordId));
2110+
if (tool === 'run_action') return { output: refusal(known ? 'HOOK_ABORTED' : 'RECORD_NOT_FOUND'), isError: true };
2111+
return known ? { output: JSON.stringify({ id: args.recordId }), isError: false } : { output: refusal('RECORD_NOT_FOUND'), isError: true };
2112+
};
2113+
return { sent, callTool };
2114+
};
2115+
2116+
it('a row a recorded run_action created (its answer\'s result.id) is named by the id the replay\'s app gave it, in a later write of the same turn and of a later turn', async () => {
2117+
const replay = new RecordedDriver({
2118+
driver: { driver: 'claude-code-cli', apiBilled: false },
2119+
turns: {
2120+
'c/scratch/run/a/p': turnOf(
2121+
call('run_action', { actionName: 'file_claim', params: { trip: 't1' } }, actionAnswer('file_claim', { id: 'cl-rec', name: 'EC-0007' })),
2122+
call('run_action', { actionName: 'submit_claim', recordId: 'cl-rec' }, refusal('HOOK_ABORTED'), true),
2123+
),
2124+
'c/scratch/run/b/p': turnOf(call('update_record', { objectName: 'claim', recordId: 'cl-rec', data: { note: 'cl-rec' } }, '{"id":"cl-rec"}')),
2125+
},
2126+
files: {},
2127+
});
2128+
const { sent, callTool } = claimDoor();
2129+
// Before the action's result.id was read, the submit went out naming `cl-rec` and the app answered RECORD_NOT_FOUND: not faithful.
2130+
await replay.ask(task('a', callTool));
2131+
await replay.ask(task('b', callTool));
2132+
expect(sent).toEqual([
2133+
['run_action', { actionName: 'file_claim', params: { trip: 't1' } }],
2134+
['run_action', { actionName: 'submit_claim', recordId: 'cl-live-0' }],
2135+
['update_record', { objectName: 'claim', recordId: 'cl-live-0', data: { note: 'cl-live-0' } }],
2136+
]);
2137+
});
2138+
2139+
it('control: a create_record row is still remapped from its top-level id, in a later update_record and a later run_action', async () => {
2140+
const replay = new RecordedDriver({
2141+
driver: { driver: 'claude-code-cli', apiBilled: false },
2142+
turns: {
2143+
'c/scratch/run/a/p': turnOf(
2144+
call('create_record', { objectName: 'claim', data: {} }, '{"id":"rec-1"}'),
2145+
call('update_record', { objectName: 'claim', recordId: 'rec-1', data: {} }, '{"id":"rec-1"}'),
2146+
call('run_action', { actionName: 'submit_claim', recordId: 'rec-1' }, refusal('HOOK_ABORTED'), true),
2147+
),
2148+
},
2149+
files: {},
2150+
});
2151+
const { sent, callTool } = claimDoor();
2152+
await replay.ask(task('a', callTool));
2153+
expect(sent).toEqual([
2154+
['create_record', { objectName: 'claim', data: {} }],
2155+
['update_record', { objectName: 'claim', recordId: 'new-0', data: {} }],
2156+
['run_action', { actionName: 'submit_claim', recordId: 'new-0' }],
2157+
]);
2158+
});
2159+
20892160
it('⛔ a recorded write with no recorded answer (a turn cut short): nothing of the turn is re-sent, and the turn is not faithful', async () => {
20902161
const t = turnOf(call('create_record', { objectName: 'o', data: {} }, '{"id":"r1"}'), call('update_record', { objectName: 'o', recordId: 'r1', data: {} }));
20912162
const replay = new RecordedDriver({ driver: { driver: 'x', apiBilled: false }, turns: { 'c/scratch/run/a/p': t }, files: {} });

0 commit comments

Comments
 (0)