Skip to content

Commit f59a4aa

Browse files
feat(scenarios): restore the seeded rows before each operation, so one failed write does not cascade into the next (#34338)
<!-- claude-projects-attribution: {"github_login":"os-tesla"} --> _Requested by **Tesla** · [project thread](https://claude.ai/code/project/chan_01AXsQkLFKRdQCqQ3RTr6Jao?thread=cmsg_01AXsQkLFKRdQCqQ3RTr6JaoRjJUKvHSKGRptLNiD3Nska)_ epic:#33595#1 · os-tesla · session_01L9qibxMxTCsjCeHw2vP5qU Clause-②: yes (widening) — through `./runner`: new exports `restoreObjects`, `seededRows`, `restoreSeededRows` and types `SeededRows` / `RowRestore` (`orchestrate.ts`); `derivedFields`, `rowDrift`, `driftText`, `RESTORE_UNCOMPARED`, `RESTORE_UNWRITTEN` and types `HeldRow` / `RowDrift` (`seed.ts`); the new optional member `AppHarness.deleteRow` and the method `HttpApp.deleteRow` (`app.ts`); the new optional fields `OperationResult.restored` (`orchestrate.ts`) and `HalfScores.operations.restored` (`scorecard.ts`). No export entry moves; `./score`, `./score/full`, `./export` and `.` are untouched. Operation grades after an earlier turn's write move: an operation that used to start from the rows the turn before it left now starts from the seeded rows. Metadata-protocol: none Fixes #34294 ## 维护者速读 - 改了什么:评测跑分器在每个操作运行之前,先把前面回合改动过的行恢复到种子加载后的状态(以管理员身份:删掉新增行、按种子原样重新插入被删行、把被改的列改回),所以每个操作都从卡片声明的数据出发;无法恢复时该操作记为「未测量」并写明原因。 - 为什么改:原来所有操作在同一份种子数据上按顺序跑,一次写错(或探针被应用错误地存下)会让后面两三个操作一起失败,模型之间的操作分比较就混进了连锁失败,而不只是每个回合自己的表现。 - 风险与回滚:没有任何前面回合写入时不写任何东西,记录和分数表逐字节不变(已钉住);恢复只在操作的第一个回合之前,不会插在「先问后确认」的两个回合之间;问数不受影响。旧录像回放时,依赖前一操作写入的后续操作会读成「未测量」(回放不忠实),不会读成失败。回滚即还原本 PR。 - 先看:`packages/qa/scenarios/src/runner/orchestrate.ts` 的 `restoreSeededRows`(三轮恢复与失败判定)和 `runHalf` 操作循环开头的调用;`src/runner/seed.ts` 的 `rowDrift`(比较哪些列)。 - 两分钟验证:`pnpm --filter @objectstack/scenarios exec vitest run --maxWorkers=2 test/runner/orchestrate.test.ts -t 34294`,预期 7 个用例全过。 - 需要你做的:无,席位落地。 ## What changes - **Design point 1, what is restored** (`orchestrate.ts` `restoreObjects` / `seededRows` / `restoreSeededRows`, `seed.ts` `rowDrift`): right after the seed loads, the runner reads, as the admin, the rows of every seeded object and of every object an operation writes or its outcome reads that the seed does not name. That read is the seeded state: the app's own answer to the seed, so a row the app refused, or one it made itself while seeding, is held exactly as the operations would have met it before this change. This is a superset of "the objects the operation and its outcome read": the agent's turn may read any seeded object (it looks an account up by name before it creates a contact), and the cost is one list per object per operation, against an agent turn that takes minutes. Before each operation the runner reads them again and compares by id, every column except `created_at`, `updated_at`, `updated_by` (stamped anew by every write, the restore's own included) and the fields the build computes (`COMPUTED_VALUE_TYPES` from `@objectstack/spec/data`: formula, summary, autonumber, read from the built artifact through the scorer's one reader). When something moved it puts it back, as the admin, through the seed path: a row a turn added is deleted (new `DELETE /api/v1/data/:object/:id`, `HttpApp.deleteRow`); a seeded row a turn removed is inserted again with the very body the seed sent (`seedRowBody`, now shared by `seedApp`), or, for a row the app made itself while seeding, the row as read less the platform's stamps; a changed column is set back to the value the seed left. A lookup to a row still missing waits for the next round. Up to three rounds of writes, so a cascade settles (a delete that takes a child, a reference set back before a delete is allowed). - **Design point 2, when**: before every operation, and only when the read finds something moved. A run where no earlier turn moved a row writes nothing and records and scores byte for byte as before (pinned). The first operation restores only when a question turn wrote (questions are not meant to write; that drift would otherwise reach every operation), which the order's "after the first that follows a write" reading covers as the same rule: the check, not the position, decides. - **Design point 3, a restore that fails**: rows that still differ after the three rounds make the operation NOT MEASURED, `restore: the rows could not be restored to the seeded state: OBJECT: 1 added (ID), … (refused: VERB OBJECT ID: STATUS CODE MESSAGE)`, each refusal named once. The operation is not asked, so no turn, observation or grade is recorded, and it counts in neither passed nor total. A list the app refuses during the restore fails it the same way. A harness without `deleteRow` (it is optional, so an existing harness keeps compiling) fails a restore that needs a delete, and says so. - **Design point 4, interplay**: the restore runs at the head of the operations loop, before an operation's first turn; a `pending_confirmation` operation's ask and confirmation (#34293) run back to back on the same rows, and the confirmed delete is undone before the next operation (pinned). Questions are unchanged: they all run before any operation, at every `--ask-repeats` ask, and the seeded state is read before them. Ask mode runs the same Run half, so it restores the same way. A replay re-sends each operation's recorded writes against the restored rows (`RecordedDriver`, #33737); where a later operation leaned on an earlier one's write, it reads NOT MEASURED (the replay is not faithful), never a fail. - **The record and the scorecard**: an operation that started from restored rows carries `restored: { deleted?, reinserted?, setBack? }` (each `object/id`; `setBack` maps a row to the columns set back), absent otherwise. The `Run-operations` cell, and the run record's `run-operations` note, add `· N started from restored rows` (measured operations only) when N > 0. - README: a bullet `Each operation starts from the seeded rows`; changeset `34294-scenario-restore-seeded-rows.md` (patch). ## Design point 5, measured on eval#1's records Read-only over the 138 run records under `/mnt/project-files/eval/runs` (2026-11-14 through the 2026-11-16 M2 close-out; 258 Run halves; 1,290 operations that ran): - 628 operations ran after an earlier turn in their half wrote (the agent's write, a probe's, or a confirmed one): the restore would run before each of them, and the other 662 are untouched. - 199 of those 628 failed. 198 failed only on checks that read the turn's own calls and reply (`answer`, `no-write`, `agent`, `confirmed-by-agent`, `platform`): asking first, refusing, withholding. They would grade the same on restored rows unless the agent behaved differently on them, which no record can tell. - 1 failed on a row-state check after an earlier write on the same row: `2026-11-15-replay-m1/high/opus`, `invoice_with_line_items`, iterate Run, `send_invoice` (`state: demoinvoice_invoice#i3.status read "draft"`, `audit-actor`), after `add_line`'s runner probe stored a line on `i3`. That is the one grade the restore can plausibly move. - 0 operations errored after an earlier write. What the records do not allow: they keep each operation's post-state rows and write counts, not the rows it started from, so an exact count of moved grades needs a replay of the recordings on this branch (booted apps per card); this PR did not run one. The scripts and outputs are in the project files beside the PR's other evidence (`out-34294/measure*.mjs`, `out*.txt`). ## Tests - `test/runner/orchestrate.test.ts`, a new top-level describe (#34294, 5 cases) and one for the pure helpers (2 cases): - **an operation after a wrong write passes on its own merits**: `add_contact`'s turn also deletes Eli (`ct5`), the row `move_eli` acts on; `move_eli` passes with `restored: { deleted: [new-add_contact], reinserted: [ct5] }`, and `add_contact`, the first operation, restores nothing; - the restore runs before an operation, never between its ask and its confirmation (`remove_ben` sets back `ct5.account`, its confirmed delete still grades on the rows its ask saw; `contact_bad_email` reinserts `ct2`; the validation operation wrote nothing, so the next restores nothing); - **parity**: with no earlier write the app takes the seed's 8 inserts and nothing after, and the record and the scorecard carry no `restored` and no `restored rows`; - **a refused restore is NOT MEASURED** with the reason, the operation never asked (403 on delete; and a harness with no `deleteRow`); - `restoreSeededRows` directly: the clock and a computed field moving restore nothing and write nothing; a changed name is set back; a removed seeded row goes back with the seed's body; - `rowDrift` (clock and last writer not compared, `null` = absent) and `derivedFields` (formula/summary/autonumber; nothing from an unreadable artifact). - `test/runner/app.test.ts` (+1): `HttpApp.deleteRow` sends `DELETE /api/v1/data/OBJECT/ID` with no body and reads a refusal's code. - Existing pins that read the app's rows after the run, or the operations tally, now see the restores: the crm card's clean run reads `restored: 3` (`move_eli`, `remove_ben`, `contact_bad_email`); the probe that a broken app stores is deleted before `partner_edits_account` (`restored: 4`); eval#1's haiku replay deletes `replayed-0` before `move_eli`, and reinserts `ct2` after a replay whose app applied the delete. Their grades are unchanged. - `test/export/fixture.ts`: its `FakeApp` gains `deleteRow`. ## Acceptance notes - `add_contact` passed in the cascade pin although its turn also deleted `ct5`: the grader reads the declared post-state, and an extra removal on the same object is not charged to that turn. That is the grader's existing reading (`src/score/**`, outside this card); noted, not filed. - The restore lists up to 1,000 rows per object (`listRows`), as every read of the runner does; the largest seeded object in the library holds 307. - `HttpApp.deleteRow`'s route is read from `packages/rest/src/crud-routes.ts`, not yet measured live, like the seed's second-pass PATCH beside it; a live run's first restore is that measurement, and a refusal there reads NOT MEASURED with the code. - A row an earlier turn deleted and the restore inserts again is a new row to the platform: its `created_at` and any autonumber are new. Neither is compared; a card that declares an autonumber value would see the difference in its own post-state check. - The four `orchestrate.test.ts` record-note and cell pins that read `5/5` now read `5/5 · 3 started from restored rows`. ## Verification <details><summary>Ablation</summary> - `node scripts/ablation-replace.mjs` on the committed head of the time (`orchestrate.ts` blob `bc4bc9f62aa2`; the later `dcbc4425` changes only how a failed restore names its refusals), the restore call in `runHalf` replaced by "nothing restored"; the tests import `src`, so there is no build leg. Restored each time with `git diff HEAD` empty and the blob equal to HEAD. - The #34294 describe: 3 failed / 4 passed (the cascade pin, the confirmation-interplay pin, the refused-restore pin; parity and the helper pins hold, as they should with no restore). - The cascade pin alone, its grade asserted first: `move_eli` reads `"Cannot convert undefined or null to object"` (the row it acts on is gone) instead of a pass. </details> <details><summary>Local gates</summary> - On `dcbc4425`: `pnpm --filter '@objectstack/scenarios^...' build` :: exit 0 (lock VERDICT command-exit 0); `pnpm --filter @objectstack/scenarios build && pnpm --filter @objectstack/scenarios typecheck && pnpm --filter @objectstack/scenarios test` :: exit 0 (lock VERDICT command-exit 0): Test Files 35 passed (35), Tests 985 passed (985). - `eslint --no-inline-config` on the seven touched TS files :: exit 0. - Derived gates (`dispatch-gates --commands --repo objectstack-ai/objectstack` at `dcbc4425`, 9 paths, 67 families), each run with stdin from `/dev/null`: 65 exit 0, and 2 exit 3 (PREREQUISITE NOT MET): - `check-plugin-teardown-shape --self-test` could not read its pinned fixture commit in the shallow clone; after `git fetch origin 621a487…`, a rerun exited 0 ("48 cases pass"), recorded on its own line; the first-run record is kept as it was. - `pnpm check:dual-build-cjs-loads` is NOT MEASURED locally: it needs every package's `dist/`. CI runs it. - `--ran` on the first-run record: "67 derived famil(ies) accounted for — 65 run, 2 NOT-MEASURED (2 DERIVED from a recorded exit 3)". - Main (`951eceee` → `c9346317`, the objectql cascade-delete batch, #33887) was merged once before opening (`88929ff3`); it touched nothing under `packages/qa/scenarios`. After the merge, on `88929ff3`: `pnpm install --frozen-lockfile && pnpm --filter '@objectstack/scenarios^...' build && pnpm --filter @objectstack/scenarios build && … typecheck && … test` :: exit 0 (lock VERDICT command-exit 0), Test Files 35 passed (35), Tests 985 passed (985); `packages/spec` moved on main's side, so `pnpm --filter @objectstack/spec check:generated` :: exit 0. The derived-gate record is the one on `dcbc4425`, whose diff the merge leaves as it was. - 616 changed lines (+571/-45) in 9 files. No governed surface; `packages/spec`, `src/score/**`, `src/schema.ts`, card JSONs and `src/export/**` untouched (the export test fixture gains `deleteRow`). </details> --- _Generated by [Claude Code](https://claude.ai/code/session_01L9qibxMxTCsjCeHw2vP5qU)_ <!-- signed: epic:#33595#1 · os-tesla · session_01L9qibxMxTCsjCeHw2vP5qU --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent f4f0dfa commit f59a4aa

9 files changed

Lines changed: 571 additions & 45 deletions

File tree

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
'@objectstack/scenarios': patch
3+
---
4+
5+
feat(scenarios): every operation starts from the seeded rows: the runner undoes an earlier turn's write before the next operation runs
6+
7+
Clause-②: yes (widening) — new exports `restoreObjects`, `seededRows`, `restoreSeededRows` and types `SeededRows` / `RowRestore` (`orchestrate.ts`); `derivedFields`, `rowDrift`, `driftText`, `RESTORE_UNCOMPARED`, `RESTORE_UNWRITTEN` and types `HeldRow` / `RowDrift` (`seed.ts`); new optional member `AppHarness.deleteRow` and method `HttpApp.deleteRow` (`app.ts`); new optional fields `OperationResult.restored` (`orchestrate.ts`) and `HalfScores.operations.restored` (`scorecard.ts`); all of these reached through `./runner`. Operation grades after an earlier turn's write move: an operation that used to read the rows the turn before it left now reads the seeded rows.
8+
Metadata-protocol: none
9+
10+
Until now a Run half ran every operation in card order on one seeded app, so a turn that wrote the wrong row, deleted one, or a probe the app wrongly stored, left the next operation starting from rows the card never declared. One bad write could fail two or three operations, and the operations score measured the cascade as much as each turn.
11+
12+
Now the runner reads the rows of every seeded object, and of every object an operation writes or its outcome reads, right after the seed loads. Before each operation it reads them again, and when an earlier turn moved them it puts them back as the admin: a row a turn added is deleted, a seeded row a turn removed is inserted again with the body the seed sent, and a changed column is set back to the value the seed left, in up to three rounds so a cascade settles. The clock, the last writer and the fields the build computes (formula, summary, autonumber) are neither compared nor written. The operation's result carries `restored` (`deleted`, `reinserted`, `setBack`), and the `Run-operations` cell adds `N started from restored rows`. Rows that still differ after the rounds make the operation NOT MEASURED with the reason (`restore: …`), never a pass or a fail.
13+
14+
The restore runs before an operation's first turn, never between a `pending_confirmation` operation's ask and its confirmation. Questions are untouched: they all run before any operation, at every `--ask-repeats` ask. A run where no earlier turn moved a row writes nothing and records and scores exactly as before. A replayed recording re-sends each operation's writes against the restored rows; where a later operation leaned on an earlier one's write, it reads NOT MEASURED (the replay is not faithful), never a fail.

‎packages/qa/scenarios/README.md‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,22 @@ npx @objectstack/scenarios help # the comma
383383
reads the second NOT MEASURED, never a fail. The `Run-operations` cell adds `confirmed write k/N` beside the
384384
`asked first` count, and the card states the sum on its own line. A card with no `pending_confirmation` operation
385385
runs, records and scores exactly as before.
386+
- **Each operation starts from the seeded rows** (`orchestrate.ts`, `seed.ts`, `app.ts`, `scorecard.ts`): right after
387+
the seed loads, the runner reads the rows of every seeded object, and of every object an operation writes or its
388+
outcome reads (`restoreObjects`), as the admin. Before each operation it reads them again and compares
389+
(`rowDrift`: every column but `created_at`, `updated_at`, `updated_by` and the fields the build computes — formula,
390+
summary, autonumber). When an earlier turn moved them (the agent's write, a probe's, a confirmed one, or a question
391+
turn that wrote), it puts them back (`restoreSeededRows`): a row a turn added is deleted, a seeded row a turn removed
392+
is inserted again with the body the seed sent, and a changed column is set back to the value the seed left, in up to
393+
three rounds so a cascade settles. The operation's result then carries `restored` (`deleted`, `reinserted`,
394+
`setBack`, each `object/id`), and the `Run-operations` cell adds `N started from restored rows`. Rows that still
395+
differ after the rounds make the operation NOT MEASURED (`restore: the rows could not be restored …`, naming what
396+
differs and the first refusals), never a pass or a fail on rows the card did not declare. The restore runs before an
397+
operation's first turn, never between its ask and its confirmation; questions are untouched (they all run before any
398+
operation). A run where no earlier turn moved a row writes nothing and records and scores exactly as before. A
399+
replay re-sends each operation's recorded writes against the restored rows, so a recording made before restores
400+
whose later operation leaned on an earlier one's write reads NOT MEASURED there (the replay is not faithful), never a
401+
fail.
386402
- **Language and build prompt** (`prompts.ts`, `orchestrate.ts`, `scorecard.ts`, `driver.ts`): `--lang zh|en` renders
387403
every card-authored text a prompt carries in that language and no other — the build prompt (`prompt.short` or
388404
`prompt.detailed`), the iterate change (`iterate.change`), and each question's and each operation's `ask` — in every

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222
* seed's second pass, `seedApp` in `orchestrate.ts`; read from the
2323
* route's source, `packages/rest/src/crud-routes.ts`, not yet
2424
* measured live)
25+
* a restored row DELETE /api/v1/data/:object/:id (a row an earlier operation added,
26+
* deleted before the next one runs, `restoreSeededRows` in
27+
* `orchestrate.ts`; read from the same route source, not yet
28+
* measured live)
2529
* rows GET /api/v1/data/:object?limit=…
2630
* the audit actor GET /api/v1/data/sys_audit_log?record_id=… (`user_id`)
2731
* unmanaged install POST /api/v1/marketplace/install-local { packageId, manifest,
@@ -125,6 +129,13 @@ export interface AppHarness {
125129
insertRow(object: string, row: Record<string, unknown>): Promise<HttpAnswer>;
126130
/** Set fields on a row already in (the seed's second pass: the lookups that close a reference cycle). */
127131
updateRow(object: string, id: string, patch: Record<string, unknown>): Promise<HttpAnswer>;
132+
/**
133+
* Delete a row, as the admin (a restore: a row an earlier operation added).
134+
* Optional, so a harness written before restores keeps compiling; without it
135+
* a restore that needs a delete cannot be done, and the operation is not
136+
* measured.
137+
*/
138+
deleteRow?(object: string, id: string): Promise<HttpAnswer>;
128139
listRows(object: string): Promise<HttpAnswer & { rows: Array<Record<string, unknown>> }>;
129140
/** The `user_id` the newest audit row for this record names; `null` when none names one. */
130141
auditActorUserId(object: string, recordId: string): Promise<string | null>;
@@ -272,6 +283,10 @@ export class HttpApp implements AppHarness {
272283
return this.call('PATCH', `/api/v1/data/${encodeURIComponent(object)}/${encodeURIComponent(id)}`, patch, { session: this.admin });
273284
}
274285

286+
deleteRow(object: string, id: string): Promise<HttpAnswer> {
287+
return this.call('DELETE', `/api/v1/data/${encodeURIComponent(object)}/${encodeURIComponent(id)}`, undefined, { session: this.admin });
288+
}
289+
275290
async listRows(object: string): Promise<HttpAnswer & { rows: Array<Record<string, unknown>> }> {
276291
const r = await this.call('GET', `/api/v1/data/${encodeURIComponent(object)}?limit=1000`, undefined, { session: this.admin });
277292
const records = (r.body as { records?: unknown } | null)?.records;

0 commit comments

Comments
 (0)