M5 Gate Report: One Ordinary On-Demand Peer, Not a Second Runtime #

Milestone: M5 — One ordinary on-demand peer, not a second runtime
Owner: m5-gate (workstream D)
Date: 2026-09-11
Repository: /Users/dawn/proj/klbr
Snapshot: uncommitted working tree at gate-run time; no commit or pushed snapshot is claimed here.


1. Executive Summary #

M5 delivers on-demand klbr peer agency using existing agent/session machinery rather than introducing a second runtime, nested agent implementation, recursive spending framework, or automatic whole-scratchpad sharing. The implementation spans klbr-runtime (Store schema migration 010, LocalPeerHost, PeerHost trait, HostRequest protocol extensions), klbr-daemon (session registry integration and peer delegation), Python workbench bindings (klbr.peer and klbr.agents), and pure klbr-core orientation governance (OrientationScope::Peer, ReceivingContext, remote execution identity preservation).

Key structural guarantees established and proven:

  1. On-Demand Reviewer as Ordinary Peer (U28): Main opens one configured reviewer through the Python workbench SDK (agents.open / peer.open), passes selected immutable evidence, and receives discrete admission immediately. The reviewer operates as an ordinary klbr session with its own SessionId, independent workspace, and distinct store history—main's private scratchpad is never auto-replicated into reviewer context. Correlated results are queried by request_id, and only the designated task owner integrates changes.
  2. Restart Survival & Echo Loop Immunity (U29): Admitted requests are persisted durably in SQLite peer_requests (request_id PRIMARY KEY). After service interruption and full daemon restart across separate variants, the reopened store re-derives the request from durable SQLite state. The echo-loop property was verified across a growth count series ($N=5$ retries/acknowledgments): all retries reuse request identity, trigger zero additional inferences (captures_after == captures_before), and associate results exactly once. Subsequent result deliveries are strictly idempotent (already_completed).
  3. Peer Receiving Agency & Remote Execution Identity (S21): Reviewers maintain receiving agency within OrientationScope::Peer { peer_id }. Reviewers can adopt, revise, or reject orientation within their peer scope without corrupting or overwriting main's active wake (preventing shared-wake last-writer overwrite). Remote execution placement binds an execution target without creating a second target author or second model context; branch parent revisions and actual receiving context are durably recorded.

All distributed multi-daemon claims remain strictly NOT RUN (same-daemon with real restart is proven; multi-host recovery requires multi-daemon transport tests per U29). Real-model provider runs remain strictly NOT RUN due to absence of provider credentials in this environment.


2. Gate Table #

item owner exact command exit code + pass/fail honesty label mutation receipt
U28 — On-demand reviewer is an ordinary klbr peer m5-peer + m5-gate cargo test -p klbr-daemon --test m5_peer_gate -- u28 --nocapture 0; 1 passed, 0 failed YES Mutated klbr-runtime/src/peer.rs:139 from "status": "admitted" to "status": "completed"; exit 101, panic Step 1 (open and send) must succeed: Cell { status: Error ... AssertionError: assert receipt.status == "admitted" } at m5_peer_gate.rs:88:5; restored to exit 0. Reachability confirmed: live model tool dispatches through LocalPeerHost and validates discrete admission before result creation.
U29 — Peer message survives real restart without an echo loop m5-peer + m5-gate cargo test -p klbr-daemon --test m5_peer_gate -- u29 --nocapture 0; 1 passed, 0 failed YES Mutated klbr-runtime/src/store.rs:2689 from return Ok(PeerAdmitOutcome::AlreadyAdmitted(...)) to return Ok(PeerAdmitOutcome::Admitted(...)) (bypassing idempotency early return on retry); exit 101, panic Retry series must succeed with duplicate=True at m5_peer_gate.rs:303:5 (failing assert duplicate_count == 5, got 0); restored to exit 0. Reachability confirmed: reopened store recovers durable state across restart, prevents endless inference over 5 retries, and enforces single association.
S21 — Peer receiving agency and remote execution identity m4-orient + m5-gate cargo test -p klbr-core --test m5_peer_gate -- s21_ --nocapture 0; 3 passed, 0 failed YES Mutated klbr-core/src/agent/orientation.rs:577 from self.active.insert(candidate.scope.clone(), ...) to self.active.insert(OrientationScope::Global, ...) (simulating last-writer overwrite across peer scopes); exit 101, panic assertion left == right failed (None == Some("rev-peer-...")) at m5_peer_gate.rs:91:5; restored to exit 0. Reachability confirmed: reviewer scope adoption preserves main wake identically and commute across interleaving orders.

3. Four Honesty Labels #

All gates evaluated against the rigorous four-label standard:

  • YES: Requirement fully satisfied by real production code, exercised across real daemon/store/runtime boundaries, verified by non-tautological assertions, and proven reachable via exact mutation receipts. (U28, U29, S21).
  • NO: Implementation absent, broken, or failing required invariants. (None).
  • PARTIAL: Implementation partially complete or verified only at a subsystem boundary without full production wiring. (None for M5; all M5 gates fully wired through production entrypoints).
  • NOT RUN: Scenarios requiring hardware/environment capabilities not available on this machine (multi-daemon distributed transports, external LLM provider credentials). (Documented in Section 4).

4. NOT RUN #

  1. Cross-Daemon Distributed Recovery (U29):
    • Status: NOT RUN
    • Reason: U29 explicitly forbids advertising a single-process or single-daemon test as multi-host recovery ("Distributed mode is claimed only if tested across separate stores/transports"). While single-daemon restart survival across separate variants with reopened SQLite store is fully proven and passing, cross-daemon cluster replication across independent daemon processes with network transports has not been executed and is honestly declared NOT RUN.
  2. Real-Model Follow-On (S21 / Real-Model Reviewer):
    • Status: NOT RUN
    • Reason: No real LLM provider credentials or local weight engines exist in this test environment. All live model interaction was verified through the standard local mock provider (klbr-daemon/tests/common/mod.rs) asserting exact request payload framing, token budgets, and zero echo inference emissions.

5. Defects Found & Resolved #

  1. Session Reference Leak Across Restart Boundaries:
    • Discovery: When attempting daemon restart in u29_peer_message_survives_restart_without_echo_loop, Store::open failed with WouldBlock on the .owner.lock file.
    • Root Cause: In the test harness, entry1 (Arc<SessionEntry>) was retained in scope across the daemon1.stop().await boundary. Each SessionEntry retains a clone of SessionRuntime, which retains Store, which retains the Arc<File> owner lock.
    • Fix: Ensured all SessionEntry handles are explicitly dropped before daemon quiescence and reopen, enabling SQLite file lock release without lingering thread contention.
  2. Strict Peer Scratchpad Isolation:
    • Discovery: U28 requires proving no automatic sharing of the whole main scratchpad. Initial assertions checked for total event emptiness in the reviewer session, but needed to distinguish between session provisioning records (ensure_session) and conversational turns.
    • Fix: Added negative assertion over reviewer history: verified that main session's causal inputs (u28-main-init) and prompt blocks never leak or replicate into the reviewer's private session stream.
  3. Non-Generative Echo Loop Defense:
    • Discovery: A one-shot retry test is insufficient to prove immunity against acknowledgement loops. If an implementation dispatches inference on receipt of an ack, the system loops endlessly.
    • Fix: Gate U29 drives 5 consecutive duplicate admissions through the reopened store and verifies that provider captures remain strictly at 0 new requests (captures_after == captures_before), while recording duplicate == true on every retry.

6. Workspace Health & Limitations Disclosure #

  • Workspace Build & Test Status: Both cargo test -p klbr-core --test m5_peer_gate and cargo test -p klbr-daemon --test m5_peer_gate pass with exit code 0.
  • Untracked / Modified Artifacts: The working tree contains new implementation files (klbr-runtime/migrations/010_peers.sql, klbr-runtime/src/peer.rs, klbr-daemon/src/peer.rs, python/klbr-runtime/src/klbr/peer.py, python/klbr-runtime/src/klbr/agents.py, klbr-core/tests/m5_peer_gate.rs, klbr-daemon/tests/m5_peer_gate.rs) and modifications to integrate them. Per instructions, no commits or pushes have been made.

Retired citations (added later) #

The gate suites cited above — klbr-daemon/tests/m5_peer_gate.rs and klbr-core/tests/m5_peer_gate.rs — no longer exist: they repeated whole-service setup, so they were retired in favour of the suites listed in docs/retirement-ledger.md. The commands quoted in this report are therefore a record of what was run when it was written, not something a reader can re-run. Peer request admission and the dispatch worklist are covered today by klbr-runtime/tests/peer_store.rs.