Skip to content

feat(backends): prove a discovering pi worker extension-free from what its loader loaded (#2874) - #4056

Merged
schlessera merged 4 commits into
mainfrom
feat/2874-pi-loaded-extension-proof
Nov 16, 2026
Merged

schlessera merged 4 commits into
mainfrom
feat/2874-pi-loaded-extension-proof

Conversation

@schlessera

@schlessera schlessera commented Nov 15, 2026 •

Copy link
Copy Markdown
Owner

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 as loadedExtensions in its ready frame, 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. The ready field 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 in AgentSession.reload(). Its only callers are interactive /reload and an extension command's ctx.reload(), which pi's modes bind through bindExtensions. 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_CURATED failed (Expected −6 / Received +6: every discovering-worker call was null). PI_CONTRADICTED_CURATED_PROVES_NOTHING failed (a curated worker reporting one loaded extension still proved worker_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.ts against the base worker-entry.ts: PI_READY_REPORTS_RUNTIME_LOADED_EXTENSIONS failed with Expected: 3, Received: undefined in both modes.

After the change, the focused files pass 24/24: tool-execution-evidence, extension-inspection, worker-snapshot and worker-session-units.

Acceptance criteria:

  1. A discovering worker that reports none proves exactly what a loadExtensions: false worker 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).
  2. One installed or repo-local extension proves nothing. Pi's real loader counts a repo-local .pi/extensions/loom.ts as 1 and an installed user extension agent/extensions/aeolus.ts as 1 (PI_REPO_LOCAL_EXTENSION_COUNTED, PI_INSTALLED_EXTENSION_COUNTED). A real createSessionRuntime().newSession with one refuses with PiInputSafetyUnavailableError (PI_LOADED_EXTENSION_REFUSED). A worker reporting 1 proves no call (PI_LOADED_EXTENSION_PROVES_NOTHING).
  3. A worker whose set can change, meaning one with an extension loaded that can reach 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 diff was clean against the committed tree):

  • M1, host trusts any report (loadedNone = true): PI_LOADED_EXTENSION_PROVES_NOTHING fails.
  • M2, host ignores the report: PI_REPORTED_EXTENSION_FREE_MATCHES_CURATED and PI_CONTRADICTED_CURATED_PROVES_NOTHING fail.
  • M3, loadedPiExtensions drops loaded extensions from its count: PI_REPO_LOCAL_EXTENSION_COUNTED fails with Expected 1, Received 0, and PI_LOADED_EXTENSION_REFUSED fails.
  • M4, the session result reports a constant 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/main worktree 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 in http-mount-timers, 1 in http-supported-mounts, 1 in ws-session-recovery) are timing cases with no pi worker code on their path. Rerun alone on this branch, they pass.
  • bun run build passes, and so does bun run typecheck (with a larger Node heap: the default heap ran out of memory).
  • bun scripts/prove-native-host.ts --observation-timing needs the pinned native Docker image and a host that allows namespaces. This host refuses unshare -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.
bun run check:pr --base origin/main
{"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

  • Focused local preflight/behavioral receipts and complete selected hosted proof passed; actual head/base/job checkout evidence is in Proof. (Local receipts above; hosted proof is pending.)
  • Acceptance criteria from the issue are all met, or the gap is named below.
  • The PR and completed/advanced issues have verified release milestones under docs/process/github.md.
  • A changeset is included, or this changes nothing a consumer can see.
  • No personal data anywhere in the diff — the leakage gate covers the whole tree.
  • The integration contract index or relevant component is updated in this same commit, or nothing in the machine surface moved. (Internal worker protocol only.)
  • Docs under docs/ reflect the change, or nothing documented moved.
  • A fail-closed guard added or changed answers the proportionate-containment checklist in this body, or no guard changed. (The refusal is unchanged; it now reads the shared count.)
  • Provider history stays append-only (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 4056 at head 972a16f037e7aff683108dd120520be300f83895: no path or unknown collisions. There are closure-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-anchors scripts/pi-schema-worker-preload.ts on installPiToolSafety(session.agent,options.toolSafety, (twice in native-session-runtime.ts). This PR leaves both of those lines byte-identical, and leaves the other preload anchors in worker-entry.ts, worker-session.ts and worker-reader.ts untouched.

Anything left open

Nothing.

🤖 Generated with Claude Code

schlessera and others added 3 commits November 15, 2026 20:24
…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>
@schlessera
schlessera marked this pull request as ready for review November 16, 2026 08:39
@schlessera
schlessera merged commit ef37644 into main Nov 16, 2026
51 of 54 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: backends AgentBackend implementations and the seam they share. type: feat A new capability or a change in user-visible behaviour.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

backends: prove an extension-free pi worker from what it actually loaded, so default pi turns can skip proven-read observations

1 participant