Repository navigation
feat(backends): prove a discovering pi worker extension-free from what its loader loaded (#2874) - #4056
Merged
Conversation
…t its loader loaded (#2874) A managed pi worker now counts the extensions, extension load errors and runner paths its session loaded (loadedPiExtensions) and sends the count in its ready frame, before the prompt. The host's execution proof accepts zero as extension-free and any other count as unproven, whatever the configuration said; no report keeps the configuration's answer. The set cannot change mid-turn: pi changes it only in AgentSession.reload(), which a managed worker reaches only through a loaded extension's ctx.reload(). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 15, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #2874
What changed
A managed pi worker now counts what its own session loaded: every extension, every extension load error and every path its extension runner holds (
export function loadedPiExtensions,packages/ui-backend-pi/src/native-session-runtime.ts:136-139). It sends that count asloadedExtensionsin itsreadyframe, before the prompt and before any model-directed code runs. The host's execution proof (function createExecutionProof,packages/ui-backend-pi/src/worker-session.ts:253-259) accepts a count of zero as extension-free, so a worker with discovery on that loaded nothing now proves the same curated reads, writes and host bridge calls as a curated worker. Any other count makes the worker unproven, whatever the configuration said. A worker that sends no count keeps the configuration's answer, which is unproven when discovery is on. The existing refusal (unqualifiedResources) now reads the same count. Thereadyfield is optional in the strict worker schema, so a missing report is no evidence rather than a protocol error.The decision record (
docs/decisions/governed-writable-workers.md, the evidence section) names the mechanism that fixes the set for the worker's lifetime. In installed pi 0.99.2 the loaded set changes only inAgentSession.reload(). Its only callers are interactive/reloadand an extension command'sctx.reload(), which pi's modes bind throughbindExtensions. A managed worker runs no pi mode and binds nothing, and a/prompt reaches only commands that loaded extensions registered. A turn that writes.pi/extensions/, a settings file or a package changes only what a later worker loads.Why this shape
#3673 (#3658) changed the issue's premise. Pi now defaults to curated tools, so a default worker was already extension-free, and the managed worker already refuses any loaded extension. The issue body now carries a dated correction. The remaining gap was a worker with discovery on that loaded none: before this change, the configuration alone decided, and that worker proved nothing. I chose a worker-side report over host-side inspection (
inspectPiExtensions) because only the worker's loader sees the worker's effective agent directory and settings snapshot. The report is computed by the same function as the refusal, and the refusal is already the boundary the worker's input safety relies on. An extension that could forge the count could defeat that refusal too, so the report adds no weaker trust. No public seam, contract or provider-facing history changes. The field sits on the internal worker protocol.Proof
Failing first, with only the schema field added (so the new frame parses) and the proof logic unchanged:
tool-execution-evidence.test.ts:PI_REPORTED_EXTENSION_FREE_MATCHES_CURATEDfailed (Expected −6 / Received +6: every discovering-worker call wasnull).PI_CONTRADICTED_CURATED_PROVES_NOTHINGfailed (a curated worker reporting one loaded extension still provedworker_read). An earlier run without the schema field failed only at protocol parse, so I did not count it as a receipt.worker-snapshot.test.tsagainst the baseworker-entry.ts:PI_READY_REPORTS_RUNTIME_LOADED_EXTENSIONSfailed withExpected: 3, Received: undefinedin both modes.After the change, the focused files pass 24/24:
tool-execution-evidence,extension-inspection,worker-snapshotandworker-session-units.Acceptance criteria:
loadExtensions: falseworker proves. The new test runs every existing ui-server: a full native journal observation runs after every tool result and delays the next request (230–860 ms per call) #2834 evidence case under both configurations and compares the results (PI_REPORTED_EXTENSION_FREE_MATCHES_CURATED)..pi/extensions/loom.tsas 1 and an installed user extensionagent/extensions/aeolus.tsas 1 (PI_REPO_LOCAL_EXTENSION_COUNTED,PI_INSTALLED_EXTENSION_COUNTED). A realcreateSessionRuntime().newSessionwith one refuses withPiInputSafetyUnavailableError(PI_LOADED_EXTENSION_REFUSED). A worker reporting 1 proves no call (PI_LOADED_EXTENSION_PROVES_NOTHING).ctx.reload(), proves nothing (same test). The decision record names the mechanism. A discovering worker with no report also proves nothing (PI_UNREPORTED_DISCOVERY_PROVES_NOTHING).Mutations, each restored afterwards (
git diffwas clean against the committed tree):loadedNone = true):PI_LOADED_EXTENSION_PROVES_NOTHINGfails.PI_REPORTED_EXTENSION_FREE_MATCHES_CURATEDandPI_CONTRADICTED_CURATED_PROVES_NOTHINGfail.loadedPiExtensionsdrops loaded extensions from its count:PI_REPO_LOCAL_EXTENSION_COUNTEDfails with Expected 1, Received 0, andPI_LOADED_EXTENSION_REFUSEDfails.0: survives. This is an equivalent mutant: a session that loaded anything is refused before it returns, so every returned session's count is 0. The computed count keeps the report tied to the loader if that refusal ever changes.Wider suites, compared with an
origin/mainworktree in this sandbox, which has many environment-only failures:bun run test packages/ui-backend-pi: 581 pass, 25 fail. The same 25 fail on base (host relay, native auth, provider history and other runtime files that need namespaces).bun run test packages/ui-server packages/ui-backend-claude: 6385 pass, 384 fail across 84 files. On base the same 84 files give 380 failures, all of them also in my run. The 4 extra failures (2 inhttp-mount-timers, 1 inhttp-supported-mounts, 1 inws-session-recovery) are timing cases with no pi worker code on their path. Rerun alone on this branch, they pass.bun run buildpasses, and so doesbun run typecheck(with a larger Node heap: the default heap ran out of memory).bun scripts/prove-native-host.ts --observation-timingneeds the pinned native Docker image and a host that allows namespaces. This host refusesunshare -Ur, so it was not run locally. Under the hybrid ruling native runtime proof runs on the squash's main run. A curated worker's behaviour is unchanged on that path: it was already extension-free, and any session that opens reports 0.{"version":1,"kind":"brain-check-pr-receipt","head":"88949f6079b7e1970bf3cbd4404ec0a34b385715","base":"origin/main","mode":"focused","startedAt":"2026-11-16T08:35:45.380Z","finishedAt":"2026-11-16T08:36:54.316Z","checks":[{"name":"all lint and leakage gates","categories":["changeset"],"outcome":"passed","elapsedMs":12781.283043000001},{"name":"environment documentation","categories":["changeset"],"outcome":"passed","elapsedMs":125.36289100000067},{"name":"pending changeset package names","categories":["changeset"],"outcome":"passed","elapsedMs":110.04953000000023},{"name":"contribution changeset","categories":["changeset"],"outcome":"passed","elapsedMs":21.623767999997654},{"name":"affected fast invariants","categories":["verify","unit"],"outcome":"passed","elapsedMs":55880.437473000005}]}Checklist
docs/reflect the change, or nothing documented moved.docs/decisions/provider-history.md): the provider-history guard passes, or nothing on a turn's path changed. (Nothing provider-facing changed.)Collisions
bun scripts/collisions.ts --json --pr 4056at head972a16f037e7aff683108dd120520be300f83895: nopathorunknowncollisions. There areclosure-only overlaps with open PRs #3056, #3059, #3069, #3437, #3581, #3622, #3806, #4002, #4018, #4024, #4028, #4034, #4035, #4036, #4037, #4038, #4040, #4041, #4042, #4046, #4050, #4052 and #4053. #4037 re-anchorsscripts/pi-schema-worker-preload.tsoninstallPiToolSafety(session.agent,options.toolSafety,(twice innative-session-runtime.ts). This PR leaves both of those lines byte-identical, and leaves the other preload anchors inworker-entry.ts,worker-session.tsandworker-reader.tsuntouched.Anything left open
Nothing.
🤖 Generated with Claude Code