Skip to content

Commit 1efe7a2

Browse files
fix(scenarios): an operation an earlier write would meet runs on a fresh seeded copy of the app, so a one-way state rule no longer leaves later operations unmeasured (#34490)
<!-- claude-projects-attribution: {"github_login":"os-steve"} --> _Requested by **Steve** · [project thread](https://claude.ai/code/project/chan_01FdL1XeUyvVNxLreh3F4Qi9?thread=cmsg_01FdL1XeUyvVNxLreh3F4Qi9Qqe2mkHm2XbfxVw1ebw8zU)_ Part of #34448 Clause-②: yes (widening) Metadata-protocol: none The widening is through `./runner`: the new exported type `FreshCopy`, the new optional last parameter `fresh` of `runHalf`, and the new optional field `RowRestore.freshCopy` (`orchestrate.ts`). Nothing removed or narrowed; `./score`, `./score/full`, `./export` and `.` untouched. The claim was amended to match (its Clause-② amendment on #34448, 23:01Z). ## 维护者速读 - 改了什么:评测跑分器在某个操作之前发现前面回合改动过种子行时,不再以管理员身份把行写回应用(那会被应用自己的校验规则、钩子和流程评判),而是另起一份全新的应用副本、重新登录人设并重新加载种子,让这个操作和之后的回合在副本上跑;副本起不来或种子加载结果与原来不同,该操作记为「未测量」并写明原因。 - 为什么改:带状态机的卡(如资产生命周期)里,「批准」把报废单从 submitted 推到 approved 后,写回 submitted 被应用的单向状态规则正确拒绝(400 VALIDATION_FAILED),之后每个操作都读成「未测量」,画廊导出因此被拒。 - 风险与回滚:没有前面写入时不起任何副本,记录与分数逐字节不变;每次换副本多一次启动、人设登录和种子加载(只在写入之后的操作前付);模板模式仍走原来的写回路径(它的应用里有代理现场改的元数据,重启拿不到)。回滚即还原本 PR。 - 先看:`packages/qa/scenarios/src/runner/orchestrate.ts` 的 `runHalf`(`moveToFreshCopy` 与操作循环开头的分支)、`seedDifference`、`withInstalledBuild` 里 ask 模式的 `fresh`。 - 两分钟验证:`pnpm --filter @objectstack/scenarios exec vitest run --maxWorkers=2 test/runner/orchestrate.test.ts -t 34448`,预期 3 个用例全过。 - 需要你做的:无,席位落地。 ## What changes - **Why Ask 1 has no path, read from source, not inferred.** The runner reaches the app only over HTTP (`bootDev` spawns `objectstack dev --fresh`; `HttpApp` is the whole harness). The seed load the card names as "privileged, system-context" is the same admin data door the restore uses (`HttpApp.insertRow` → `POST /api/v1/data/:object` with the admin session; `seedApp`), so there is no privileged seed path to reuse. The platform takes an object's declared controls off a write only for `ExecutionContext.isSystem === true`, and an HTTP request is assembled with `isSystem: false`: the import doors refuse `runAutomations: false` / `treatAsHistorical: true` for every signed-in caller, administrators included (`importControlOptOutRefusal`, `packages/rest/src/import-prepare.ts`), and the import undo writes under the controls (`importUndoWriteContext`, `packages/rest/src/data-action-routes.ts`). Delete-and-reinsert through the data door runs the app's delete and create hooks and record-triggered flows, so it cannot promise "no flow runs". Opening a door past the controls would weaken the platform, which the card rules out. So this PR takes Ask 2: isolation. - **Isolation, paid only when needed** (`orchestrate.ts`). `runHalf` takes an optional last parameter `fresh` (`FreshCopy`: boot another copy of the same app with the same build installed the same way). Before each operation it reads the seeded objects (`seedDrift`, only reads; the read loop `restoreSeededRows` already had, now shared). Nothing moved ⇒ nothing happens. Something moved ⇒ `moveToFreshCopy`: boot the copy, sign the admin in, create every persona with its permission set, mint the admin key, load the seed by the same `seedApp`, compare the copy's seed with the run's (`seedDifference`: rows loaded, rows refused with code and fields, permission sets assigned), read the copy's seeded state, then switch the half to it (accounts, keys and seeded state included) and stop the copy it replaces. The half's last copy is stopped in a `finally`; the booted app stays with `withApp`, as before. The operation records `restored: { freshCopy: [object/id, …] }`, the rows that had moved. - **Where a copy comes from.** Scratch mode's Run half and iterate Run half: `ops.boot(dir)` on the same project (`freshBoot`). Ask mode: `withInstalledBuild` boots the same blank host again and installs the same manifest through the unmanaged door; a refused install fails that copy. Template mode passes none: its app holds the agent's iterate, made live through the app's doors, which a host booted again would not hold, so it keeps writing rows back through `restoreSeededRows` (comment at the call). - **A copy that fails** (boot throws, a persona or key refused, the seed loads differently) makes the operation NOT MEASURED: `restore: no fresh copy of the app could be seeded for it (REASON); what had moved: DRIFT`. It is not asked, and never graded on other rows. A half that has no `fresh` keeps today's write-back and today's `restore: the rows could not be restored …` reason. - **Unchanged.** Questions all run on the booted app before any operation. A `pending_confirmation` operation's ask and confirmation run back to back on the same app. The scorecard's `N started from restored rows` still counts every operation that started from the seeded rows, now including the ones on a copy (`scorecard.ts` untouched). - Changeset `.changeset/34448-scenario-fresh-copy-restore.md` (patch; `@objectstack/scenarios` publishes). ## Why #34338, the change for #34294, restored the seeded rows by writing them back through the app's data door as the admin. On `asset_lifecycle` (#34448's measured run, objectstack main `a121e29c`), `manager_approves_scrap` moved DR-0006 `submitted` → `approved`; the write-back to `submitted` met the app's one-way status rule, 400 `VALIDATION_FAILED`, and `dispose_scrapped_asset`, `employee_approves_own_scrap` and `check_out_asset_in_repair` read NOT MEASURED in both halves. A rule like that is what a well-built app declares, so a restore the app must accept cannot undo a legitimate transition, and a restore it accepts can still fire its flows. ## Tests `test/runner/orchestrate.test.ts`, a new top-level describe (#34448, 3 cases) on the `asset_lifecycle` card with an app double that carries the card's one-way rule (a decided scrap request never goes back to `submitted`, 400 `VALIDATION_FAILED`, the issue's own message): - **the approval moves DR-0006 one way, and the disposal after it is measured all the same**: all six operations asked, none NOT MEASURED for its start, `manager_approves_scrap` wrote once, `dispose_scrapped_asset` records `restored: { freshCopy: ['demoasset_disposal_request/dr06'] }`; the rule refused nothing on any app; the booted app took exactly the seed's inserts and the seed's own second-pass updates and no delete; every boot was stopped by the end. - **⛔ without a fresh copy the same rule refuses the write-back**: the Run half alone, as template mode runs it; `dispose_scrapped_asset` is NOT MEASURED with `demoasset_disposal_request: 1 changed (dr06: status, decided_on)` and the refusal `update demoasset_disposal_request dr06: 400 VALIDATION_FAILED …` named, not asked, not graded. - **⛔ a copy whose seed does not load as the run's did, or that does not boot**: the second operation is NOT MEASURED with `the copy's seed did not load as the run's did: it loaded N rows, the run M; it refused demoasset_employee/e05 VALIDATION_FAILED, the run nothing` and what had moved; not asked; every refused copy was released. A copy whose boot throws says `objectstack dev exited before it was ready`. Tests forced to change, each because the scratch half now runs an operation after a write on a copy instead of writing the rows back (assertions read the new truth, none loosened): - `runCard — the seed against a build whose owner field is a user lookup` › `loads all 8 rows…`: the booted app now keeps `new-add_contact` (nothing is written back to it); added that there are 4 apps (the booted one and the copies for `move_eli`, `remove_ben`, `contact_bad_email`) and that every copy's owners equal the booted app's. - `runCard — the card's own namespace, demo + code` › `scaffolds the project as democrm…`: the template host is the last app booted, no longer `apps[1]`. - `runCard — the validation operation is probed…` › `sends the declared write once…`: the two probes are read across every app (each went to the app its operation ran on); same two calls, same keys. › `an agent that catches the bad value…`: `partner_edits_account` records `{ freshCopy: ['democrm_contact/probe-5'] }` (was `{ deleted: [...] }`), and the copy it ran on holds no probe row. - `runHalf — each operation starts from the seeded rows… (#34294)`: the cascade case reads `{ freshCopy: ['democrm_contact/new-add_contact', 'democrm_contact/ct5'] }` (was deleted + reinserted), still passes on its own merits; the confirmation-interplay case reads `freshCopy` for `remove_ben` and `contact_bad_email`; the refused-restore case (403 delete, and a harness with no `deleteRow`) now runs the Run half with no fresh copy, as template mode does, and pins the same reasons verbatim. ## Acceptance notes - **Ask 4 (a live `asset_lifecycle` run) is NOT MEASURED, reason: this container holds no model credential** (checked by presence only); per the order no credential was sought. The seat schedules the live run (the daily gallery task). - Template mode's write-back restore is filed as #34497. - Known, non-blocking: if stopping the replaced copy throws inside `moveToFreshCopy`, the error path releases the new copy as well; left for a later change so the head does not move. - A copy's seed load runs the app's create-side rules and flows exactly as the run's own seed load did: that is the seeded state, not a restore. What the copy guarantees is that nothing is written to undo a turn, so no rule judges a restore and no update/delete flow fires on one. - Cost: one boot (`objectstack dev --fresh` waits up to 180 s for health), the persona sign-ins and one seed load per operation that follows a write; up to three servers live for a moment (the booted app, the copy being replaced, the new copy). The crm card's clean run pays three copies per half. - A recording made before this change replays against a copy: persona user ids and keys are the copy's, as they already differ between any two runs. - `packages/qa/scenarios/README.md`'s bullet *Each operation starts from the seeded rows* now names both paths (scratch and ask on a fresh copy, template writing back), after the claim amendment added it to the file surface. ## Verification <details><summary>Ablation</summary> - `node scripts/ablation-replace.mjs` on the committed head (`orchestrate.ts` blob `f92b76b517ff`), scratch mode's Run half given no fresh copy (`…, opts.promptChoice, freshBoot(ops, dir))` → `…, opts.promptChoice, undefined)`): anchor 1 → 0, blob `f92b76b517ff` → `5cdc7e332873`. The tests import `src`, so there is no build leg. `-t 34448`: 2 failed / 1 passed. The first case reads exactly the issue's failure: `dispose_scrapped_asset` NOT MEASURED `restore: the rows could not be restored to the seeded state: demoasset_disposal_request: 1 changed (dr06: status, decided_on) (refused: update demoasset_disposal_request dr06: 400 VALIDATION_FAILED That status change is not allowed: …)`, and two more after it. The copy case finds no NOT MEASURED where a copy was refused. Restored: blob == HEAD (`f92b76b517ff`), `git diff HEAD` empty. </details> <details><summary>Local gates</summary> - Head `69b88800` (after merging `origin/main` once at `dc265d44`; the merge touched nothing under `packages/qa/scenarios`; `69b88800` adds only the README paragraph). - `pnpm --filter '@objectstack/scenarios^...' build` :: exit 0 (lock VERDICT command-exit 0, 2m59s). - `pnpm --filter @objectstack/scenarios build && pnpm --filter @objectstack/scenarios test` :: exit 0 (lock VERDICT command-exit 0) on `dc265d44` and again on `69b88800`: Test Files 35 passed (35), Tests 991 passed (991). On the same source, `pnpm --filter @objectstack/scenarios typecheck && pnpm --filter @objectstack/scenarios test` passed its typecheck leg (its test leg then asked for the package's own `dist/`, which the run above built). - `eslint --no-inline-config` on the two touched TS files :: exit 0. - Derived gates on `69b88800` (`dispatch-gates --commands --repo objectstack-ai/objectstack`, 4 paths, 62 families, the same set as on `dc265d44`), each with stdin from `/dev/null`: 62 exit 0. `--ran`: "62 derived famil(ies) accounted for — 62 run, 0 NOT-MEASURED". - The first round, on `dc265d44`, read 60 exit 0 and 2 exit 3: `check-plugin-teardown-shape --self-test` before its pinned fixture commit was fetched (a rerun after `git fetch --depth=1 origin 621a487…` exited 0, "48 cases pass"), and `pnpm check:dual-build-cjs-loads` before every package's `dist/` was built. Both records are in the project files. - 4 files changed (the README paragraph added to the three). No governed surface; `packages/spec`, `src/score/**`, `scorecard.ts`, card JSONs and `src/export/**` untouched. </details> ## Human Minimum - [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic. - [x] 2. Every name I added uses the casing for its kind. - [x] 3. No formatter ran; `pnpm lint` passes. - [x] 4. One issue, one branch off an up-to-date `main`, one pull request. - [x] 5. A change that publishes carries a changeset, and both declaration lines are filled in here and in the changeset. - [x] 6. `packages/spec` touched: its generated artifacts are regenerated and committed. (not touched) - [x] 7. No hand edits to `content/docs/references/`, `packages/*/CHANGELOG.md` or `content/docs/releases/`. - [x] 8. Title, body and comments are in English. - [ ] The *Before Submitting* list in CONTRIBUTING.md is done. <!-- signed: repo:objectstack#2 · os-steve · session_01ADHkmP1FQBBcaufj5VXUcV --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent a6c2b83 commit 1efe7a2

4 files changed

Lines changed: 345 additions & 66 deletions

File tree

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
'@objectstack/scenarios': patch
3+
---
4+
5+
fix(scenarios): an operation an earlier write would meet runs on a fresh seeded copy of the app, so an app's one-way state rule no longer leaves the operations after a transition unmeasured
6+
7+
Clause-②: yes (widening) — through `./runner`: the new exported type `FreshCopy`, the new optional last parameter `fresh` of `runHalf`, and the new optional field `RowRestore.freshCopy` (`orchestrate.ts`). Nothing is removed or narrowed; `./score`, `./score/full`, `./export` and `.` are untouched.
8+
Metadata-protocol: none
9+
10+
Before each operation the runner put the rows an earlier turn had moved back to the seeded state by writing them through the app's own data doors, as the admin. A well-built app judges those writes like any other: its validation rules, hooks and record-triggered flows run on them. So on a card with a state machine the restore failed exactly where the app was right. In `asset_lifecycle`, approving scrap request DR-0006 (`submitted` → `approved`) was followed by a write-back to `submitted`, the app's one-way status rule refused it with 400 `VALIDATION_FAILED`, and every later operation of the half read `restore: … not measured`. Even a write-back the app accepted could fire its flows.
11+
12+
Now, in scratch mode (the Run half and the iterate Run half) and in ask mode, the runner still reads the seeded rows before each operation, but when an earlier turn moved one it does not write anything back. It boots a fresh copy of the same app (scratch: the same project; ask: a blank host with the same build installed the same way), signs the personas in, loads the seed and reads the seeded state there, and that operation and every later turn of the half run on the copy. The copy it replaces is stopped. No rule, hook or flow of the app sees a restore, because there is none. The operation's result carries `restored: { freshCopy: [object/id, …] }`, naming the rows that had moved, and it still counts in the `Run-operations` cell's `N started from restored rows`. When the copy cannot boot, or its seed does not load as the run's did (other rows loaded or refused, a permission set not assigned alike), the operation is NOT MEASURED with that reason, never graded on other rows.
13+
14+
The cost is one boot, the persona sign-ins and one seed load per operation that follows a write, paid only then. A run where no earlier turn moved a row boots nothing more and records exactly as before.
15+
16+
Template mode keeps writing the rows back through the app's doors: its app holds the agent's iterate, made live, which a host booted again would not hold.

‎packages/qa/scenarios/README.md‎

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -391,12 +391,25 @@ npx @objectstack/scenarios help # the comma
391391
outcome reads (`restoreObjects`), as the admin. Before each operation it reads them again and compares
392392
(`rowDrift`: every column but `created_at`, `updated_at`, `updated_by` and the fields the build computes — formula,
393393
summary, autonumber). When an earlier turn moved them (the agent's write, a probe's, a confirmed one, or a question
394-
turn that wrote), it puts them back (`restoreSeededRows`): a row a turn added is deleted, a seeded row a turn removed
395-
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
396-
three rounds so a cascade settles. The operation's result then carries `restored` (`deleted`, `reinserted`,
397-
`setBack`, each `object/id`), and the `Run-operations` cell adds `N started from restored rows`. Rows that still
398-
differ after the rounds make the operation NOT MEASURED (`restore: the rows could not be restored …`, naming what
399-
differs and the first refusals), never a pass or a fail on rows the card did not declare. The restore runs before an
394+
turn that wrote), the operation starts from the seeded rows all the same, in one of two ways:
395+
- **Scratch and ask modes run it on a fresh copy** (`FreshCopy`, `runHalf`'s `fresh`): the runner boots the same
396+
app again (scratch: the same project; ask: the same blank host with the same build installed the same way), signs
397+
the personas in, loads the seed and reads the seeded state there, and that operation and every later turn of the
398+
half run on the copy; the copy it replaces is stopped. Nothing is written to undo the move, so no validation rule,
399+
hook or flow of the app judges a restore or runs on one: a one-way state rule (a request approved never goes back
400+
to submitted) cannot refuse it. The result carries `restored: { freshCopy }` (the rows that had moved, each
401+
`object/id`). A copy that does not boot, or whose seed does not load as the run's did (other rows loaded or
402+
refused, a permission set not assigned alike), makes the operation NOT MEASURED (`restore: no fresh copy of the
403+
app could be seeded for it (…)`, naming what had moved). Each copy costs one boot, the sign-ins and a seed load.
404+
- **Template mode writes the rows back** (`restoreSeededRows`), because its app holds the agent's iterate, made live,
405+
which a host booted again would not: a row a turn added is deleted, a seeded row a turn removed is inserted again
406+
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
407+
a cascade settles, all through the app's own doors, which its rules judge. The result carries `restored`
408+
(`deleted`, `reinserted`, `setBack`). Rows that still differ after the rounds make the operation NOT MEASURED
409+
(`restore: the rows could not be restored …`, naming what differs and the first refusals).
410+
411+
Either way the `Run-operations` cell adds `N started from restored rows`, and an operation is never a pass or a fail
412+
on rows the card did not declare. The move or the restore runs before an
400413
operation's first turn, never between its ask and its confirmation; questions are untouched (they all run before any
401414
operation). A run where no earlier turn moved a row writes nothing and records and scores exactly as before. A
402415
replay re-sends each operation's recorded writes against the restored rows, so a recording made before restores

0 commit comments

Comments
 (0)