Repository navigation
feat(security): who started a run is a stored fact, written once where the worker mints the id - #2221
wanderdev0 wants to merge 7 commits into
Conversation
…page's restored one, and page claims that write it Rows ask `runStartedBy` after real flows (the bundle) and after a restore (sw-runs in the test realm over the storage the bundle wrote). At f750ae3, red: a person's run resumed on a tab or with no tab reads "page" (`makeWorkerRun` puts it in the hand-over list); a page's run restored from a snapshot the hand-over left saying `builtBy: "worker"`, whose id the list has lost, reads "person"; a snapshot from a build with no fact reads "person"; a page's START_RUN fields (`startedBy`, `runStartedBy`, …) are stored verbatim in its run's payload; and a fork's own mint reads "page" after a hand-over. Green guards: a page's run stays "page" through hand-over/save/resume and after a RESUME_RUN's claims; a page's fork with a person parent is "page"; no event to a page or bringable row carries the fact; an archive restore carries the stored payload unchanged. Adds `__mlRunStartedByForTest` (SW realm only) so a row can ask the worker's own answer with no message type that would give a page the same answer. Co-Authored-By: Claude Code <noreply@anthropic.com>
…nd a hand-over never rewrites it Narrows the START_RUN claim row to `startedBy` (the fact's name) at the top level and inside `rebuild`; the other claimed names are unknown fields the payload check leaves alone by design and nothing reads. Inverts the session-folder row's last assertion: the person's fixture now carries `startedBy: "person"`, and `makeWorkerRun` on it leaves it "person" — the hand-over that used to burn the fact no longer does. Both rows are red at f750ae3 and green with the origin-fact fix (session-store's branch). Co-Authored-By: Claude Code <noreply@anthropic.com>
…e the worker mints the id `runStartedBy` read `isWorkerRun && !handedToWorker.has`, and `makeWorkerRun` puts every resumed run in the hand-over list, so the person's own run read "page" after any resume (on a tab, with no tab, or adopted). The other direction was unsafe: a page's run whose snapshot the hand-over left saying `builtBy: "worker"` read "person" once its id left the list. The fact is now `StartRunPayload.startedBy: "person"`, set only in `startMinted` (sw-run-start.ts) and carried as stored by every hand-over, resume, adoption, restore and archive. A page's START_RUN cannot set it (`PAGE_STRIPPED_KEYS`, top level and `rebuild`); RESUME_RUN copies named fields only. `runStartedBy` reads it and no longer reads the hand-over list, which keeps its meaning. A payload stored before the field existed reads "page"; nothing infers it. State registry `run.started-by`; state.md, shell.md and FILE_ATTACHMENTS.md say so. tests/started-by.test.mjs pins the upgrade: an old saved row resumed on a tab and with no tab reads "page" and mounts no folder. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… write Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Docs read at 7b7f3d5 (
Accepted as written: the
|
…ored startedBy, a stated limit Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Delta 7b7f3d5...8297a85 read: two doc files, the asked sentence in each. Named 8297a85 for the docs, no change asked. The code is janitor-2's.
|
Who started a run is now a stored fact, written once where the worker mints the id. A session's own folder (#2213,
mountForSession) is gated on it. Nothing callsmountForSessionyet, and nothing will before this merges.The defect
runStartedByreadisWorkerRun(id) && !handedToWorker.has(id)."page"after any resume.makeWorkerRunadds every resumed run to the hand-over list:adoptSession(a saved session resumed or adopted on a tab) andresumeDetached(no tab), sw-sessions.ts."person"after a restore.markWorkerRunrewrites the stored payload'sbuiltByto"worker"at the hand-over, and the hand-over list was the only thing that corrected it.hydratePersistedRunsrestores the snapshot. If the id is no longer inml_handed_to_worker, the run reads as worker-built and never handed over. The id leaves the list when its write never lands (an eviction betweenmakeWorkerRunand thehydrationDone-gated flush, or the key lost), or whendeleteRundrops the entry while a stored copy still saysbuiltBy: "worker". TheHANDED_MAXprune spares runs the worker still holds. e3 traced this path.The fact
StartRunPayload.startedBy?: "person".startMinted(sw-run-start.ts), where the worker minted the id withshortHash().markWorkerRunspreads the payload), a resume and an adoption (history.payloadintobgRuns), a snapshot restore, the saved row'srunmeta, and an archive restore (restoreSessioncarriesmeta.payloadbyte for byte).PAGE_STRIPPED_KEYSat the top level and insiderebuild.run-payload-checkaccepts only"person". RESUME_RUN copies named fields only (sw-run-host.ts, the resume's{ ...stored.p, task, images, maxSteps, origin }).SessionSummary, never in an event to a page, never in a bringable row. It travels only in the run payload, which stays in the worker.runStartedBy=isWorkerRun(id) && bgRuns.get(id)?.p.startedBy === "person", afterhydrationDone. A run still starting (not yet inbgRuns) reads"page".startUserRunand carries its own fact. It is never copied from the parent. A page's fork has none, whatever its parent's says."person"gets a folder. The file is the person's own, and restoring it is the person's act.Upgrade (stated limit)
A payload stored before this field existed (a snapshot, a saved row, an archive) has no fact and reads
"page", so its session gets no folder. Nothing infers the fact from the payload's shape,builtBy: "worker"included. Fixtures: tests/started-by.test.mjs (an old saved row resumed on a tab and with no tab:"page", the row unchanged, then no mount call and no folder record read or written) and e3's old-snapshot row.handedToWorkerkeeps its meaningrunStartedByno longer reads it. Its readers and writers are unchanged, all in sw-runs.ts:makeWorkerRunadds an entry.run.handed-to-workerstate read.HANDED_MAXprune insaveHandedToWorker.deleteRun.clear.markWorkerRun.State
Registry
run.started-by(worker, run scope,lostOn: []), beside its store in sw-runs.ts. docs/dev/state.md, Run state: where it lives, what carries it, what loses it (an unsaved run's snapshot when it settles), and that an old payload reads"page". docs/dev/shell.md and FILE_ATTACHMENTS.md ("One folder per session") now name the fact.Tests
"person"; a page's run handed over, saved and resumed reads"page"; a page's run restored from a snapshot sayingbuiltBy: "worker"with its id lost from the list reads"page", on a tab and with no tab; an old snapshot reads"page"and is not rewritten; a page's START_RUN or RESUME_RUN naming the fact changes nothing, at either level and through a restore;__proto__is refused; a page cannot start under a person's live id; a fork reads its own fact in both directions; no page event or bringable row carries it; an archive restore carries the payload as stored. It also adds the SW-realm-only hook__mlRunStartedByForTest.runStartedByrow at 5829ce7. It encoded the defect: a person's run aftermakeWorkerRunread"page".PAGE_STRIPPED_KEYSlist now namesstartedBy. Its adversarial row strips every listed key at both levels, so it covers the new key.Full suite at bec289e (main cfa17f5 merged last): 12708 tests, 12684 pass, 0 fail, 3 skipped, 21 todo.
🤖 Generated with Claude Code