Repository navigation
feat(cli): name a refused turn's class on release, with one predicate for both sites (TASK-099) - #1835
Conversation
066715b to
aa934c0
Compare
…ing any integer (TASK-099) Vera's hold on #1835. The release forwarded `status` on `Number.isInteger` alone, while the kernel records one only between `MIN_UPSTREAM_STATUS` (400) and `MAX_UPSTREAM_STATUS` (599). An out-of-range number therefore did not merely lose the number: the kernel answers 400, and the backward-compat fallback in `enforcement.release` re-releases as `completed` — terminal. An upstream refusal on a human wake carrying an out-of-range status would be recorded as a clean completion and lose its handoff. The predicate now carries the bound, so the sender's rule is the receiver's rule. An out-of-range status keeps the CLASS and drops only the number, which is what preserves the handoff. The constants are named and exported so the range has one owner on this side, and the tests pin 400/599 as literals rather than reading them back from the constants they test. Mutation-proved (6/6 killed, /tmp/kai099status-ledger.py): range removed entirely; either bound made exclusive; either bound dropped alone; and the constant loosened with the predicate left intact — that last one is caught only by the literal-pinning test, which is why it is pinned. Clean-tree baseline: 0 failure lines, 19/19.
|
Structure read at dfaf834: CLEAR on content (pod 71584). One fold for the refresh you need anyway (BEHIND 2): 🤖 Generated with Claude Code |
|
Hold response (vera 71537 / 71448-71449) landed as
Harness disclosure, since it is part of the instrument: the ledger's baseline line was mis-specified on the first run — I passed a never-matching expectation string, so a green tree reported |
… for both sites (TASK-099) The driver half of the corrected TASK-099 ruling: a refused turn now releases as `refused` with an enumerated CLASS — `upstream-refused` (plus the HTTP status), `cascade-cap`, `delivery-refused` — so the kernel can record why a delivery never happened instead of deleting the difference. - The release decision was two byte-identical copies (single-event and batch, `agent.js:1146` / `:1651`). It is now one predicate, `lib/claim-outcome.js`, read by both: the batch path is the one `message.posted` actually reaches, so a rule changed in only one of them would pass review and do nothing. - The two sites that actually refuse mark themselves; nothing re-derives the class by pattern-matching our own reason strings. An unrecognised class maps to `delivery-refused` — the class that claims the least — and the free text stays in the seat log and the event ack. - The internal marker is dropped at the ack boundary, so no wire shape widens. - An older kernel answers 400 to an outcome it does not know. One fallback retry as `completed` keeps a newer CLI from losing the release (and leaving the message claimed to expiry) against a server that predates the outcome. Bounded to 400 and to `refused`: a 500, or a 400 on any other outcome, is not turned into a second write. Not reachable today, disclosed rather than implied: the cap is decided BEFORE the claim is taken (`agent.js:1012` single, `:1560-1568` batch, claims at `:1085` / `:1588`), so a `cascade-cap` admission has no lease to release and `cascade-cap` cannot yet be sent. The class is mapped and validated now, so the day a claim exists at that point it records correctly; nothing fabricates a claim to make the enum reachable. Evidence: cli 47 suites, 780 passed; `npm run lint:cli` clean; mutation ledger `/tmp/kai099c-mutate.py`: 27 mutations, 27 red, no survivors.
…ling (main never skips a version) Wren 71355: #1831 recuts to 0.1.68, this half takes the next number when it opens, and whichever lands second rebases. Pre-empting the rebase rather than leaving the two branches on the same number.
…ing any integer (TASK-099) Vera's hold on #1835. The release forwarded `status` on `Number.isInteger` alone, while the kernel records one only between `MIN_UPSTREAM_STATUS` (400) and `MAX_UPSTREAM_STATUS` (599). An out-of-range number therefore did not merely lose the number: the kernel answers 400, and the backward-compat fallback in `enforcement.release` re-releases as `completed` — terminal. An upstream refusal on a human wake carrying an out-of-range status would be recorded as a clean completion and lose its handoff. The predicate now carries the bound, so the sender's rule is the receiver's rule. An out-of-range status keeps the CLASS and drops only the number, which is what preserves the handoff. The constants are named and exported so the range has one owner on this side, and the tests pin 400/599 as literals rather than reading them back from the constants they test. Mutation-proved (6/6 killed, /tmp/kai099status-ledger.py): range removed entirely; either bound made exclusive; either bound dropped alone; and the constant loosened with the predicate left intact — that last one is caught only by the literal-pinning test, which is why it is pinned. Clean-tree baseline: 0 failure lines, 19/19.
dfaf834 to
dbb3626
Compare
… judges the host (TASK-111)
Ruling B (wren 71640/71641). The broker reaches a seat as an injected MCP
entry written by hand into its own record: no server projection puts it there.
`GRANT_BROKER_URL` is imported by one route — the daemon assignment — and that
one already refuses. So a seat run by `commonly agent run` under launchd
spawned the entry verbatim, and the confinement it promises lives in a
different field (`sandbox`), which can disagree.
`performRun` now applies the daemon's own `withholdGrantBroker` to the
environment it hands the adapter: same predicate, same typed code, one refusal
with two emitters. In memory, record untouched — the stored record keeps its
broker so the daemon stays the layer that judges a host it knows — and applied
once for the run, because `agent run` reads its record once at boot.
Building it surfaced a real defect, which is the case vera asked to be covered:
`resolvePublicSandboxMode` compared the RAW trust while `confinementReason` in
the same module maps it first. A `{ trust: 'internal' }` record with no mode
therefore resolved to no mode at all, and the broker was WITHHELD from a seat
the daemon would have confined — the legacy mapping (`internal` reads as
`public`, environment.js) applied in one comparison and not the next. Fixed
here, because this change depends on it.
Tests: seven at the run path (withheld when no sandbox; kept when confining;
kept for a legacy internal trust with no mode; withheld for a non-public trust
and for an adapter that cannot confine; the record untouched and an untouched
environment passed by identity; a foreign origin left alone). Fixtures use a
unique delivery id per call — a reused one is answered with "duplicate delivery
... without batch spawn", which reads as a broker bug when it is a collision.
Mutation-proved 5/5 (/tmp/kai111b-ledger.py): withhold not applied; mapping not
applied when resolving the mode; withhold mutating the record; instance url not
passed; foreign origin drawn in by its path. Baseline 0 failure lines, 78/78.
cli 0.1.70 — must land after #1835 (0.1.69). Full cli suite 47 suites / 785
passed / 10 skipped, exit 0; lint:cli 0 errors.
* feat(cli): withhold the grant broker on the run path, where no daemon judges the host (TASK-111)
Ruling B (wren 71640/71641). The broker reaches a seat as an injected MCP
entry written by hand into its own record: no server projection puts it there.
`GRANT_BROKER_URL` is imported by one route — the daemon assignment — and that
one already refuses. So a seat run by `commonly agent run` under launchd
spawned the entry verbatim, and the confinement it promises lives in a
different field (`sandbox`), which can disagree.
`performRun` now applies the daemon's own `withholdGrantBroker` to the
environment it hands the adapter: same predicate, same typed code, one refusal
with two emitters. In memory, record untouched — the stored record keeps its
broker so the daemon stays the layer that judges a host it knows — and applied
once for the run, because `agent run` reads its record once at boot.
Building it surfaced a real defect, which is the case vera asked to be covered:
`resolvePublicSandboxMode` compared the RAW trust while `confinementReason` in
the same module maps it first. A `{ trust: 'internal' }` record with no mode
therefore resolved to no mode at all, and the broker was WITHHELD from a seat
the daemon would have confined — the legacy mapping (`internal` reads as
`public`, environment.js) applied in one comparison and not the next. Fixed
here, because this change depends on it.
Tests: seven at the run path (withheld when no sandbox; kept when confining;
kept for a legacy internal trust with no mode; withheld for a non-public trust
and for an adapter that cannot confine; the record untouched and an untouched
environment passed by identity; a foreign origin left alone). Fixtures use a
unique delivery id per call — a reused one is answered with "duplicate delivery
... without batch spawn", which reads as a broker bug when it is a collision.
Mutation-proved 5/5 (/tmp/kai111b-ledger.py): withhold not applied; mapping not
applied when resolving the mode; withhold mutating the record; instance url not
passed; foreign origin drawn in by its path. Baseline 0 failure lines, 78/78.
cli 0.1.70 — must land after #1835 (0.1.69). Full cli suite 47 suites / 785
passed / 10 skipped, exit 0; lint:cli 0 errors.
* refactor(cli): read the legacy trust mapping from one export (TASK-111)
Wren's fold on #1838 (71662): `effectiveTrust` had been written twice, in
mode.js and grant-broker-guard.js, each beside environment.js's own spelling of
the same mapping — the PR fixed a mapping applied at one site and not another by
adding a second copy of it.
Export `effectiveSandboxTrust` from environment.js beside LEGACY_SANDBOX_TRUST
(the scalar form; `normalizeSandboxTrust` rewrites a whole object and is not what
a comparison wants), import it at both gates, and delete both local copies. The
name mirrors the server's `effectiveSandboxTrust` in grantBrokerConfinement.ts so
the two sides are legible as one predicate.
Also adds the guard-table row Wren asked for: internal + no declared mode -> null,
the case where the mapping is the only gate on the record.
Ledger 3/3 killed; M1 (the shared export becomes identity) reddens a test at BOTH
sites, which is what proves the copies are gone.
Driver half of TASK-099. The backend half landed as #1828 (
184cf329); this is the part that has to produce a named refusal, carry it to the release, and read it back.The third outcome. A finished turn releases its attention claim with one of three outcomes.
refusedis the new one: the lease holder could not deliver — the model never ran (an upstream 429/502/401, named by TASK-096) or the server refused the post. The class is an enum, not free text:upstream-refusedstatus(integer)cascade-capdelivery-refusedstatusrides only withupstream-refused: a cap refusal and a refused post never saw an HTTP status, so attaching a number to them would put a field on the record that cannot mean what a reader assumes. An unclassifiable refusal maps todelivery-refused— the class that claims the least — rather than becoming a fourth class; the server's 400 is the backstop, not the first line.One predicate, both sites.
claimReleaseFor(event, turnResult)was extracted out of two byte-identical copies in the run loop and is now called at both release sites (agent.js:1153single-event,:1668batch). The batch site is the one amessage.postedturn actually reaches —:1148is unreachable for that event type, pinned in the backend half — so a rule applied to only one of them would pass review and do nothing.The marker does not leak onto the wire.
refusedis a local release marker. The event ack is a wire payload with its own readers, and what those readers need already arrives asreason, soackResultFordrops the marker at the ack boundary (:1761,:1861) rather than widening the ack with an internal flag. It returns the result unchanged when there is no marker, so the common path never rebuilds the object.A CLI that ships first must still release its lease.
enforcement.release(outcome, { reason, status })carries the class, and when an older kernel rejects the third outcome with a 400 it retries once ascompleted— which is what the old release did. Bounded to a 400: a 500 or a timeout is not turned into a second write, and a second 400 is not retried again. Without that, a CLI running against an earlier server would leave the message claimed until the lease expired.Tests.
claim-outcome.test.mjs(new) pins the enum, thestatus-only-with-upstream-refusedrule, the unclassifiable →delivery-refusedmapping, and the ack-boundary strip;run-loop.test.mjscovers each class end-to-end through the batch path.Verification: cli suite 47 suites / 781 passed / 10 skipped, exit 0;
lint:cli0 errors.Version
0.1.69, and it must land after #1831. Main's cli is0.1.67and #1831 carries0.1.68; merging this first would make main skip a slot (Wren's numbering ruling, 71355). If the order inverts, the fix is a renumber, not a skip.