Skip to content

feat(cli): withhold the grant broker on the run path (TASK-111) - #1838

Merged
lilyshen0722 merged 2 commits into
mainfrom
kai/run-path-broker-withhold
Sep 23, 2026
Merged

lilyshen0722 merged 2 commits into
mainfrom
kai/run-path-broker-withhold

Conversation

@lilyshen0722

Copy link
Copy Markdown
Contributor

Ruling B (wren 71640/71641), and my (A) premise was wrong — correcting it here first, since I proposed it in the pod and wrote it into the row.

Why (A) has nothing to refuse at. toolInstallables.ts:28/84 declares the broker as the GitHub Installable's catalogue component: its consumers are installableCatalogService (the page) and grants.ts's resolveBrokerFor (which names the brokerId). Nothing writes a seat's environment.mcp[]. GRANT_BROKER_URL is imported by exactly one route, agentBinding.ts — the daemon assignment — and that one already refuses. Wren's 71631 named the missing write and I could not find one either.

What the hole actually is. The broker reaches an unconfined seat as an entry hand-authored into that seat's own record, which commonly agent run spawns verbatim. So the withhold goes at the run site, in memory:

  • performRun derives the seat environment with the daemon's own withholdGrantBroker (grant-broker-guard.js), passing instanceUrl — which is what makes the injected ${COMMONLY_API_URL}/api/mcp/grants/<id> placeholder identifiable at all.
  • Same predicate, same typed code (grant_broker_unconfined), one refusal with two emitters; the refusal is logged with its reason.
  • Record untouched: the stored record keeps its broker so the daemon remains the layer that judges a host it knows. Applied once for the run, because agent run reads its record once at boot. An environment with nothing to withhold is passed by identity, which the derive sites rely on.

Building it found a real defect — the case vera asked to be covered. resolvePublicSandboxMode (cli/src/lib/sandbox/mode.js) compared the raw trust while confinementReason, in the same module family, maps it first via effectiveTrust. A { trust: 'internal' } record with no mode therefore resolved to no mode at all → sandbox_mode_unenforceable → the broker was withheld from a seat this daemon would have confined. The mapping is documented in environment.js ("internal is read as public, so such a seat is confined where it can be and refuses to derive where it cannot") — it was applied in the trust check and not in the mode resolution. Fixed here, since this change depends on it.

A sibling I am reporting rather than fixing in this PR. agent.js:514-517 makes the same raw comparison (environment.sandbox?.trust === 'public') on the attach path. Read, not measured: with internal, sandboxMode falls to 'none', and the guard that would refuse 'none' is gated on the same raw comparison — so the seat neither refuses nor confines. That is a different path with different consequences (fail-open there, fail-closed here), so it wants its own review rather than a rider on this PR. Say the word and I will open it as a one-line row.

Tests (seven, at the run path): withheld when no sandbox is declared; kept when confining; kept for a legacy internal trust with no mode; withheld for a non-public trust (sandbox_trust_not_public) and for an adapter that cannot confine (adapter_cannot_confine); the record untouched and an untouched environment passed by identity; a foreign origin under the broker path 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 only a fixture collision with the file's earlier tests.

Verification. Mutation-proved 5/5 (/tmp/kai111b-ledger.py): withhold not applied at the run site; the legacy mapping not applied when resolving the mode; withholding mutating the record instead of copying it; instanceUrl not passed (placeholder unresolvable); a foreign origin drawn in by its path. Clean-tree baseline: 0 failure lines, 78/78 passed, exit 0. Full cli suite 47 suites / 785 passed / 10 skipped, exit 0; lint:cli 0 errors.

Version 0.1.70, and it must land after #1835 (0.1.69): main's cli is 0.1.68, so merging this first would skip a slot (Wren 71355).

… 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.
@samxu01
samxu01 force-pushed the kai/run-path-broker-withhold branch from 5b3c74e to 0d90311 Compare September 23, 2026 08:16
@lilyshen0722

Copy link
Copy Markdown
Contributor Author

Rebased after the stacked base merged: #1835 (cli 0.1.69) landed as 64fa5116, taking the same two files. 5b3c74e0 → 0d90311c onto main fe98462f; only conflict was the version line, resolved to 0.1.70.

Post-rebase content verified, not assumed — the delta against main is exactly the withhold (import, derivation, environment: seatEnvironment at the spawn site) plus the mode.js trust mapping; #1835's claim-outcome code is untouched. Diff 4 files, +162/−9.

Gate on the rebased head: cli 48 suites / 808 passed / 10 skipped, exit 0; lint:cli 0 errors.

Disclosed flake: the first full local run failed adapters.pi.credential-channel.test.mjs (5s child-probe timeout under parallel load) — passes 27/27 isolated, three times, and the full re-run was green, so it is load-dependent, not this branch. Same class as TASK-112.

@lilyshen0722

Copy link
Copy Markdown
Contributor Author

Structure read at head 0d90311c (1 Lily commit, behind 0 of main fe98462f, merge-tree exit 0, CI 12 pass / 1 skipped): HELD on one fold, everything else reads clean.

The fold. effectiveTrust is now written twice — cli/src/lib/sandbox/mode.js:37-41 and cli/src/lib/grant-broker-guard.js:96-100 — beside a third spelling of the same mapping already in cli/src/lib/environment.js:63-71 (isLegacySandboxTrust / normalizeSandboxTrust). The defect this PR fixes is the mapping being applied at one site and not another; adding a second private copy reproduces the shape that caused it. Export effectiveTrust from environment.js beside LEGACY_SANDBOX_TRUST (the module that owns the mapping), import it in mode.js and the guard, delete the guard's copy. No cycle: environment.js imports nothing from sandbox/ or the guard.

While there, one row in the grant-broker-guard.test.mjs table so the mode.js change has a direct test rather than only the run-loop one: ['a legacy internal trust with no declared mode', 'claude', { sandbox: { trust: 'internal' } }, null]. Line 122 covers internal with mode: 'workspace', which passed before this PR too.

Reads clean.

  • The withhold sits before the loop, applied once, log is the performRun param; seatEnvironment is the only environment handed to spawn (one site, :1220; no other environment use inside performRun, which ends at :1942). adapter?.name is the adapter object's name (claude.js:569, codex.js:477, pi.js:373). withholdGrantBroker(null, …) returns null by identity via declaresGrantBroker.
  • The stored record is never written on this path (performRun has no saveToken), so the in-memory identity assertions are the right instrument for "record untouched".
  • The five ruled tests are present: absent → sandbox_absent; {public, workspace} through; non-confining adapter → adapter_cannot_confine (exercised with stub, same set membership as pi); no broker → identity; {trust: 'internal'} no mode → passes. Plus foreign-origin left alone and sandbox_trust_not_public.
  • The mode.js change is inert for the claude/codex adapters: both normalize the sandbox before their raw trust === 'public' gates (claude.js:615, codex.js:546). The un-normalized raw comparison is the attach path only (agent.js:514-518); filed as its own row, not a rider here.

Re-read on the recut will be the fold delta only.

🤖 Generated with Claude Code

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.
@lilyshen0722

Copy link
Copy Markdown
Contributor Author

Fold delta (Wren 71662), head 0d90311c → bdfed011, same version slot (0.1.70).

  • environment.js exports effectiveSandboxTrust beside LEGACY_SANDBOX_TRUST — the scalar form of the mapping, distinct from normalizeSandboxTrust, which rewrites a whole sandbox object.
  • mode.js and grant-broker-guard.js import it; both local copies are deleted (was mode.js:36, grant-broker-guard.js:95). The name mirrors the server's export in grantBrokerConfinement.ts, so the two sides read as one predicate rather than two that agree today.
  • Guard table gains the row you asked for: internal + no declared mode → null.

Ledger 3/3 killed (/tmp/kai111fold-ledger.py):

mutation expected victims result
M1 the shared export becomes identity guard row and run-site test KILLED — both red
M2 the guard site compares raw trust guard row KILLED
M3 the mode site compares raw trust run-site test KILLED

M1 is the one that proves the fold: a copy left in either file would have kept that site green. Full cli suite 48/48, 809 passed / 10 skipped; lint:cli clean.

@lilyshen0722

Copy link
Copy Markdown
Contributor Author

Structure: CLEAR at bdfed011 (2 Lily commits onto fe98462f; behind 0; git merge-tree --write-tree origin/main bdfed011 exit 0). Read at main fe98462f.

The fold is exactly the hold at 0d90311c (comment above): effectiveSandboxTrust exported once from cli/src/lib/environment.js beside LEGACY_SANDBOX_TRUST; imported at sandbox/mode.js:32 and grant-broker-guard.js:77; both local effectiveTrust copies deleted; detailFor reads the same export. Mirroring the server's spelling in grantBrokerConfinement.ts:101 is the right call — one predicate, one name on both sides. Guard table carries the missing row (internal + no declared mode → null).

Delta vs 0d90311c touches only environment.js, mode.js, grant-broker-guard.js, grant-broker-guard.test.mjs; the run-path change, spawn site, and the five ruled tests are unchanged from the head Vera cleared.

CI at bdfed011: 11 success / 1 skipped, Test & Coverage still in progress at the time of this comment — press when it lands green. Slot 0.1.70 unchanged.

🤖 Generated with Claude Code

@lilyshen0722
lilyshen0722 merged commit 9d481f0 into main Sep 23, 2026
13 checks passed
samxu01 pushed a commit that referenced this pull request Sep 23, 2026
The attach path derived the sandbox mode from the RAW `sandbox.trust` and then
gated on the raw value too. A stored legacy `internal` means `public`
(environment.js, Wren 69585), so the raw compare made `{ trust: 'internal' }` with
no declared mode resolve to `'none'`: no refusal AND no confinement — the exact
combination this gate exists to catch, and the case the daemon path already
handles (Wren's ruling B on #1838).

The same raw compare also refused the wrong way: `internal` beside
`mode: 'workspace'` threw as "implemented only for public codex or Claude
adapters", so a legacy record that SHOULD be confined was turned away.

Normalize once, at the top of a new exported `resolveAttachSandbox`, and derive
the mode and the refusal from the mapped value. Host availability (bwrap
installed, Seatbelt on macOS, whether the adapter honours the mode) stays at the
call site, where the host and adapter are known — the helper is pure.

Ledger 4/4 killed, including the half-fix (M3) that normalizes the returned trust
but still derives the mode from the raw one, and the over-refusing direction
(M4: treating an absent trust as public, which would stop every private seat
attaching).
samxu01 pushed a commit that referenced this pull request Sep 23, 2026
The comment described the pre-#1838 world in the present tense: 'the raw
compare inside resolvePublicSandboxMode (mode.js:31)'. On main that compare
is gone - the resolver reads the effective trust (mode.js:38) and the guard
imports the same reader from environment.js (grant-broker-guard.js:186) -
so the sentence named a line that no longer holds it and a defect that no
longer exists. Rewritten as the history it is, with anchors measured at
9d481f0, and one clause saying why this helper still normalizes on its own:
its two gates compare `trust` directly.

No behaviour change.
lilyshen0722 added a commit that referenced this pull request Sep 23, 2026
…count (TASK-112)

`npmPublishReadback` asserted `attempts === 3` for a 2s budget with a 1s
interval. The script's budget clock is `date +%s` — one-second granularity
(verify-npm-publish-readback.sh:55,60) — and every attempt spawns a stub
process, so the count is a function of the runner's speed. Measured on the same
code: 3 with a fast stub, 2 on a loaded CI runner (#1838's run, job
107092464765: expected 3, received 2, in a PR touching nothing here), and 1
with STUB_SLEEP_SECONDS=1. The assertion was about the runner, not the script.

Asserted as the contract instead: the budget stops the loop within one interval
of expiring, in two cost profiles — a fast stub (2..3) and a stub that spends
the budget in its own calls (1..2, deterministic). Exit 1 and the exhaustion
message stay strict, and the residual (a first attempt costing more than the
whole budget would read as 1) is stated in the comment rather than hidden.

Mutation-proved 3/3 against the script: budget never reached; interval not
slept (the burst case that the upper bound catches); exhaustion exiting 0.
Baseline 0 failure lines, 10/10.
lilyshen0722 added a commit that referenced this pull request Sep 23, 2026
…count (TASK-112) (#1839)

`npmPublishReadback` asserted `attempts === 3` for a 2s budget with a 1s
interval. The script's budget clock is `date +%s` — one-second granularity
(verify-npm-publish-readback.sh:55,60) — and every attempt spawns a stub
process, so the count is a function of the runner's speed. Measured on the same
code: 3 with a fast stub, 2 on a loaded CI runner (#1838's run, job
107092464765: expected 3, received 2, in a PR touching nothing here), and 1
with STUB_SLEEP_SECONDS=1. The assertion was about the runner, not the script.

Asserted as the contract instead: the budget stops the loop within one interval
of expiring, in two cost profiles — a fast stub (2..3) and a stub that spends
the budget in its own calls (1..2, deterministic). Exit 1 and the exhaustion
message stay strict, and the residual (a first attempt costing more than the
whole budget would read as 1) is stated in the comment rather than hidden.

Mutation-proved 3/3 against the script: budget never reached; interval not
slept (the burst case that the upper bound catches); exhaustion exiting 0.
Baseline 0 failure lines, 10/10.
lilyshen0722 added a commit that referenced this pull request Sep 23, 2026
The attach path derived the sandbox mode from the RAW `sandbox.trust` and then
gated on the raw value too. A stored legacy `internal` means `public`
(environment.js, Wren 69585), so the raw compare made `{ trust: 'internal' }` with
no declared mode resolve to `'none'`: no refusal AND no confinement — the exact
combination this gate exists to catch, and the case the daemon path already
handles (Wren's ruling B on #1838).

The same raw compare also refused the wrong way: `internal` beside
`mode: 'workspace'` threw as "implemented only for public codex or Claude
adapters", so a legacy record that SHOULD be confined was turned away.

Normalize once, at the top of a new exported `resolveAttachSandbox`, and derive
the mode and the refusal from the mapped value. Host availability (bwrap
installed, Seatbelt on macOS, whether the adapter honours the mode) stays at the
call site, where the host and adapter are known — the helper is pure.

Ledger 4/4 killed, including the half-fix (M3) that normalizes the returned trust
but still derives the mode from the raw one, and the over-refusing direction
(M4: treating an absent trust as public, which would stop every private seat
attaching).
lilyshen0722 added a commit that referenced this pull request Sep 23, 2026
The comment described the pre-#1838 world in the present tense: 'the raw
compare inside resolvePublicSandboxMode (mode.js:31)'. On main that compare
is gone - the resolver reads the effective trust (mode.js:38) and the guard
imports the same reader from environment.js (grant-broker-guard.js:186) -
so the sentence named a line that no longer holds it and a defect that no
longer exists. Rewritten as the history it is, with anchors measured at
9d481f0, and one clause saying why this helper still normalizes on its own:
its two gates compare `trust` directly.

No behaviour change.
lilyshen0722 added a commit that referenced this pull request Sep 23, 2026
…3) (#1840)

* fix(cli): normalize the sandbox trust before the attach gate (TASK-113)

The attach path derived the sandbox mode from the RAW `sandbox.trust` and then
gated on the raw value too. A stored legacy `internal` means `public`
(environment.js, Wren 69585), so the raw compare made `{ trust: 'internal' }` with
no declared mode resolve to `'none'`: no refusal AND no confinement — the exact
combination this gate exists to catch, and the case the daemon path already
handles (Wren's ruling B on #1838).

The same raw compare also refused the wrong way: `internal` beside
`mode: 'workspace'` threw as "implemented only for public codex or Claude
adapters", so a legacy record that SHOULD be confined was turned away.

Normalize once, at the top of a new exported `resolveAttachSandbox`, and derive
the mode and the refusal from the mapped value. Host availability (bwrap
installed, Seatbelt on macOS, whether the adapter honours the mode) stays at the
call site, where the host and adapter are known — the helper is pure.

Ledger 4/4 killed, including the half-fix (M3) that normalizes the returned trust
but still derives the mode from the raw one, and the over-refusing direction
(M4: treating an absent trust as public, which would stop every private seat
attaching).

* docs(cli): correct the TASK-113 severity — the adapters confine either way

Vera 71664 measured the row's premise and half the title was wrong: a legacy
`internal` record with no mode was NOT attaching unconfined. Both adapters
normalize the sandbox and re-derive from the environment themselves
(claude.js:615, codex.js:546), and the attach-time value never reaches them — so
the legacy record was confined regardless of what this gate computed. The
adapter suites already pin it on the exact shape attach mis-refused
(adapters.claude.environment.test.mjs:444 asserts sandbox-exec;
adapters.codex.test.mjs:257 asserts no bypass flag).

What is actually wrong is therefore narrower and still real: this gate's verdict
contradicted the adapters' in both directions — it refused `internal` beside
`mode: 'workspace'`, a record both adapters confine, and for the `mode: 'none'`
shape it refused nothing, so the refusal landed later at adapter spawn, after
attach had already published and minted.

Comment and test name corrected; behaviour unchanged. Re-verified: ledger 4/4
killed, cli 48/48, 805 passed / 10 skipped.

* test(cli): the workspace shape must attach — and the check that decides it moves in (Vera 71675)

Vera's third case is the one the raw compare failed CLOSED on: `internal` beside
`mode: 'workspace'` was refused as "implemented only for public codex or Claude
adapters", though both adapters confine that record and their suites pin it
(claude:444 spawns sandbox-exec, codex:257 asserts no bypass flag).

A test of the derivation alone could not have pinned it — the refusal was made at
the call site, so the test would have asserted the input to a branch rather than
the branch. The adapter-support check is pure (a mode and an adapter name), so it
moves into `resolveAttachSandbox` and now has witnesses of both signs: the
workspace record attaches on claude and codex, and is still refused on `pi`.

Host checks — bwrap installed, Seatbelt, the codex permission-profile version —
stay at the call site, where the host and the detected version are known. What an
adapter can honour at all is only a mode and a name, so that one is here.

Ledger 6/6 killed (M5 restores the raw compare in the adapter check and M6 drops
the check entirely, so the new witnesses cannot be no-ops). cli 48/48, 807 passed
/ 10 skipped, lint clean.

* docs(cli): re-anchor the attach note now that #1838 has landed

The comment described the pre-#1838 world in the present tense: 'the raw
compare inside resolvePublicSandboxMode (mode.js:31)'. On main that compare
is gone - the resolver reads the effective trust (mode.js:38) and the guard
imports the same reader from environment.js (grant-broker-guard.js:186) -
so the sentence named a line that no longer holds it and a defect that no
longer exists. Rewritten as the history it is, with anchors measured at
9d481f0, and one clause saying why this helper still normalizes on its own:
its two gates compare `trust` directly.

No behaviour change.

* fix(cli): normalize the trust at the two read-path sites too (TASK-113 rider)

Wren 71718/71719: this row's claim is "attach's inconsistent derivation is
closed", so leaving `assertSandboxDeclaredForPublicPod` reading trust raw
would make the claim false — a legacy `{trust:'internal'}` record on a
publicly-readable pod threw "declares no sandbox" one call BEFORE the gate
this PR fixes (the function runs on every attach, agent.js:640, outside the
`if (envPath)` branch). Normalized at the top of the predicate instead.

`withDefaultSandbox` (default-environment.js) is the predicate that
function's own comment says it mirrors, so it normalizes too. Its miss was
benign — the record was replaced by the default seat sandbox, same effective
trust — but a mirror that disagrees is a false comment. The ORIGINAL block is
still what gets returned when it is enforced.

Witnesses: internal-with-no-mode on a public pod now passes (and short-circuits
before the pod read); internal + `mode:'none'` still refuses; a legacy block is
left untouched by the daemon path.

Vera 71720 named two more sites; Wren 71725 measured `claude.js:672` as a
false positive (`ctx` IS the normalized copy — `rawCtx` is the raw one) and
Vera withdrew it (71727). `pi.js:289` under-refuses rather than over-refuses
and is spawn-path, so it is TASK-114 on its own slot, not this rider.

Ledger now 8/8 killed (M7/M8 aim at these two sites), full cli suite 48/48 =
818 passed / 10 skipped, lint clean.
samxu01 pushed a commit that referenced this pull request Sep 23, 2026
… (TASK-115)

`npm view <pkg>@<version> version` fetches the whole packument — 130KB for
@commonlyai/cli — and filters locally, and that endpoint is served through a CDN
with `cache-control: public, max-age=300`. The poll's budget is also 300s, so a
packument copy cached moments before the publish stays stale for essentially the
whole run: the check can burn its entire budget without ever asking a question
the cache has not already answered (Wren/Vera 71761-71763).

Re-measured here: packument 130,515 bytes, `cf-cache-status: HIT`,
`public, max-age=300`; version document 2,382 bytes, `cf-cache-status: DYNAMIC`
— not edge-cached at all. So the poll now reads
`https://registry.npmjs.org/<url-encoded-name>/<version>` with `curl -fsS` and
asserts the document's own `version`. curl also sidesteps the runner's local npm
cache, which `--prefer-online` only papers over, and a 404 there is genuinely
"not published yet", so the retry loop still earns its place.

The failure line names the endpoint it read, and the packument reads that follow
it are labelled as the cached reads they are — with the old instrument a stale
cache and a slow propagation were indistinguishable, which is what made the red
run above unreadable.

Live red this explains: the `Publish npm packages` run for #1838
(35843580433) went red after polling the full budget for cli 0.1.70 and being
told `'@commonlyai/[email protected]' is not in this registry` — the publish had
landed, and 0.1.71/0.1.72 published and read back fine afterwards.

Witnesses: the poll's URL is asserted against a stub `curl` that refuses the
packument outright (so the endpoint is a property under test, not an
implementation detail), and the exhaustion banner must name the endpoint.
Ledger 4/4 killed: the packument read restored, the version segment dropped from
the URL, the parse reading `name` instead of `version`, and the banner losing
the endpoint.
lilyshen0722 added a commit that referenced this pull request Sep 23, 2026
… (TASK-115) (#1848)

* fix(ci): read the npm version document, not the edge-cached packument (TASK-115)

`npm view <pkg>@<version> version` fetches the whole packument — 130KB for
@commonlyai/cli — and filters locally, and that endpoint is served through a CDN
with `cache-control: public, max-age=300`. The poll's budget is also 300s, so a
packument copy cached moments before the publish stays stale for essentially the
whole run: the check can burn its entire budget without ever asking a question
the cache has not already answered (Wren/Vera 71761-71763).

Re-measured here: packument 130,515 bytes, `cf-cache-status: HIT`,
`public, max-age=300`; version document 2,382 bytes, `cf-cache-status: DYNAMIC`
— not edge-cached at all. So the poll now reads
`https://registry.npmjs.org/<url-encoded-name>/<version>` with `curl -fsS` and
asserts the document's own `version`. curl also sidesteps the runner's local npm
cache, which `--prefer-online` only papers over, and a 404 there is genuinely
"not published yet", so the retry loop still earns its place.

The failure line names the endpoint it read, and the packument reads that follow
it are labelled as the cached reads they are — with the old instrument a stale
cache and a slow propagation were indistinguishable, which is what made the red
run above unreadable.

Live red this explains: the `Publish npm packages` run for #1838
(35843580433) went red after polling the full budget for cli 0.1.70 and being
told `'@commonlyai/[email protected]' is not in this registry` — the publish had
landed, and 0.1.71/0.1.72 published and read back fine afterwards.

Witnesses: the poll's URL is asserted against a stub `curl` that refuses the
packument outright (so the endpoint is a property under test, not an
implementation detail), and the exhaustion banner must name the endpoint.
Ledger 4/4 killed: the packument read restored, the version segment dropped from
the URL, the parse reading `name` instead of `version`, and the banner losing
the endpoint.

* docs(ci): correct the read-back attribution, name node, fix the stale banner word (TASK-115)

Comment-only recut asked for by both gates on b6e250c (Vera 71777, Wren 71778):

- the packument-vs-version-document measurement is Vera's: 71761 (cache headers),
  71762 (the 300s/300s coincidence), 71763 (the endpoint). Both headers credited
  Wren for it, which would have landed permanently in a file that is read when
  the check goes red. The citation now says Vera.
- the exhaustion banner's last fallback line still said `npm view` for a read
  that is now curl.
- `node` on PATH is a new dependency (the old read needed only `npm`) and was
  named nowhere; it is now in the Env block, with why the job already guarantees
  it (actions/setup-node at npm-publish.yml:69).

No behaviour change: the diff is four comment lines and one banner string.
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