Repository navigation
fix(science): never let a synthetic run take a journal ordinal - #784
Conversation
|
ANIRUDDHA ADAK (@aniruddhaadak80) is attempting to deploy a commit to the InkVell Team on Vercel. A member of the Team first needs to authorize it. |
Ishaan Gangwani (ishaan1124)
left a comment
There was a problem hiding this comment.
Thanks, the collision is real and the test shows it. The fix is incomplete, though.
In backend/cli/src/science/execution/history.ts, the new loop reserves ordinals only from finished runs (runs). A kernel run that is queued or still running exists only in the journal (durable), so a shell run can still take its number. With this PR applied, a finished shell run and a queued kernel run both came back as sequence 1.
Please also reserve the journal's ordinals:
for (const record of durable) add(record.session_id, record.sequence)and add a test with a queued kernel run. (For context, the only consumer today is the /provenance/executions route, so this is low urgency.)
The list numbered every run from one counter, but only kernel cells carry a real executionSequence, so a local shell run took the next number — the one the durable journal had already given the following kernel execution. Reserve the journal-assigned ordinals first and skip them when synthesising, keeping the counter monotone.
A kernel run that is queued or still running has no provenance node yet, so reserving only the ordinals already stamped on graph runs left its number free: a finished shell run, which carries no ordinal of its own, was handed sequence 1 while the journal already held it, and the two records then contradict each other for the same session. Read the ordinals out of the journal as well, which is the authority that assigned them.
f05373f to
3839585
Compare
|
Done in 3839585.
|
|
All checks are green on |
The file had been re-saved with a UTF-8 BOM and a cp437 round trip that turned the existing fixture label 'Result · version 1' into mojibake. Restoring main's bytes leaves the new tests as the file's only change. Co-authored-by: Cursor <[email protected]>
|
I pushed one commit (b8335cb) that restores |
The requested changes are in and verified; CI is green.
# Conflicts: # CHANGELOG.md
7f39c0a
into
synthetic-sciences:main
What does this PR do, and why?
ExecutionHistory.listnumbers a session's runs with one shared counter thatmixes two different sequence spaces:
countis advanced by every run, but only kernel cells carry a realexecutionSequence(assigned byExecutionHistory.submit). Alocal_computerunhas no
meta.executionSequence—tool/bash.tsrecords{ messageID, callID, exit, cwd, stdout, stderr }— so it takes the syntheticbranch and is handed
count + 1, which is exactly the ordinal the durablejournal already gave the next kernel cell.
The result, reproduced in the new test with
python→bash→python:The agent reads
sequenceas "execution N of this session". The ledger nowdisagrees with the journal about which result is the second result, and
anything keying on
(session_id, sequence)— including the ordered rendering,which tie-breaks on a content hash — sees a collision and an arbitrary order.
The fix reserves the journal-assigned ordinals first, so a synthetic number can
never land on one:
The
Math.maxmatters: without it, a journal ordinal of 2 seen after asynthetic 3 would rewind the counter to 2 and the next synthetic run would
collide again.
What this does not change
A sequence-less run is still numbered after the ones before it, so it remains
slightly out of chronological position. Numbering it correctly needs
tool/bash.tsto take its ordinal from
ExecutionHistory.submitso both producers share onecounter — a larger change than this fix, and one that would touch the hot write
path. The invariant repaired here is that no two runs claim the same number,
which is what the journal and any consumer keying on it need.
Linked issue
Self-identified. Happy to file a report if you would rather track it; my issue
budget this turn went to the two
apply_patchdefects and thelocalStoragecopies.
How did you verify it?
One case added to
backend/cli/test/science/execution-history.test.ts:a run recorded without a sequence does not take a kernel execution's number.It records a kernel run at ordinal 1, a
local_computerun exactly astool/bash.tsrecords it (envelope with noexecutionSequence,meta.exit), anda kernel run at ordinal 2, then asserts the sequence numbers are unique and that
the two kernel runs keep 1 and 2.
On unmodified
3e94875c:Commands run:
bun test --timeout 120000 ./test/science/execution-history.test.ts→ 4 pass, 0 fail
bun run --cwd backend/cli typecheck→ exit 0The whole file matters more than the new case: the three pre-existing cases cover
two runs with no ordinal (both synthetic, so no collision) and two runs that
both have one (no synthetic allocation), which is precisely why the mixed case
survived. All three still pass, so neither numbering path regressed.
Checklist
bun run checkis green (format, typecheck, backend + frontend/ui + SDK tests) — blocked on this Windows checkout by the CRLF and symlink artifacts in my other pull requests; backend typecheck is clean and the execution-history suite is greenbun run --cwd frontend/workspace buildsucceeds if I touchedfrontend/workspaceorfrontend/ui— not touched./tooling/repo/generate.tswas run and thetooling/sdkoutput committed if I changedbackend/cli/src/server— not touchedfrontend/docs/src/content/openscience/is updated if behavior changed — no doc change needed: the ordinal contract is unchanged, only the collision is gonepackage.jsonversions and tags are written by the release workflow)installandfrontend/landing/public/installare still byte-identical if I touched either — not touched