Repository navigation
fix: recheck zcode route ownership after replacement discovery on exit handoff - #62
Conversation
…t handoff handoffZcodeRoutingOnExit checked that the shared store pointed at its own origin only before awaiting replacement discovery. Another process could take the route during that await, and the exiting process then overwrote it with the replacement or reverted it to direct. Ownership is now re-read after the await and again before the direct revert that follows a failed re-route. A store that changed owner is left untouched and the outcome is "not-ours". Refs #13 Assisted-by: Cindy (https://cindy.app)
📦 Built Package ArtifactBranch: Download artifact
tar xzf billion-context-pr62.tgz
npm install -g packageInstall instructions are refreshed on each push. |
| log(`exit handoff: store → ${replacement.origin}`); | ||
| return "handed-off"; | ||
| } | ||
| if (!stillOurs()) return "not-ours"; |
There was a problem hiding this comment.
(ai: openai/gpt-6-astra)
WARNING: Cover both outcomes of the post-reroute ownership guard
Both new cases return at the earlier post-discovery check, and the existing handoff tests either successfully route or bypass this replacement block. Removing this guard would therefore leave the handoff tests passing even though a refused re-route could then strip another owner's route; an unconditional return here would also pass while leaving our exiting origin in place. AGENTS.md and the Gate Test Discipline require positive and negative assertions for every new gate.
Add replacement-present cases that force routeZcodeConfig to return undefined: changed ownership must produce not-ours with unchanged store bytes, while retained ownership must produce reverted-direct and remove the wrappers. A pre-wrapped signing-blocked personal store with BILI_ZCODE_ROUTE=plans can force refusal; the existing injected log callback can change the stored origin when that refusal is logged, without adding a production test seam.
Code Review Summary(ai: openai/gpt-6-astra) Status: No Issues Found | Recommendation: Merge Reviewed the incremental test changes at Files Reviewed (2 files)
Previous Review Summary (commit f0b8870)Current summary above is authoritative. Previous snapshots are kept for context only. Previous review (commit f0b8870)(ai: openai/gpt-6-astra) Status: 1 Issues Found | Recommendation: Address before merge Reviewed both changed files at Overview
Issue Details (click to expand)WARNING
Files Reviewed (2 files)
Reviewed by gpt-6-astra · Input: 39 · Output: 4.6K · Cached: 573.3K Review guidance: REVIEW.md from base branch |
Review of #62: the guard before the direct revert that follows a refused re-route had no test. A signing-era store with route "plans" makes the re-route refuse; the injected log callback moves the store to another owner in one case. Changed ownership must give "not-ours" with the store byte-identical; retained ownership must give "reverted-direct". The new handoff tests also pass an isolated env so no ambient store override can redirect them. Refs #13 Assisted-by: Cindy (https://cindy.app)
(ai: anthropic/claude-fable-5-2)
Closes #13
What this changes
handoffZcodeRoutingOnExit(src/zcode/native.ts) checked that the shared provider store pointed at this process's origin only before awaiting replacement discovery. If another process took the route during that await, the exiting process then either overwrote it with the replacement it found or reverted it to direct.Ownership is now re-read:
When the store has changed owner, nothing is written, one log line records it, and the outcome is
not-ours.Evidence
Two new tests in
tests/zcode-native.test.tsuse the existingfindReplacementseam to re-point a real scratch store to a third origin during discovery, then return either no replacement or a replacement. They assert the outcome isnot-oursand the store is byte-identical to what the new owner wrote.9d4bda8e5): both fail. Outcomes werereverted-directandhanded-off, so the new owner's route was removed or overwritten.tests/zcode-native.test.ts39 of 39 pass, 0 skipped (Windows 11, Node v24.14.0).tsc --noEmitclean.plansmakes the re-route refuse; in one case the store moves to another owner during that refusal. Changed ownership givesnot-ourswith the store byte-identical; retained ownership givesreverted-direct. With that guard deleted the first case fails, and with it made unconditional the second fails.Limits, stated plainly
routeZcodeConfigreads the store, then awaits the config lock, then writes, andunrouteZcodewrites without taking the lock. A process that takes the route between the re-check and the write can still be overwritten. Closing that needs an ownership check inside the locked write (compare-and-set), which is a persistence-behaviour change and is not attempted here. That needs an owner decision before anyone builds it.repairSharedStoreDrifthas the same read, await, write shape. It is not touched here and is filed separately.Assisted-by: Cindy (https://cindy.app)