Repository navigation
fix(zcode): store-drift repair re-checks the store's owner before each write (#63) - #73
Conversation
…h write (#63) repairSharedStoreDrift read the shared store's origin once, awaited up to two health probes and replacement discovery, then wrote without looking again. A route another process wrote during those awaits could be overwritten with this process's origin or a replacement, or reverted to direct. Each of the three writes is now allowed only while the store still points at the dead origin first read. The two route writes ask under the config lock (the existing shouldWrite hook); the revert re-checks immediately before it, which also stops a declined route write from falling through into a revert. New outcome "owner-changed" for the stand-down. Assisted-by: Cindy (https://cindy.app)
📦 Built Package ArtifactBranch: Download artifact
tar xzf billion-context-pr73.tgz
npm install -g packageInstall instructions are refreshed on each push. |
| const dir = dataDir(); | ||
| try { | ||
| await routeZcodeConfig({ origin: DRIFT_DEAD, dataDir: dir, env: {}, log: NO_LOG }); | ||
| const outcome = await repairDownPath(dir, writePath, () => {}); |
There was a problem hiding this comment.
(ai: kilo/openai/gpt-6-astra)
WARNING: Successful control tests POST to unowned fixed ports
The self and replacement controls mock health probes, but this call still reaches activateZcodePluginMode (src/zcode/native.ts:578,587), which calls reportRuntimeInfo and sends a real POST to /__bili/plugin/runtime-info (src/agent/shared.ts:298-303). With DRIFT_SELF/DRIFT_REPLACEMENT, those requests target fixed localhost ports 28787 and 48787. If another bili instance is listening there, the fixture replaces its agent-level zcode runtime-info entry (src/plugin.ts:609-614,676-685); an unresponsive listener instead adds a five-second timeout. Temporary store directories and env: {} do not isolate this network side effect. Use an owned listen(0) server for successful destinations, or stub the runtime-info request with test-scoped restoration.
There was a problem hiding this comment.
(ai: anthropic/claude-fable-5-2)
Valid, fixed in 00890c2. The self and replacement origins in the new tests are now loopback servers the test starts on allocated ports (withDriftOrigins), so the runtime-info post of a successful repair lands on a server the test owns. The dead origin and the new owner are never contacted: liveness comes from the probe seam and those writes do not reach activateZcodePluginMode. Against the original code the same 7 tests still fail.
The older exit-handoff tests in this file use the fixed origin 127.0.0.1:28787 in the same way (lines 803 to 904 on this head). They predate this PR, so I left them; say if you want them changed here or tracked separately.
|
(ai: kilo/openai/gpt-6-astra) Code Review SummaryStatus: No Issues Found | Recommendation: Merge Reviewed the incremental test-fixture changes in Previous Review Summary (commit 9ce97ca)Current summary above is authoritative. Previous snapshots are kept for context only. Previous review (commit 9ce97ca)(ai: kilo/openai/gpt-6-astra) Code Review SummaryStatus: 1 Issue Found | Recommendation: Address before merge Reviewed the shared-store ownership guards and regression tests at Overview
Issue Details (click to expand)WARNING
Files Reviewed (2 files)
Reviewed by gpt-6-astra · Input: 33 · Output: 4.1K · Cached: 483.9K Review guidance: REVIEW.md from base branch |
…wn (#63) A successful repair calls activateZcodePluginMode, which posts runtime info to the origin it routed to. The new tests used fixed ports for the self and replacement origins, so a bili instance listening there could have received that post. Both origins are now loopback servers the test starts on allocated ports. Assisted-by: Cindy (https://cindy.app)
(ai: anthropic/claude-fable-5-2)
Closes #63.
What changes
repairSharedStoreDrift(src/zcode/native.ts) read the shared store's origin once, then awaited up to two health probes and, on one branch, replacement discovery, and wrote without looking again. A route another process wrote during those awaits could be overwritten with this process's origin or a replacement, or reverted to direct.Each of the repair's three writes is now allowed only while the store still points at the dead origin first read:
shouldWritehook (added in fix(zcode): decline the watchdog's route write once shutdown has begun (#67) #68), immediately before the write.unrouteZcode. This check also covers a declined route write, which would otherwise fall through and revert the new owner's route."owner-changed"and logsstore drift repair: the store no longer points at <origin> — leaving it untouched. The only production caller (src/zcode/mcp-entry.ts) discards the outcome, so nothing else changes.A store that went direct during the awaits is also left alone: the predicate is "still the dead origin", not "not someone else's".
Evidence
tests/zcode-native.test.ts, 10 new tests (49 of 49 in the file;zcode-mcp-eof17,zcode-mcp-entry9,zcode-mcp-degraded6 unchanged and passing). Windows 11, Node v24.14.0. Typecheck and both static checks clean.Transfer during the awaits, one test per write path (self, replacement, revert): another owner routes the store inside the
probe/findReplacementseam; the store is byte-identical afterwards and the outcome isowner-changed.Went direct during the awaits (self, replacement): the store is not re-wrapped.
Transfer while waiting for the config lock (self, replacement): the store still points at the dead origin when the route call starts and changes only while the lock is held by another writer.
Controls, one per write path: with nothing changed during the awaits the repair still writes (
repointed-self,repointed-replacement,reverted-direct).Ports: the self and replacement origins are loopback servers the test starts on allocated ports, because a successful repair posts runtime info to the origin it routed to (added after review). The dead origin and the new owner are never contacted.
Mutation checks, each restored afterwards:
shouldWriteon the self routeshouldWriteon the replacement routeNot covered
unrouteZcodetakes no config lock, so its re-check narrows the cross-process window to a synchronous read-then-write but does not close it. Putting the revert under the lock is the separate decision Zcode store-drift repair can overwrite a route transferred during its health probes #63 defers; not decided here.routeZcodeConfigcomputes its rewrite from text read before it takes the lock (existing behaviour). With the owner check passing, other edits made to the file in that window are still overwritten. Out of scope here.Assisted-by: Cindy (https://cindy.app)