Skip to content

fix(mcp,contract): scope lease_status to this session; restore the §1 boundary test - #103

Merged
V3RON merged 5 commits into
fix/0003-09-error-parityfrom
fix/0003-10-mcp-hygiene
Sep 4, 2026
Merged

V3RON merged 5 commits into
fix/0003-09-error-parityfrom
fix/0003-10-mcp-hygiene

Conversation

@V3RON

@V3RON V3RON commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Stacked on #102. Three blocking defects from the adversarial review, plus the dead-code cleanup ADR §11 implies.

lease_status reported a lease the session does not hold

The handler's doc-comment claimed lease.list returns at most one entry because "this session only ever requests mode: "held" leases under one requester id". That is not what lease.list does — the dispatcher filters by owner principal only, with no mode or connection filter — and the handler took leases[0] blindly.

With SIMLOCK_AGENT_ID=agent-7, the CLI and MCP share a principal. An agent running simlock lease --detach in a shell and then calling MCP lease_status got {held: true, mode: "detached"} for a lease its connection never requested and will not release on close. The cache-based implementation this stack deleted got this right.

lease_status still calls lease.list unconditionally — no cache of lease state returns, which is what §11 removed — but the session now tracks only the id of the lease its own lease() call obtained, cleared on release and on the lease-lost push, and filters to mode === "held" and that id. The false doc-comments are corrected.

The boundary test enforcing §1 was blind to multi-line imports

boundary.test.ts kept only lines matching ^\s*import\s and looked for from "…" on that same line. The repo's own formatter breaks any import with more than one named binding across lines — so for exactly the style this project writes, the import { line has no from and the } from "../core/index.js"; line was never examined at all.

The single mechanism enforcing ADR §1's central constraint — "the contract imports nothing from core, daemon, or drivers … this is what keeps private types out of the public package surface" — would have passed a multi-line import { DeviceRecord } from "../core/index.js"; in schemas.ts.

Now it strips comments and scans the whole file, matching the approach no-core-leak.test.ts already used correctly. The fix was demonstrated: a multi-line core import was temporarily added to schemas.ts, the suite failed as it should, and the import was reverted.

Gates that were failing, both clean on main

  • README.md had three JSON examples collapsed onto single lines, failing format:check. Reformatted — and while verifying them against the current schemas, the progress push example turned out to be wrong: the CLI emits it flattened, with no nested progress key. Fixed.
  • fallow reported dead exports left over from the hand-written parsers §11 says are deleted.

The daemon-client package is deleted

Chasing those dead exports showed the whole of src/daemon-client/ was referenced only from comments — src/simlock-client/ supersedes it entirely. Six modules and their tests are removed, so §11's "raw parsers and hand-built payloads deleted" is finally true rather than approximately true. A fallow suppression that went stale when queueDepth moved behind the dispatcher goes with them, and the comments naming the deleted module are repointed.

After this the fallow gate reports zero dead code and one fewer duplication group.

lease.list filters by owner principal only, with no mode or connection
filter, so it could return a held/detached lease this MCP connection
never requested (e.g. the CLI's --detach lease under the same
SIMLOCK_AGENT_ID principal). lease_status took leases[0] blindly,
reporting a foreign lease as held and never releasing it on close.

Track the id of the lease this session's own lease() call obtained
(not a cache of its state -- always re-read via lease.list) and filter
status() to mode === "held" && id === that tracked id. Correct the
false doc-comment claiming leases holds at most one entry.
The CLI emits {push:"progress", ...progress} flattened -- no requestId, no nested
"progress" key -- not the wrapped shape the example showed.
parseRawLeaseLost and parseRawLeaseProgress (and their RawLeaseLost/
RawLeaseProgress types) are leftovers of the hand-written push parsers
ADR 0003 §11 replaced with the typed contract client -- fallow flagged
both as unused exports, and neither is referenced anywhere in the
repo, including this file's own test.
The test kept only lines matching ^\s*import\s and extracted "from"
from that same line. The project's formatter breaks any import with
more than one named binding across multiple lines, so for such an
import the "import {" line has no "from" and the "} from '...'" line
is never in scope at all -- the one mechanism enforcing ADR 0003 §1's
"the contract imports nothing from core/daemon/drivers" was blind to
the import style this repo actually writes.

Strip comments and scan the whole file text for from "..." specifiers
instead, the way src/simlock-client/no-core-leak.test.ts already does.
Verified by temporarily adding a multi-line `import { ... } from
"../core/index.js"` to schemas.ts: the old logic missed it, the new
logic fails on it.
The typed client in src/simlock-client supersedes it entirely; nothing outside
the package imported it any more, so ADR 0003 §11's "raw parsers and hand-built
payloads deleted" is only true once these six modules go with them.

Also drops a fallow suppression that went stale when queueDepth moved behind the
dispatcher, and repoints the comments that named the deleted module.
@V3RON
V3RON force-pushed the fix/0003-10-mcp-hygiene branch from 1633232 to 30c9dbb Compare September 4, 2026 06:25
@V3RON
V3RON merged commit ef5c2d6 into main Sep 4, 2026
8 of 11 checks passed
V3RON added a commit that referenced this pull request Sep 4, 2026
**Stacked on #103.** Two client-side push-bookkeeping defects from the
adversarial review.

## A second crash on the same lease was silently dropped

`#deliveredLeaseScoped` was a `Set` keyed `${kind}:${leaseId}` that was
**never pruned**. This was self-reported as merely swallowing a
duplicate `device-recovered`; it also swallowed a second
**`device-unhealthy`**, which is the dangerous direction.
`LeaseHealthMonitor` clears its recovery bookkeeping after a successful
recovery, so a second crash on the same lease genuinely re-emits
`device.crash-detected` — and the client dropped it. Neither the CLI's
stderr lines nor MCP's health notifications reported the second cycle,
so **the agent kept driving a dead simulator**.

The test that supposedly covered this pushed two identical
`device-unhealthy` frames with **no intervening `device-recovered`**, so
it passed under both the correct and the broken semantics.

Now split in two:

- `lease-lost` keeps a permanent per-lease key — loss is genuinely
terminal.
- Device health is a **toggle**: delivering one kind clears the other's
eligibility, so `unhealthy → recovered → unhealthy` delivers all three,
while two identical pushes in a row are still suppressed.

The misleading test is fixed and a full-cycle test added.

## Self-initiated release marks leaked permanently and muted genuine
losses

The client-side `#selfInitiatedReleases` set was add-only, cleared only
by a matching `lease-lost` push. The daemon already suppresses that push
to the releasing connection (and clears its own bookkeeping in a
`finally`), so on a healthy release the client entry was never consumed
— pure residue. On a **failed** release it was a permanent mute: mark
`L1`/`L2`, have the release reject, and when `L1` later expires the real
`lease-lost` is swallowed. The client then believes it holds a lease the
daemon has already reclaimed.

Dropped the client-side set entirely rather than wrapping it in a
`finally` — the daemon's suppression already implements ADR §8's rule,
and one mechanism is better than two that must agree. A regression test
proves a real `lease-lost` after a *failed* release is still delivered.

## Coverage added

The heartbeat pong, the four malformed-push `safeParse` drop branches,
and `releaseAllLeases`'s held-lease bookkeeping — none had any coverage.

## Note

The health-state map is still unpruned per lease, so it grows with
distinct leases seen over a connection's life — the same bound as
before, not a new leak, but unbounded in principle on a very long-lived
connection with heavy churn.
@V3RON
V3RON deleted the fix/0003-10-mcp-hygiene branch September 9, 2026 17:12
V3RON added a commit that referenced this pull request Nov 29, 2026
… its prompt (#1946)

## Why

The deliver orchestrator walks a fixed path in prose after every stage
report: 7.4 Opus turns per stage, 24–34% of delivery spend. In 9 of 24
replayed deliveries the first build spawn was refused for its ledger
line. Two finished fixes were parked because a review round ran no lens.

## What

- `.agents/scripts/deliver-step.mjs <pr|issue> --report <file>` reads
the report, `pr-shas.sh` and `ci-triage.mjs`, re-runs flaky or unknown
CI, writes `### Status`, and prints the next stage's whole prompt,
`decide:`, `finish:`, `gate:`, `park:` or `done:`.
- Every prompt it prints carries the ledger line the guard accepts.
- A round 1 or 2 reported incomplete with no lens started runs once
more; a second incomplete parks.
- The `deliver` skill runs the script after every stage. Skill and
`feature.md`: 435 lines before, 323 after. The push-notification line is
gone (#1943).

## Proof

```
replay: every stage report of 24 sandbox deliveries and 85 real deliver
  sessions (2026-11-15..28), fed to the script with the state folded from
  the issue's earlier reports
  path, sandbox: 114/126 same    path, real: 437/488 same
  differences (sandbox 24, real 107): the script follows the rules in 79,
  an ADR flip adr-flip.mjs now does in 14, the orchestrator's own call
  (--fix, --hardware, its own park) in 38; none where the script breaks a rule
  142 real reports of PRs resumed mid-way were not replayed
starts: 75 first spawns, all pass tool-guard.mjs; recorded: 29 refused
change 3: 6 cases (#77, #103 and 4 real), each gets one rerun
--report <output-file>: 765 of 770 agent transcripts yield the notification's
  report; lens counts 284 of 284
turns: 5.7 per stage (sandbox), 7.4 (real); report to next spawn median 2,
  p90 7. Absorbed calls: 615 pr-shas/ci-triage, 249 Status writes, 50 reruns
src/deliver-step.test.ts: 56 tests; every review fix fails its test by mutation
live: one sandbox delivery at 00bc26e (real PR #1672) merged in 26.7 min,
  11 sub-agent runs, one deliver-step.mjs call between each report and the
  next spawn, 0 refused spawns (2 in each of 3 earlier runs), a red gate
  handled by fix run and fix-check
```

Not verified, next step: fewer orchestrator calls per spawn overall
(3.0, as before); 15 of 32 calls are preflight, Done when ticks, ready
and gate, ledger and the run report. Raw agreement is under the 95% the
proposal set.

## Review

Spec review: skipped. Code review: 13 blocking, 13 fixed, 0 notes.
Claims review: 2 blocking, 2 fixed, 0 notes.
Rounds: 5. Tokens: 6.7M.
Assessment: complete

*Written by an agent.*
V3RON added a commit that referenced this pull request Nov 29, 2026
… lens is sent back, and script tests are linted for Windows traps (#1950)

## Not verified

```
These checks stop the forms agents use, and mistakes; a call built to evade them (through a
script file or another interpreter, say) is stopped only at the merge gate: pr-body-check.mjs,
and the author check of PR #1944.

Last fix run (lens check at e411922):
- R4  gh-argv.mjs reads gh's arguments as gh does (-R/--repo/--hostname first, --flag=value,
      glued and combined short flags); the shim's body and label checks and the guard's write
      check all use it. A sub-agent's `gh alias` or alias is refused; extensions pass.
- R2, R20  the guard reads the mark and the shim bypasses from the parsed words (quotes removed,
      pieces joined, strings kept whole, `bash -c` scripts included); a sub-agent's eval or a
      sourced file the same call wrote is refused beside a gh write; a `gh` function always.
- R21 delivery.md says which of the two refuses what.

Replay at a8cbec0 (CI green), 28 days: 17,144 Bash calls (11,175 sub-agent). Guard, new
rules: 0 refused (eval and a sourced file it wrote refuse only beside a gh write). Shim,
sub-agent mode, 4,650 gh commands: 1 refusal, a reviewer's deliberate probe. Bodies on GitHub's text: 1,001 found, false refusals 0.

#1944's guard test now belongs to the shim's tests (the guard no longer reads labels).
A sandbox delivery with the shim at e411922 merged two deliveries; bodies and labels passed.
```

## Why

Workflow review 2026-11-27 (instructions-and-tokens 6, review-and-gates
8). Replayed deliveries lost 3.2 turns each to refusals: unreadable
bodies, wrong `ledger:` lines, review rounds with no lens.

## What

- A `gh` shim first on PATH (`session-env.sh`) checks a body when gh
runs. The guard stops parsing bodies, and refuses gh by a path or after
a PATH change.
- A wrong `ledger:` line is rewritten, or refused with the exact line.
- `report-guard` sends back a round 1 or 2 with no lens, reads its lines
loosely, and lets a clean later check skip the findings file.
- The test lint flags three Windows traps in agent-script tests.
- The shim lets a sub-agent write labels only by `gh issue|pr edit` or
`create` label flags (all 28 days of real use), never removing
`fast-track` or `fast-track-review`.
- Findings need `path:line`; a later check's inputs carry the previous
`findings.json`.

## Proof

```
Replay at this head, transcripts of 28 days: 9,844 Bash calls that run gh (3,881 sub-agent).
  guard, new rules: 0 refused (one main-session `export PATH=...; gh api -X POST .../cancel`
                    was, until the rule counted only calls the shim checks)
  shim, sub-agent mode, 4,650 gh commands: 1 label refusal, a reviewer's deliberate probe
                    (`gh api --hostname 127.0.0.1:9 -X=DELETE .../labels/fast-track`); 0 false
  bodies on GitHub's text: 1,001 found, 1,000 pass, 1 real defect: false refusals 0 of 1,001

Shim: every gh issue|pr|api call with a body, transcripts 2026-11-08..28: 1,408 (470 sub-agent).
The guard's verdict as recorded; the shim run on the body rebuilt from the transcript.
  guard passed           1,110   replayed on the text GitHub received (a comment by the URL gh
                                 printed, else by time; an edit or create by its edit history):
                                 1,001 found: shim passes 1,000, refuses 1, a real defect (PR #1766
                                 body at 14:11 had no footer; added at 14:18). False refusals: 0 of
                                 1,001. Not found 109: 67 releases or reviews, 40 creates whose
                                 output the transcript dropped, 2 with no version in 10 minutes
  guard: body shape         57   shim refuses the same defect 43, unknown 9, passes 5 (the guard
                                 read the file before `printf <footer> >> f` earlier in the call)
  guard could not read     235   (122 `$(...)`/variable, 113 file not there yet) shim verdict on 111:
                                 102 pass, 9 refused (7 footer or handoff, 2 triage over 300 words)
  gh run by a path            0   in 28 days

Ledger tag: 44 spawns refused in 28 days (25 sessions, 19 a second time in a row):
  36 repaired (32 `[ledger #N implement]`-style builds), 8 refused with the exact line.

Report guard, 720 reviewer runs, 28 days:
  round 1 or 2 with no lens: 57 (25 r1: 8 said complete, 17 incomplete; 32 r2: 27 complete)
    all 57 sent back; 0 of 473 runs that started a lens; 0 of 170 fix-checks with none.
  sends-back then: 424 in 310 runs; 311 pass now (36 once their file exists), 98 still sent back
  named cases as tests: before-2 #77, after-1 #103 (incomplete), PR #1862 round 1 (complete)

path:line: 834 of 854 findings in 316 ledgers (PRs merged 10-29..11-27) have no line.

Windows lint: flags PR #1919's first head (fake pmset -g), PR #1924 at 1c9611f (CRLF quote)
  and 031fc6a (2 merges with no git identity); 0 on both merged heads; 0 on main's 778 test
  files. Misses 1caed1e (fakeCommandEnv where the fake is written only off Windows).

Sandbox passes, 77 refusals in 24 deliveries: #1923 repairs 17, this PR removes 45 (18 ledger
  spawns, 27 bodies), 15 left: 3.21 -> 0.63 per delivery (after-1, with #1923: 3.25 -> 0.75);
  Agent spawns refused 19 -> 1. About 2 of the 27 bodies hold a real defect the shim refuses.
```

## Review

Spec review: skipped. Code review: 9 blocking, 9 fixed, 0 notes. Claims
review: 3 blocking, 3 fixed, 0 notes.
Rounds: 5. Tokens: 10.6M.
Assessment: complete

*Written by an agent.*
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.

1 participant