Skip to content

fix: recheck zcode route ownership after replacement discovery on exit handoff - #62

Merged
anuzzolilli-oss merged 2 commits into
masterfrom
2026-11-14_zcode-exit-handoff-recheck-ownership
Nov 14, 2026
Merged

anuzzolilli-oss merged 2 commits into
masterfrom
2026-11-14_zcode-exit-handoff-recheck-ownership

Conversation

@anuzzolilli-oss

@anuzzolilli-oss anuzzolilli-oss commented Nov 14, 2026 •

Copy link
Copy Markdown
Owner

(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:

  • right after replacement discovery returns, before any write;
  • again before the direct revert that follows a re-route which returned nothing.

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.ts use the existing findReplacement seam 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 is not-ours and the store is byte-identical to what the new owner wrote.

  • Before the fix (master 9d4bda8e5): both fail. Outcomes were reverted-direct and handed-off, so the new owner's route was removed or overwritten.
  • After the fix: tests/zcode-native.test.ts 39 of 39 pass, 0 skipped (Windows 11, Node v24.14.0). tsc --noEmit clean.
  • Added after review: two tests for the second re-check. A signing-era store with route plans makes the re-route refuse; in one case the store moves to another owner during that refusal. Changed ownership gives not-ours with the store byte-identical; retained ownership gives reverted-direct. With that guard deleted the first case fails, and with it made unconditional the second fails.
  • The three existing handoff tests are the other direction: a route we still own is still handed off or reverted.

Limits, stated plainly

  • This narrows the window; it does not close it. routeZcodeConfig reads the store, then awaits the config lock, then writes, and unrouteZcode writes 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.
  • repairSharedStoreDrift has the same read, await, write shape. It is not touched here and is filed separately.
  • Not exercised against a real ZCode install or the live proxy. This is not deployed.

Assisted-by: Cindy (https://cindy.app)

…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)
@github-actions

github-actions Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

📦 Built Package Artifact

Branch: 2026-11-14_zcode-exit-handoff-recheck-ownership (d24bea3)

Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pr62.tgz
npm install -g package

Install instructions are refreshed on each push.

Comment thread src/zcode/native.ts
log(`exit handoff: store → ${replacement.origin}`);
return "handed-off";
}
if (!stillOurs()) return "not-ours";

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(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.

@kilo-code-bot

kilo-code-bot Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

Code Review Summary

(ai: openai/gpt-6-astra)

Status: No Issues Found | Recommendation: Merge

Reviewed the incremental test changes at d24bea3127d97b953b4a3b72cf02989de5bf95c4 and performed targeted verification of the prior ownership-guard finding. Standard depth, not Light, because shared-store persistence is affected. Static review only; tests were not executed under the read-only restrictions.

Files Reviewed (2 files)
  • tests/zcode-native.test.ts
  • src/zcode/native.ts (targeted prior-finding verification)
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 f0b887024ada060ec3699a2dea18489bc5f7649d using standard depth, not Light, because shared-store persistence is affected. Static review only; tests were not executed under the read-only restrictions.

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 0
Issue Details (click to expand)

WARNING

File Line Issue
src/zcode/native.ts 611 The post-reroute ownership guard lacks both required test directions: preserve a new owner's store after routing refusal, and revert direct when ownership is retained. All current handoff tests bypass this guard.
Files Reviewed (2 files)
  • src/zcode/native.ts - 1 issue
  • tests/zcode-native.test.ts - 0 additional issues

Reviewed by gpt-6-astra · Input: 39 · Output: 4.6K · Cached: 573.3K

Review guidance: REVIEW.md from base branch master

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)
@anuzzolilli-oss
anuzzolilli-oss merged commit 6f847d1 into master Nov 14, 2026
44 checks passed
@anuzzolilli-oss
anuzzolilli-oss deleted the 2026-11-14_zcode-exit-handoff-recheck-ownership branch November 14, 2026 18:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Zcode exit handoff can overwrite routing transferred during replacement discovery

1 participant