Repository navigation
Description
What happened
WorkHub correction replaces its link without stopping a shared manual Turn (packages/runtime-host/src/__tests__/execution-composition.test.ts:689) fails intermittently on a clean main checkout. It is the most frequent Runtime Host flake on this machine: 10 of 13 full-suite runs failed on it, and it reproduces in focused repetitions too (2 of 6, then 1 of 3).
The assertion that fails is assert.equal(delegated.ok, true) on the workhub.coordination.act call. The rejection is not a timeout:
{"ok":false,"error":{"code":"operation_conflict",
"message":"WorkHub Session candidates changed; refresh before delegating"}}
Root cause: the candidate-set identity includes the Session name, and the automatic title lands asynchronously
candidateSet (packages/runtime-host/src/server/workhub-coordination-action-gate.ts:960) digests each eligible Session's id, name, workspace projection, status and updatedAt into candidateSetId. workhub.coordination.act rejects with operation_conflict when the id it is handed no longer matches (:504).
The test starts a manual Turn, reads the candidate set, then delegates into it. Starting the Turn also triggers the automatic Session title, which commits on its own schedule. Dumping both candidate sets at the moment of the rejection shows exactly one field moved, and it is the name:
BEFORE sha256:28184d9a… [{ id: 7f5f66ee…, name: "New Chat", status: running, updatedAt: 1788529087769 },
{ id: 232443e9…, name: "New Chat", status: active, updatedAt: 1788529087758 }]
AFTER sha256:daa2d376… [{ id: 7f5f66ee…, name: "__e2e_hold_open__", status: running, updatedAt: 1788529087769 },
{ id: 232443e9…, name: "New Chat", status: active, updatedAt: 1788529087758 }]
7f5f66ee… is the source Session. updatedAt is byte-identical across the two reads; the title commit is the whole difference. Whether the test passes is therefore decided by whether the title lands before or after the act call.
Beyond the test
The conflict domain looks wider than the decision it protects. A delegation cares which Sessions are eligible and what state they are in; it does not depend on what any of them is called. As written, any automatic title committing anywhere in the workspace invalidates every in-flight WorkHub delegation, so a user who opens WorkHub and clicks delegate can lose the race to a title commit on an unrelated Session and be told to refresh. That is the same race the test loses, just with a human in it.
Two directions, and which one is right is a maintainer call:
- Narrow the identity to the fields a delegation actually depends on — Session set, eligibility and status — and leave cosmetic fields such as
nameout of it. The candidate list would still be re-read; only the conflict would stop firing on a rename. - Keep the identity as it is and make the caller tolerate
operation_conflictby re-reading candidates and retrying once, which is what the message already tells clients to do.
The test change follows from whichever is chosen: under (1) nothing is needed; under (2) the test should settle the title before reading candidates rather than racing it.
How to reproduce
npm ci
npm --workspace @maka/runtime-host run build
# full suite; fails on this test in most runs
npm run test:dist --workspace @maka/runtime-host
# focused; fails in roughly one run in three
node --test \
--test-name-pattern="WorkHub correction replaces its link without stopping a shared manual Turn" \
packages/runtime-host/dist/__tests__/execution-composition.test.jsThe candidate-set dump above comes from printing workhub.coordination.candidates again inside the failure branch; the harness is not committed.
Environment
- Maka commit:
a9307d005(source build), also seen on4ed6255f2 - OS: macOS, Darwin 25.6.0, arm64, 10 cores
- Surface: Runtime Host
- Node.js: v24.19.0
Additional context
Found while investigating #4776, which is a different pair of tests; this one is unrelated to that fix and is filed separately as promised in #4784. #4776's own two tests did not fail once here in 42 focused repetitions and 19 full-suite runs.
Analysis produced with Claude Code; the runs, the candidate-set dump and this report were reviewed by me.
Activity
Adarsh-Me commentedon Sep 4, 2026
take
sunrioa commentedon Sep 23, 2026
Still reproducing on CI, through a second code path
This race is still active. Since it was filed, CI has hit it on several unrelated branches, and the symptom is not limited to the test named above.
A second exit for the same candidate-set identity. On
codex/fix-5009-host-lifecycle(#5043, head1b0141633, run 35847982862),default production WorkHub selects and delegates through its durable Host interactionfailed with:That is a different code and message from the
operation_conflictin the report above, and it is raised somewhere else —packages/runtime-host/src/server/workhub-coordination-coordinator.ts:603, rather thanpackages/runtime-host/src/server/workhub-coordination-action-gate.ts:577. Both compare acandidateSetIdobtained from the same#actionGate.candidates()call, so the identity this issue describes has at least two rejection sites, and narrowing it would fix both.Other recent failures, mechanism unconfirmed. Further CI failures landed on
WorkHub Resume and Stop follow logical lineage across repeated physical handoffs, in the same file:refactor/remove-permission-mode-comp…4483cd20bcodex/fix-5448-codex-handoff-import(#5450)09d72e78bperf/onboarding-incrementalfda730a67maine6e35aefeThose logs only show
ERR_ASSERTION,actual: false, expected: true, with no error code, so I cannot say from the logs alone whether they share this root cause. I am listing them because they are the same file and the same week, not as confirmed instances.The named test no longer reproduces locally. On current
main(9082cf144), macOS 26.5.2 arm64, Node 24.21.0:WorkHub correction replaces its link without stopping a shared manual Turn, focused,--test-concurrency=1: 6 rounds, 6 passed, 0 failed.execution-composition.test.jsfile: 5 rounds, 39 tests each, all passed.So a macOS checkout is not a good place to reproduce this now; the failures above are all on the Linux runners.
Why this still matters.
mainitself failed on it today, so this is not confined to contributor branches, and #5043 and #5450 are currently blocked on a redtestcheck that neither change can influence — neither touchespackages/runtime-host.Analysis produced with Claude Code; the CI logs, the source locations and the local runs above were reviewed by me.
Adarsh-Me commentedon Sep 23, 2026
Confirmed your second site, and reading it against current
main(9082cf144) changes what "narrowing the identity" has to cover. Analysis only here -- no patch, for the reason at the bottom.The mechanism is one digest, not two bugs.
candidateSet()buildscandidateSetIdas a digest over every eligible session'sid, name, workspace, status, updatedAt.candidates()is not cached -- it iscandidateSet(await this.#effects.listSessions()), re-derived from live session state on each call. So any unrelated session touchingupdatedAtrotates the whole identity, and the automatic Session title write named in the issue is exactly that kind of write. Both error codes you saw are that one digest being re-derived after the snapshot was taken.Four comparison sites, not two. Same call, same rotating id:
action-gate.ts:574-- delegate,candidate_set_staleaction-gate.ts:816-- replace,candidate_set_staleaction-gate.ts:961-- correct, and this onereturns silently, so it cannot surface as a code at allcoordinator.ts:601-- your site, and the widest window: it sits inside thecreatecallback of#requestForm, so the identity is re-derived after an unbounded wait for a human to answer the form. On that shape it does not matter what a branch under CI changes elsewhere, which is consistent with the two PRs you list being blocked on a check they cannot influence (I have not audited their diffs).The narrowing has a snag worth naming before anyone writes it.
candidateRefis derived from the set id --`whc_${hash(`${candidateSetId}\0${sessionId}`)}`at line 1157-1159, applied at line 1137. So ifcandidateSetIdhas rotated by the time the form is answered, every ref the user was just offered has rotated with it, and the membership lookup atcoordinator.ts:607-613fails for all of them. Dropping or relaxing the line 601 comparison on its own therefore does not fix the race -- it convertscandidate_set_staleintocandidate_unavailableand moves the rejection one frame down. Any fix has to make the ref itself stable, i.e. keycandidateRefon the selected session's identity rather than on a digest of the list it happened to be offered in, and then compare that rather than the set snapshot.updatedAtin the digest is what makes the identity churn on ordinary activity;idplus the workspace projection is what the decision actually depends on.That is a testable prediction, and it is the cheapest thing to check first: change nothing but the line 601 comparison and the failure should reappear as
candidate_unavailable. If it does not, the reasoning above is wrong and worth discarding.What I could not run here, so this stays analysis. Your note that the named test passes 6/6 focused on macOS and the CI failures are all on Linux runners matches my position: this host has no Linux container runtime and
packages/runtime-hosthas no installed workspace dependencies, so neither the flake nor a candidate fix can be executed and measured. I am not posting a patch against a race I cannot reproduce or disprove, and the four sites above are read, not exercised. Happy to take a fix if someone can drive it on a Linux runner -- or to write one against a reproduction I can actually trigger.sunrioa commentedon Sep 24, 2026
Tried to reproduce on a real Linux host; could not
You noted you cannot run this locally. I had a Linux box available, so I drove it there. It did not reproduce, and the way it failed to reproduce is itself informative.
Setup. OpenCloudOS 9.4, x86_64, 4 cores, Node 24.15.0, current
main(9082cf144), built from source, running the same command CI runs:npm --workspace @maka/runtime-host run test:dist.Result: four consecutive full-suite rounds, zero WorkHub failures.
All three WorkHub tests in
execution-composition.test.jspassed in every round, twelve executions in total: the one named in this issue,default production WorkHub selects and delegates through its durable Host interaction, andWorkHub Resume and Stop follow logical lineage across repeated physical handoffs.The eight failures are mine, not the suite's: I skipped the Electron binary download, and the host runs as root without bubblewrap, so the Electron-launcher, sandbox-boundary and account-home tests fail on environment alone. They are identical across all four rounds and none of them is in this file.
Focused runs do not reproduce it either: the named test alone, 6 rounds on this Linux host and 6 rounds on macOS 26.5.2 / Node 24.21.0, plus the whole file 5 rounds on macOS. 435 test executions, zero failures.
The duration is the interesting part. A round here takes 266-269 s. The CI run that failed on #5043 reported
duration_ms 269573.896563, i.e. 269 s. The suite is not running measurably faster or slower on this box than on the runner, so "a slower machine widens the window" does not explain the difference.What still differs from
ubuntu-24.04, for whoever picks this up:node-version: 24(latest 24.x)runnerCIenvtrueI have not isolated which of these matters. Note two of them point the opposite way from the obvious guess: this host has less memory and more baseline load than the runner, which should make a timing race more likely, not less.
So the reproduction environment is narrower than "Linux". If anyone wants to drive the falsifiable experiment you proposed -- change only the line 601 comparison and see whether the failure reappears as
candidate_unavailable-- GitHub Actions is the only place it is currently known to be observable.Analysis produced with Claude Code; the runs, the timings and the CI log references above were reviewed by me.
sunrioa commentedon Sep 24, 2026
Reproduction attempts, all negative. Recording them so the next person does not repeat them.
ubuntu-24.04, Node 24The CI attempts ran the full
@maka/runtime-hosttest:distsuite with the command and runner imageci.ymluses, including the bubblewrap install and the AppArmorunprivileged_usernssetting the managed Bash sandbox needs. Three machine states were tried: an otherwise idle runner (32 executions), CPU contention on two of four cores (15), and directly after the workspace test batchci.ymlschedules immediately before this suite (9). Neithercandidate_set_stalenorWorkHub Session candidates changedappears in any of the 56 logs.None of this shows the race is gone. It was last seen in real PR runs, where this suite is one late step of a forty-step job with a 45-minute budget. What it does suggest is that reproducing it needs more of that job's accumulated state than the suite alone provides.
One unrelated flake did surface under the CPU contention variant, filed separately as #5698.
Adarsh-Me commentedon Sep 25, 2026
Ran this on Linux-free Windows x64 (Node 24.21) against
0479fc761: 12/12 focused runs pass, so I cannot reproduce the flake here and won't claim a before/after measurement.First attempt showed 9/9 failures — that was my environment, not the race:
@maka/acp-executor-pluginis a newer workspace and was not linked, givingERR_MODULE_NOT_FOUND. Afternpm install+ building it, the run is clean.Next step I propose: a deterministic test that two candidate sets differing only in Session
nameproduce the samecandidateSetId, which pins option 1 without racing anything.sunrioa commentedon Sep 25, 2026
Two updates: a correction to my earlier comment, and a reproduction that no longer depends on the machine.
Correction. The four
WorkHub Resume and Stop follow logical lineage across repeated physical handoffsruns I listed under "mechanism unconfirmed" are not this issue, and "no error code" was wrong. The code is in the assertion message: all four aresession_busy/ "Session already has an active or pending root Turn". #5595 made a stopped delegation send a Host result Turn back to the WorkHub Session, and that test started its next Turn on the same Session before the result Turn finished. #5300 fixed it in the test withwaitForResultCompletion(7307131). All four failing trees contain #5595 and none contain 7307131. They can be dropped from the evidence here.A reproduction on any OS. The reasoning above holds on current
main(8d5a3cac3):candidateSetwith only one Session'snamechanged, or only itslastMessageAt, yields a differentcandidateSetId, and every candidate'scandidateRefchanges with it, including Sessions that did not change. The deterministic test proposed above fails as it stands.generateSessionTitle(from test(desktop): make E2E session naming deterministic #5022) so the title lands just afterworkhub.coordination.candidatesfails the delegation 20 of 20 times withcandidate_set_stale/ "refresh before delegating".Why it looks tied to one machine. The test's fake connection is
ollamaat its defaulthttp://127.0.0.1:11434/v1, so the title's latency is whatever that port on the test host does. With the named test unmodified and a stub on that port answering 404 after a set delay, six rounds each:With nothing on the port the connection is refused in about 24 ms, but the title call does not pass
maxRetries: 0the way the intent and recall calls in the same file do, so the SDK retries three times with backoff and the fallback title lands after about 6 s, past both windows. That fits a flake that failed 10 of 13 times on one machine and not once in roughly 500 runs on four others without anything on 11434. I have not seen the original machine, so this is consistent with it rather than proven.It does not explain the
candidate_set_staleon #5043's CI (a different test, the coordinator site), where nothing listens on 11434. That one is the same identity rotating on some other write; I have not identified which.sunrioa commentedon Sep 25, 2026
Larger batches of the two reproductions above, same
main:workhub.coordination.candidates: 20 of 20 delegations fail withcandidate_set_stale.127.0.0.1:11434answering 404 after 20 ms: 20 of 20 runs fail. The same test with nothing on the port: 0 of 10.The 20 ms figure is where the delegation window sits on this machine; it is only a few tens of milliseconds wide and will sit elsewhere on a faster or slower host. Injecting the title does not depend on timing, so it is the one to build a failing test on.
sunrioa commentedon Sep 25, 2026
Follow-up on the
candidate_set_stalefrom #5043's CI that the comment above left open. It is the same identity rotating, throughupdatedAtrather thanname, and it needs nothing on the host.In
default production WorkHub selects and delegates through its durable Host interaction, the test waits for the delegated Turn onbetato reportcompleted, reads candidates, and starts a secondselectAndDelegate. When that Turn completes, theturn_state: completedmessage is already inbeta's message log andturn.queryalready answerscompleted, but thelastMessageAtthe candidate list derivesupdatedAtfrom still holds the assistant message's time. It catches up to theturn_statetime a few milliseconds later. A candidate read inside that gap is rejected when the coordinator re-derives the set before offering the form, which is exactly "Discover fresh candidates before requesting a target choice".One run on
0cb4fc32b, the base CI merged #5043 into (#5043 only touchesruntime/network):beta'supdatedAtas the candidate list sees itturn_state: completedwrittenturn.queryreports completed,turn_statealready in the logReading candidates the moment the Turn reports completed and passing that read to
selectAndDelegatefails 10 of 10 times on that tree and 5 of 5 on currentmain(8d5a3cac3). The unmodified test did not fail in 30 runs under CPU load here: its poll interval and the followinginteraction.queryusually give the record time to catch up, which fits one failure on a slower CI runner. I have not traced which write moveslastMessageAt.This path does not go through
nameor port 11434, so droppingnamefrom the digest would leave it in place: an ordinary status message is enough to rotate the set. That supports keying the ref on the selected Session rather than narrowing the digest field by field.Adarsh-Me commentedon Oct 10, 2026
#5862 fixes this:
candidateSetIdnow digests only id, workspace and derived state, in id order, so a rename or timestamp on one Session can't rotate everycandidateRef.Your injected-title repro is now a deterministic test — re-ran it today: fails with only the gate reverted,
candidate_set_stale. The ~8 ms target-sideupdatedAtcatch-up stays open for review.fix(runtime-host): key the WorkHub candidate identity on the Session,…