Skip to content

feat(runtime)!: select exact vetted Pi extension tools - #9265

Open
eshulman2 wants to merge 4 commits into
fullsend-ai:mainfrom
eshulman2:docs/adr-0166-pi-tools
Open

eshulman2 wants to merge 4 commits into
fullsend-ai:mainfrom
eshulman2:docs/adr-0166-pi-tools

Conversation

@eshulman2

@eshulman2 eshulman2 commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Summary

An agent can load a vetted Pi extension but lose its native tool names during translation. This implements exact native selection so tools: [inspect_record] exposes that tool while excluding sibling tools and built-in shell/edit tools. Missing, hidden, ambiguous or non-vetted native selections fail before inference. Explicit empty selections exclude extension tools too.

This replaces the ADR-only proposal with runtime code, tests and migration documentation. Adapted from the existing fork implementation, limited to Pi tool selection; journal and tracker changes are excluded. The original ADR additions and their links are removed from the final PR diff.

Closes #9254.

Implementation

  • Preserve built-in translations and fix(runtime): preserve MCP tools and permissions in pi agents #9179's MCP selectors, asynchronous registration and callable/active distinction.
  • Resolve exact native names against vetted extension source paths with a runner-owned selector. Restore the effective active set at session, agent and turn boundaries, and block calls outside the declared selection.
  • Apply the same selector to children using the dispatcher's concrete parent/persona permission intersection and verified extension code.
  • Check selector integrity before and after environment loading and before child dispatch; selector failures stop inference rather than trigger model fallback. Existing extension-tree and manifest checks remain in place.
  • Keep repository extension discovery disabled. Tool selection grants no additional sandbox, shell, network or publication capability.

The implementation is forge-neutral and applies on GitHub, GitLab and Forgejo.

Breaking change and migration

BREAKING CHANGE: previously ignored unknown Pi tool names now request exact native extension tools, and invalid native patterns fail setup. Remove stale Claude-only names or declare a vetted extension that supplies each exact requested name. An explicit empty selection now excludes extension tools as well as built-ins. The existing runner behavior of adding read for skills remains documented.

Validation

  • go test ./internal/runtime -count=1 -coverprofile=...: passes; package coverage 94.4%.
  • Approximate changed instrumented Go line coverage: 47/48 (97.9%), above the 80% target.
  • All 180 extension tests pass with FULLSEND_TEST_PI_BIN set to pinned Pi 1.6.0 and node --test --test-concurrency=1 internal/runtime/pi_extension/*.test.mjs.
  • Real-Pi tests use a local scripted provider and the production child argument builder: selected native execution; forbidden sibling, shell and edit calls; empty parent/child selections; missing/duplicate/non-vetted names before inference; native hook denial through fullsend's adapter; modified manifest; and parent/persona permission intersections.
  • Changes staged before make lint; all applicable checks pass, including security scans, Go vet and Markdown links. git diff --check passes.
  • Existing MCP, child loadout, hook and extension integrity regression tests pass. Review identified a missing per-turn active-set restoration; it is fixed and regression-tested.
  • One existing 300 ms child-timeout test flaked under concurrent Go/lint/JS load; the full serial run passes without changing that test or its timeout.

Prepared with coding-agent assistance. Human-directed commits carry DCO sign-off.

Signed-off-by: eshulman2 <ellashulman1@gmail.com>
@eshulman2
eshulman2 requested a review from a team as a code owner November 10, 2026 10:08
@github-actions

Copy link
Copy Markdown

E2E tests did not run

E2E tests run automatically for pull requests authored by users with write access or higher.

For other contributors, someone with write access must add the ok-to-test label after the latest push.

Reason: unauthorized

See E2E testing guide for details.

@qodo-code-review

qodo-code-review Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (3) 📘 Rule violations (1) 📎 Requirement gaps (1) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)

Grey Divider


Remediation recommended

1. Pi runtime guide still says empty tool lists use the old flag 📘 Rule violation ⚙ Maintainability
Description
docs/runtimes/pi.md still says buildPiRunCommand uses --no-builtin-tools for parents whose
tools map to an empty list, although the launch branch now emits --tools ''. When debugging an
explicit empty selection, readers would look for the wrong flag and expect extension tools to load,
contradicting the updated guidance in docs/contributing/runtime-implementation.md.
Code

docs/contributing/runtime-implementation.md[1144]

+| `tools` / `toolMode` / `exploreTools` | Parent selection and launch mode (`default` or `explicit`). Each launch and fallback retry queries `pi.getActiveTools()` and `pi.getAllTools()` for active names plus registered `codemode`/`deferred` tools: pi permits nested calls to the latter even when inactive. Inactive direct tools (including `defaultActive: false` direct tools) and other inactive registrations are not added. Default mode retains that callable set; explicit lists restrict names/patterns further. No built-in classification list is needed. Patterns are resolved against concrete callable names, then intersected with the persona's selection or Explore's read-only built-ins, always excluding `Agent`/`Task`. Missing `toolMode` retains explicit-list selection only; it does not guarantee compatibility with older manifests. Missing or malformed `mcpResourceTools` returns a structured `rejected` result before acquiring a child slot. An empty child selection becomes `--tools ''`, filtering both built-in and extension tools. For explicit nonempty parent and child selections without `mcp__` entries, `--exclude-tools` denies `mcp__*` plus each unselected resource tool (`list_mcp_resources`, `list_mcp_resource_templates`, `read_mcp_resource`), preserving selected resource names/patterns. The Go tool mapper translates Claude's `ListMcpResourcesTool` to both list resource tools and `ReadMcpResourceTool` to `read_mcp_resource`. It also accepts the three pi-native resource names and scoped `list_mcp_*`/`read_mcp_*` patterns in parent and persona configuration; those spellings are pi-only. Pi otherwise retains these registrations callable through codemode/deferred exposure even when inactive. Parents without `tools:` keep default behavior. Parents whose translated tools are empty use `--tools ''`; both parent and child selections exclude unselected extension tools |
Relevance

●●● Strong

Stale doc sentence contradicting code and sibling guide; team consistently accepts doc-accuracy
fixes.

PR-#1039
PR-#7027
PR-#8587

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The launch branch in internal/runtime/pi_run.go emits --tools '' for an explicit empty
selection, while docs/runtimes/pi.md line 452 still says that case uses --no-builtin-tools. The
matching sentence in docs/contributing/runtime-implementation.md was updated, but this guide
sentence was not.

Rule 2806787: Verify docs changes against contributing documentation guidelines
docs/runtimes/pi.md[452-452]
internal/runtime/pi_run.go[723-732]
docs/contributing/documentation.md
internal/runtime/pi_run.go[726-733]
docs/runtimes/pi.md[449-454]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The Pi runtime guide describes the old flag for an explicit empty parent tool selection. The launch now uses `--tools ''`, which excludes both built-in and extension tools.

## Fix Focus Areas
- docs/runtimes/pi.md[452-454]
- internal/runtime/pi_run.go[723-732]

## Recommended Fix
Replace the `--no-builtin-tools` reference in the Pi runtime guide with `--tools ''` and state that an explicit empty parent selection excludes both built-in and extension tools, matching the updated wording in `docs/contributing/runtime-implementation.md`.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Dismiss ↗ | View ↗


2. Gateway tampering is misreported as a tool-selection failure 🐞 Bug ◔ Observability
Description
piToolSelectionExit and piGatewayConfigTamperedExit both equal 92, and piExecModel checks the
tool-selection branch first when m.Tools != nil. If a gateway run declares tools:, a rewritten
inference-gateway.json or local overlay reaches that branch and produces a selector diagnosis
rather than the gateway-specific diagnostic, directing the operator to the wrong file.
Code

internal/runtime/pi_tool_selection.go[11]

+const piToolSelectionExit = 92
Relevance

●●● Strong

Shared exit-code overloading causing misleading diagnostics was accepted in a closely matching pi
guard precedent.

PR-#6695

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The constants share exit code 92, and the gateway integrity guard returns that code. Because
piExecModel checks the selector branch before the gateway branch, a gateway integrity failure on a
run with explicit tools is handled as a selector failure.

internal/runtime/pi_gateway_run.go[43-43]
internal/runtime/pi_run.go[1133-1145]
internal/runtime/pi_tool_selection.go[10-17]
internal/runtime/pi_gateway_run.go[40-43]
internal/runtime/pi_gateway_run.go[175-180]
internal/runtime/pi_run.go[1133-1143]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The tool selector and gateway-configuration integrity guard both use exit code 92. When a gateway run declares explicit tools, the selector branch consumes a gateway integrity failure before the gateway diagnostic can run.

## Fix Focus Areas
- internal/runtime/pi_tool_selection.go[10-17]
- internal/runtime/pi_extension/fullsend-tools.js[8-8]
- internal/runtime/pi_run.go[1133-1134]

## Recommended Fix
Assign the tool selector an exit code unused by other runtime guards, update both the Go constant and `SELECTION_EXIT` in fullsend-tools.js, and update any tests that assert 92 for selector failures. Add a test for a gateway-integrity failure on a run with explicit tools to verify that it receives the gateway diagnostic.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Dismiss ↗ | View ↗


3. Missing-tool failure is only tested behind an env-gated Pi binary 📎 Requirement gap ⚙ Maintainability
Description
The Go tests (TestPiExactNativeTools, TestPiToolSelectorBootstrap) only check name syntax and
manifest contents, so nothing in a normal go test run shows that a missing or ambiguous native
name stops the run before inference. That behaviour lives in the JS selector selectTools, which
throws when registry has zero or two matches, and it is exercised only by `real Pi refuses
missing, ambiguous and non-vetted selections before inference. That test is wrapped in { skip:
!realPi }, so it is skipped unless FULLSEND_TEST_PI_BIN` is set. The same gating applies to the
real-Pi tests for the selected-tool, hook-denial and empty-selection boundaries.
Code

internal/runtime/pi_extension/fullsend-tools.test.mjs[R105-106]

+test("real Pi refuses missing, ambiguous and non-vetted selections before inference", { skip: !realPi }, async () => {
+  for (const config of [{ missing: true }, { duplicate: true }, { wrongOrigin: true }]) {
Relevance

●● Moderate

Test-gating concern is reasonable, but making real-Pi tests run by default is costly; precedents on
CI test coverage are mixed.

PR-#6365

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
Rule 4444014 asks that normal runtime tests show a missing name failing before the model call, using
a neutral real-Pi extension. In this PR that proof exists only in a JS test skipped unless a pinned
Pi binary is provided, and the Go tests never exercise the missing-name path, so a default test run
would not catch a regression.

Document and test the selection behavior
internal/runtime/pi_extension/fullsend-tools.test.mjs[105-106]
internal/runtime/pi_extension/fullsend-tools.js[24-40]
internal/runtime/pi_tool_selection_test.go[19-28]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The proof that a missing or ambiguous native tool name fails before inference is only in `real Pi refuses missing, ambiguous and non-vetted selections before inference` in `internal/runtime/pi_extension/fullsend-tools.test.mjs`. That test is skipped unless `FULLSEND_TEST_PI_BIN` is set, and the Go tests do not reach the selector's missing-name path. Rule 4444014 requires this to run in normal runtime tests.

## Fix Focus Areas
- internal/runtime/pi_extension/fullsend-tools.test.mjs[105-113]
- internal/runtime/pi_extension/fullsend-tools.js[24-40]
- internal/runtime/pi_tool_selection_test.go[19-28]

## Recommended Fix
Add a Go-level or non-gated JS test that calls `selectTools` with an empty registry and with duplicate registrations, and asserts that it throws before any model call. Keep the real-Pi variant as the pinned-binary acceptance check. Alternatively, make the Go test harness run the real-Pi test in CI and state that gate in the migration documentation.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Dismiss ↗ | View ↗


View medium (2)
4. Personas silently lose tools no extension provides 🐞 Bug ≡ Correctness
Description
piToolsFor now treats exact native names such as WebFetch as supported without verifying that a
vetted extension supplies them, so piPersonaTools and piPersonaRegistrable register personas
they previously refused. When such a persona dispatches, child selection intersects its requested
names with the parent’s callable tools and checks only the result, silently dropping a missing name
or launching with --tools '' if none remain, while the troubleshooting row in
docs/runtimes/pi.md still says missing selections fail.
Code

internal/runtime/pi_agent.go[R314-318]

+			if !piNativeToolName(ct) {
+				unsupported = append(unsupported, ct)
+				continue
+			}
+			pt = ct
Relevance

●● Moderate

Real semantic gap in native-name validation; no close precedent on accept or reject for this exact
persona-drop case.

PR-#9693

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
piPersonaTools rejects only names that piToolsFor reports as unsupported, but the translator now
accepts exact native names without checking for a supplying extension. The persona test’s change
from WebFetch to WebFetch* preserves its error expectation while showing why plain WebFetch
can register. At dispatch, selection uses the intersection with the parent’s live callable tools, so
an unavailable requested name never reaches the selector’s check; childArgs renders an empty
result as an explicit empty tool list.

internal/runtime/pi_personas.go[454-481]
internal/runtime/pi_agent.go[312-319]
docs/runtimes/pi.md[823-823]
internal/runtime/pi_extension/fullsend-tools.js[86-92]
internal/runtime/pi_agent.go[311-319]
internal/runtime/pi_personas.go[344-361]
internal/runtime/pi_extension/fullsend-agent.js[454-481]
internal/runtime/pi_extension/fullsend-agent.js[525-535]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Exact native tool names in persona `tools:` now pass registration even when no loaded, vetted extension supplies them. Dispatch can silently drop the missing name from the child’s selection or launch the child with an empty tool list instead of reporting the missing tool.

## Fix Focus Areas
- internal/runtime/pi_agent.go[314-319]
- internal/runtime/pi_personas.go[344-361]
- internal/runtime/pi_personas.go[454-481]
- internal/runtime/pi_extension/fullsend-agent.js[454-478]
- internal/runtime/pi_extension/fullsend-agent.js[531-540]
- internal/runtime/pi_extension/fullsend-tools.js[83-99]
- docs/runtimes/pi.md[823-823]

## Recommended Fix
Record each persona’s requested native names in its manifest entry and, before child inference, validate them against the loaded, vetted extension registry and the parent’s callable tools. Return a clear missing-tool error for a declared native name with no verified implementation, without treating an intentionally empty parent/persona permission intersection as a missing implementation. Alternatively, continue refusing Claude-only names in personas until this validation exists. Update the troubleshooting row in `pi.md` to match the resulting behavior.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Dismiss ↗ | View ↗


5. Runs that declare tools fail without a recorded manifest digest 🐞 Bug ☼ Reliability
Description
The selector exits 92 whenever FULLSEND_PI_MANIFEST_SHA256 is unset, but buildPiRunCommand
exports that variable only when manifestSum is non-empty, i.e. only when Bootstrap ran in the same
process. Any caller that bootstraps in one process and runs in another now fails every pi run with a
declared tools: list before inference. The existing seam was designed to allow that case: its
comment says failing closed there would break such callers.
Code

internal/runtime/pi_extension/fullsend-tools.js[R74-77]

+    const bytes = readFileSync(process.env.FULLSEND_PI_MANIFEST || "/sandbox/pi-config/fullsend-manifest.json");
+    const want = process.env.FULLSEND_PI_MANIFEST_SHA256;
+    if (!want || createHash("sha256").update(bytes).digest("hex") !== want) throw new Error("manifest integrity missing or changed");
+    manifest = JSON.parse(bytes);
Relevance

●● Moderate

Fail-closed guard vs cross-process callers is a judgment call; the team has accepted explicit
no-entry handling but rejected warnings for the same case.

PR-#8637
PR-#6756

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
piManifestHash returns "" when Bootstrap did not run in this process, and the export of
piManifestSumEnv is guarded by manifestSum != "". The new selector is loaded whenever m.Tools !=
nil and exits immediately when want is empty.

internal/runtime/pi_bootstrap.go[412-441]
internal/runtime/pi_run.go[621-646]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
fullsend-tools.js requires FULLSEND_PI_MANIFEST_SHA256, but Run exports it only when Bootstrap recorded a digest in the same process. Without it, every run that declares `tools:` exits 92.

## Fix Focus Areas
- internal/runtime/pi_extension/fullsend-tools.js[71-82]
- internal/runtime/pi_run.go[485-487]
- internal/runtime/pi_run.go[643-645]

## Recommended Fix
Pick one behaviour and make it explicit: either have Run fail with a clear guardErr when m.Tools != nil and manifestSum is empty, or let the selector fall back to reading the manifest without a digest when the env var is absent (as the hook adapter does). Document which one you chose.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Dismiss ↗ | View ↗


Grey Divider

Context sources
✅ Linked PRs:
  🌐 PR #9179
❌ Tickets: failed to load — Ticket collection could not establish complete evidence
✅ Compliance rules (platform): 96 rules
✅ Skills: 5 invoked
  writing-user-docs
  writing-adrs
  check-patch-coverage
  cutting-releases
  adr-corner
✅ Cross-repo context — repo relationships
  Explored: repo: fullsend-ai/agents (sha: b11d1b1c) — View relationship
  Explored: repo: fullsend-ai/mlflow-assessments (sha: e0fbd4e2) — View relationship
  Explored: repo: fullsend-ai/test-creator (sha: a5082d20) — View relationship
  Explored: repo: fullsend-ai/pi-anthropic-vertex (sha: e9fa7206) — View relationship
  Explored: repo: fullsend-ai/pi-xai-vertex (sha: d18d87ba) — View relationship
  Explored: repo: fullsend-ai/metrics (sha: b5e856d5) — View relationship
✅ Context preparation
  Past issues: summarized; full text retained for this review
Review mode: Auto: 🧠 Deep: Security-sensitive runtime changes span selection, integrity, hooks, and child dispatch.

Grey Divider

Tip of the day
💡 Did you know, you can keep summaries lean with Findings visible per group, which tucks the rest behind a View link

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Previous reviews

Review updated until commit cc928ba 🧠 Deep

Results up to commit 97001cc ⏭️ Skipped


No changes from previous review

Grey Divider

Qodo Logo

@qodo-code-review

qodo-code-review Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

PR Summary by Qodo

Select exact vetted Pi extension tools for parent and child runs

✨ Enhancement 🐞 Bug fix 🧪 Tests 📝 Documentation 🕐 40+ Minutes

Grey Divider

AI Description

• Resolve exact native Pi tool names from vetted extensions instead of silently dropping them.
Merge Risk 🟡 Medium

Blast radius 🟢 Low 💥 1 capability

  • 1 affected end-to-end capability after fault-specific containment; implementation boundaries do not widen its functional scope.
  • The changed bootstrap, command construction, selector extension, and child argument path all implement one bounded outcome: executing a Pi agent with the configured parent/child tool permissions.
  • The child path is part of the same Pi runtime integration rather than an independent functional scope; it propagates the selected permission set from the parent into child execution.
  • Parent selection, lifecycle restoration, call blocking, and child intersection determine one end-to-end Pi runtime behavior: which configured tool actions an agent can perform.
  • They share the same bounded runtime integration and do not represent independent product domains.
  • The same bounded Pi runtime capability includes parent and child authorization because child tool permissions are derived from and intersected with the parent selection before execution.
Sources

internal/runtime/pi_extension/fullsend-tools.js[64-68]

  pi.on("tool_call", (event) => {
    const name = event.toolName;
    if (allowed.has(name) || (mcpSelector(name) && manifest.tools.some((pattern) => matches(pattern, name)))) return;
    return { block: true, reason: "tool is outside the strict Fullsend selection" };
  });

internal/runtime/pi_extension/fullsend-agent.js[534-536]

  if (agent.toolSelector) {
    args.push("-e", agent.toolSelector, "--fullsend-selected-tools", JSON.stringify({ tools, activeTools }));
  } else if (activeTools.length !== tools.length || activeTools.some((t, i) => t !== tools[i])) {
Behavioral complexity 🔴 High 🧩 Multiple interactions

  • Before: child active-tool restoration and MCP registration were handled by the prior child extension path, while explicit lists primarily controlled Pi's CLI selection.
  • After: Bootstrap, shell guards, manifest digests, extension load order, selector registry validation, lifecycle hooks, active/callable separation, MCP late registration, and child intersections must agree.
  • New correctness conditions are: (1) the selector loads after every vetted extension it must inspect; (2) the selected registry identity and source path remain stable; (3) activeTools is a subset of tools for children; (4) lifecycle reactivation cannot widen or accidentally narrow the intended set; and (5) call-time authorization matches activation.
  • These are newly coordinated invariants, not merely routine reuse of an existing mapping or hook helper.
Sources

internal/runtime/pi_extension/fullsend-tools.js[64-68]

  pi.on("tool_call", (event) => {
    const name = event.toolName;
    if (allowed.has(name) || (mcpSelector(name) && manifest.tools.some((pattern) => matches(pattern, name)))) return;
    return { block: true, reason: "tool is outside the strict Fullsend selection" };
  });

internal/runtime/pi_extension/fullsend-agent.js[534-536]

  if (agent.toolSelector) {
    args.push("-e", agent.toolSelector, "--fullsend-selected-tools", JSON.stringify({ tools, activeTools }));
  } else if (activeTools.length !== tools.length || activeTools.some((t, i) => t !== tools[i])) {
Potential damage 🔴 High 🩹 Integrity

  • If the new authorization layer admits an unintended native extension tool, that extension could perform an operation the agent configuration explicitly excluded.
  • The concrete consequence depends on the vetted extension's behavior and existing sandbox/hook policy; the repository does not establish that every native tool can publish data or mutate external systems.
  • This is therefore a plausible serious integrity consequence of a bypass, not a claim that all runs or tools have that impact.
  • Reverting code stops future bypasses but does not automatically undo an already executed external action; compensation would be extension- and action-specific.
  • Future exposure is recoverable by rollback or redeployment.
  • Any external effect already performed would require the affected extension's supported compensation or manual remediation; no automatic compensating path is shown.
Sources

internal/runtime/pi_extension/fullsend-tools.js[64-68]

  pi.on("tool_call", (event) => {
    const name = event.toolName;
    if (allowed.has(name) || (mcpSelector(name) && manifest.tools.some((pattern) => matches(pattern, name)))) return;
    return { block: true, reason: "tool is outside the strict Fullsend selection" };
  });

internal/runtime/pi_extension/fullsend-agent.js[534-536]

  if (agent.toolSelector) {
    args.push("-e", agent.toolSelector, "--fullsend-selected-tools", JSON.stringify({ tools, activeTools }));
  } else if (activeTools.length !== tools.length || activeTools.some((t, i) => t !== tools[i])) {
Assessed commit cc928ba
Diagram

graph TD
  A["Agent tools"] --> B["Pi bootstrap"] --> C["Pinned manifest"] --> D["Launch guard"] --> E["Pi tool registry"] --> F["Exact selector"]
  C --> G["Child dispatch"] --> F
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Rely on Pi's --tools allowlist
  • ➕ Less runner-owned code and fewer integrity checks.
  • ➖ Cannot establish that a native name came from a vetted extension or enforce the child active/callable distinction.
2. Change or fork Pi's tool loader
  • ➕ Could enforce selection directly in the runtime registry.
  • ➖ Creates an upstream dependency or a maintained fork for a runner-specific permission policy.

Recommendation: Use the runner-owned selector: it verifies tool origin and child permissions without widening the sandbox or changing Pi. Review its interaction with Pi registration and lifecycle events closely, since those are the policy boundary.

Files changed (19) +557 / -32

Enhancement (6) +186 / -12
pi_agent.goPreserve exact native Pi tool names +31/-5

Preserve exact native Pi tool names

• Passes valid unknown names through tool translation, rejects invalid native patterns, and identifies native selections for verification.

internal/runtime/pi_agent.go

pi_bootstrap.goInstall and manifest the tool selector +14/-3

Install and manifest the tool selector

• Uploads the runner-owned selector and records strict, native, and child selector settings, including its digest.

internal/runtime/pi_bootstrap.go

fullsend-agent.jsPass resolved child permissions to the selector +3/-1

Pass resolved child permissions to the selector

• Loads the selector for children and passes their concrete callable and active tool sets through a runner-owned flag.

internal/runtime/pi_extension/fullsend-agent.js

fullsend-tools.jsEnforce strict tool selection inside Pi +101/-0

Enforce strict tool selection inside Pi

• Verifies selected native registrations against vetted extension paths, restores active tools at lifecycle boundaries, and blocks unselected calls. Preserves supported MCP pattern behavior and exits on selection or manifest-integrity failures.

internal/runtime/pi_extension/fullsend-tools.js

pi_run.goGuard and load the Pi selector on run +14/-3

Guard and load the Pi selector on run

• Checks selector integrity around environment loading, loads it after declared extensions, and uses an empty allowlist that excludes extension tools. Treats selector failure as fatal rather than a model-fallback condition.

internal/runtime/pi_run.go

pi_tool_selection.goEmbed and hash the Pi selector +23/-0

Embed and hash the Pi selector

• Adds the embedded extension, digest calculation, shell integrity guard, and dedicated failure exit code.

internal/runtime/pi_tool_selection.go

Tests (8) +308 / -13
openai_seeder_test.goKeep unsupported-tool fixture invalid +1/-1

Keep unsupported-tool fixture invalid

• Changes a persona fixture to an unsupported wildcard now that an exact unknown name can denote a native tool.

internal/runtime/openai_seeder_test.go

pi_agent_test.goTest exact native-name translation +8/-2

Test exact native-name translation

• Updates expectations for formerly unsupported names and tests deduplication and invalid-pattern rejection.

internal/runtime/pi_agent_test.go

pi_bootstrap_test.goAccount for the child selector digest +3/-3

Account for the child selector digest

• Updates manifest assertions to include the selector in child extension integrity coverage.

internal/runtime/pi_bootstrap_test.go

pi_edit_repair_test.goExpect an explicit empty Pi allowlist +1/-1

Expect an explicit empty Pi allowlist

• Checks that an empty selection uses '--tools ''' rather than disabling only built-ins.

internal/runtime/pi_edit_repair_test.go

fullsend-tools.test.mjsTest selector policy and pinned-Pi behavior +182/-0

Test selector policy and pinned-Pi behavior

• Covers origin checks, activation, MCP behavior, child intersections, empty selections, hook denial, and manifest failures. Includes offline real-Pi acceptance cases when the pinned binary is supplied.

internal/runtime/pi_extension/fullsend-tools.test.mjs

pi_personas_test.goRetain an invalid persona-tool fixture +3/-3

Retain an invalid persona-tool fixture

• Uses an unsupported wildcard so the persona rejection test remains valid under exact native-name selection.

internal/runtime/pi_personas_test.go

pi_run_test.goUpdate launch-command assertions +3/-3

Update launch-command assertions

• Checks the selector guard's command prefix and the new explicit empty tool argument.

internal/runtime/pi_run_test.go

pi_tool_selection_test.goTest selector bootstrap and fail-closed launch +107/-0

Test selector bootstrap and fail-closed launch

• Covers translation, uploaded selector contents, digest enforcement, load order, and fatal handling of a tampered selector.

internal/runtime/pi_tool_selection_test.go

Documentation (5) +63 / -7
architecture.mdRecord exact Pi extension-tool selection +4/-0

Record exact Pi extension-tool selection

• Adds the implemented selection rule, failure behavior, and child permission intersection to the architecture overview.

docs/architecture.md

run.mdDocument Pi run migration +7/-0

Document Pi run migration

• Explains exact native names, rejection of unknown selections, and explicit empty tool lists.

docs/cli/run.md

runtime-implementation.mdDescribe selector implementation and acceptance tests +22/-1

Describe selector implementation and acceptance tests

• Updates child tool-selection behavior and documents selector installation, integrity checks, lifecycle enforcement, and pinned-Pi validation.

docs/contributing/runtime-implementation.md

bring-your-own-agent.mdExplain native tools in agent frontmatter +8/-0

Explain native tools in agent frontmatter

• Shows how to select a vetted extension tool and migrate previously ignored names.

docs/guides/user/bring-your-own-agent.md

pi.mdDocument strict Pi tool-selection semantics +22/-6

Document strict Pi tool-selection semantics

• Replaces the extension-tool exclusion guidance with exact native selection, empty-list behavior, failure cases, and migration advice.

docs/runtimes/pi.md

@ascerra ascerra left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm for this. I hit the same limit with a small extension (code): once tools: names a built-in, Pi hides the extension tools, so I had to leave tools: off entirely (note).

One thing that may help now: with tools: left off, extension tools already run on fullsend. I ran them in a GitLab pipeline on v0.55.0 (results). So the CVE extension may not need to wait for this to run, only to be locked down. I haven't tried that extension itself.

Two questions inline.

Resolve native extension tools without widening parent or child permissions.
Preserve MCP registration and exposure semantics, fail closed before inference,
and guard the selector on launch and dispatch. Add pinned-Pi acceptance tests
and document migration from silently ignored tool names.

BREAKING CHANGE: Unknown Pi tool names now require a vetted extension that
registers the exact requested name. Remove stale names or load their extension.
Explicit empty selections now exclude extension tools as well as built-ins.

Signed-off-by: eshulman2 <ellashulman1@gmail.com>
Signed-off-by: eshulman2 <ellashulman1@gmail.com>
@eshulman2 eshulman2 changed the title docs(adr): define exact Pi extension tool selection feat(runtime)!: select exact vetted Pi extension tools Nov 23, 2026
Signed-off-by: eshulman2 <ellashulman1@gmail.com>
@eshulman2
eshulman2 marked this pull request as ready for review November 23, 2026 08:56
@eshulman2
eshulman2 requested a review from ascerra November 23, 2026 08:56
@github-actions

Copy link
Copy Markdown

Site preview

Preview: https://3eced406-site.fullsend-ai.workers.dev

Commit: cc928ba7f2da6a487ddf63e88ad2329166418a2d

| `providerModels` | Per provider a run can serve with no `models` entry, the model ids it can serve: `google-vertex` verbatim from the catalog the pinned pi bundles (`@earendil-works/pi-ai` `dist/providers/data/google-vertex.json`), and `xai-vertex` from the ids the vendored extension registers (`xai/grok-4.6`, the publisher-qualified wire form). `openai` is present only when the run-scoped OpenAI provider is attached, listing the ids that configured children resolve to (`subagents.<persona>`, `subagents.default`, a persona's frontmatter `model:`; `runtime.OpenAIChildren`), and its presence is what lets a non-openai parent dispatch to `openai` and turns on the OpenAI launch safeguards for the children (#7981). `gateway` is present only when a gateway run is registered, listing the ids of the rendered `inference-gateway.json`; it admits the `gateway` provider under any parent, since the extension's `-e` directory (`inference-gateway`) does not name the provider id (#8280). A `provider/id` call is accepted only when the full spec is in `models`, is the parent's own spec, or is listed here — a provider prefix alone is not enough, or an invented id would reach the API. A Grok spec is normalized to `xai-vertex/xai/<id>` first, exactly as `normalizeXaiVertexModel` does for the parent, and then goes through this same set |
| `thinking` | Children's `--thinking`; `FULLSEND_PI_SUBAGENT_THINKING` (validated) else `medium` |
| `tools` / `toolMode` / `exploreTools` | Parent selection and launch mode (`default` or `explicit`). Each launch and fallback retry queries `pi.getActiveTools()` and `pi.getAllTools()` for active names plus registered `codemode`/`deferred` tools: pi permits nested calls to the latter even when inactive. Inactive direct tools (including `defaultActive: false` direct tools) and other inactive registrations are not added. Default mode retains that callable set; explicit lists restrict names/patterns further. No built-in classification list is needed. Patterns are resolved against concrete callable names, then intersected with the persona's selection or Explore's read-only built-ins, always excluding `Agent`/`Task`. Missing `toolMode` retains explicit-list selection only; it does not guarantee compatibility with older manifests. Missing or malformed `mcpResourceTools` returns a structured `rejected` result before acquiring a child slot. An empty child selection becomes `--tools ''`, filtering both built-in and extension tools. For explicit nonempty parent and child selections without `mcp__` entries, `--exclude-tools` denies `mcp__*` plus each unselected resource tool (`list_mcp_resources`, `list_mcp_resource_templates`, `read_mcp_resource`), preserving selected resource names/patterns. The Go tool mapper translates Claude's `ListMcpResourcesTool` to both list resource tools and `ReadMcpResourceTool` to `read_mcp_resource`. It also accepts the three pi-native resource names and scoped `list_mcp_*`/`read_mcp_*` patterns in parent and persona configuration; those spellings are pi-only. Pi otherwise retains these registrations callable through codemode/deferred exposure even when inactive. Parents without `tools:` keep default behavior. Parents whose translated tools are empty still use `--no-builtin-tools`, but have no `Agent`/`Task`, so Bootstrap writes no child manifest |
| `tools` / `toolMode` / `exploreTools` | Parent selection and launch mode (`default` or `explicit`). Each launch and fallback retry queries `pi.getActiveTools()` and `pi.getAllTools()` for active names plus registered `codemode`/`deferred` tools: pi permits nested calls to the latter even when inactive. Inactive direct tools (including `defaultActive: false` direct tools) and other inactive registrations are not added. Default mode retains that callable set; explicit lists restrict names/patterns further. No built-in classification list is needed. Patterns are resolved against concrete callable names, then intersected with the persona's selection or Explore's read-only built-ins, always excluding `Agent`/`Task`. Missing `toolMode` retains explicit-list selection only; it does not guarantee compatibility with older manifests. Missing or malformed `mcpResourceTools` returns a structured `rejected` result before acquiring a child slot. An empty child selection becomes `--tools ''`, filtering both built-in and extension tools. For explicit nonempty parent and child selections without `mcp__` entries, `--exclude-tools` denies `mcp__*` plus each unselected resource tool (`list_mcp_resources`, `list_mcp_resource_templates`, `read_mcp_resource`), preserving selected resource names/patterns. The Go tool mapper translates Claude's `ListMcpResourcesTool` to both list resource tools and `ReadMcpResourceTool` to `read_mcp_resource`. It also accepts the three pi-native resource names and scoped `list_mcp_*`/`read_mcp_*` patterns in parent and persona configuration; those spellings are pi-only. Pi otherwise retains these registrations callable through codemode/deferred exposure even when inactive. Parents without `tools:` keep default behavior. Parents whose translated tools are empty use `--tools ''`; both parent and child selections exclude unselected extension tools |

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remediation recommended

1. Pi runtime guide still says empty tool lists use the old flag 📘 Rule violation ⚙ Maintainability

docs/runtimes/pi.md still says buildPiRunCommand uses --no-builtin-tools for parents whose
tools map to an empty list, although the launch branch now emits --tools ''. When debugging an
explicit empty selection, readers would look for the wrong flag and expect extension tools to load,
contradicting the updated guidance in docs/contributing/runtime-implementation.md.
Agent Prompt
## Issue description
The Pi runtime guide describes the old flag for an explicit empty parent tool selection. The launch now uses `--tools ''`, which excludes both built-in and extension tools.

## Fix Focus Areas
- docs/runtimes/pi.md[452-454]
- internal/runtime/pi_run.go[723-732]

## Recommended Fix
Replace the `--no-builtin-tools` reference in the Pi runtime guide with `--tools ''` and state that an explicit empty parent selection excludes both built-in and extension tools, matching the updated wording in `docs/contributing/runtime-implementation.md`.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Dismiss ↗ | View ↗

Comment on lines +105 to +106
test("real Pi refuses missing, ambiguous and non-vetted selections before inference", { skip: !realPi }, async () => {
for (const config of [{ missing: true }, { duplicate: true }, { wrongOrigin: true }]) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remediation recommended

3. Missing-tool failure is only tested behind an env-gated pi binary 📎 Requirement gap ⚙ Maintainability

The Go tests (TestPiExactNativeTools, TestPiToolSelectorBootstrap) only check name syntax and
manifest contents, so nothing in a normal go test run shows that a missing or ambiguous native
name stops the run before inference. That behaviour lives in the JS selector selectTools, which
throws when registry has zero or two matches, and it is exercised only by `real Pi refuses
missing, ambiguous and non-vetted selections before inference. That test is wrapped in { skip:
!realPi }, so it is skipped unless FULLSEND_TEST_PI_BIN` is set. The same gating applies to the
real-Pi tests for the selected-tool, hook-denial and empty-selection boundaries.
Agent Prompt
## Issue description
The proof that a missing or ambiguous native tool name fails before inference is only in `real Pi refuses missing, ambiguous and non-vetted selections before inference` in `internal/runtime/pi_extension/fullsend-tools.test.mjs`. That test is skipped unless `FULLSEND_TEST_PI_BIN` is set, and the Go tests do not reach the selector's missing-name path. Rule 4444014 requires this to run in normal runtime tests.

## Fix Focus Areas
- internal/runtime/pi_extension/fullsend-tools.test.mjs[105-113]
- internal/runtime/pi_extension/fullsend-tools.js[24-40]
- internal/runtime/pi_tool_selection_test.go[19-28]

## Recommended Fix
Add a Go-level or non-gated JS test that calls `selectTools` with an empty registry and with duplicate registrations, and asserts that it throws before any model call. Keep the real-Pi variant as the pinned-binary acceptance check. Alternatively, make the Go test harness run the real-Pi test in CI and state that gate in the migration documentation.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Dismiss ↗ | View ↗

Comment on lines +314 to +318
if !piNativeToolName(ct) {
unsupported = append(unsupported, ct)
continue
}
pt = ct

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remediation recommended

4. Personas silently lose tools no extension provides 🐞 Bug ≡ Correctness

piToolsFor now treats exact native names such as WebFetch as supported without verifying that a
vetted extension supplies them, so piPersonaTools and piPersonaRegistrable register personas
they previously refused. When such a persona dispatches, child selection intersects its requested
names with the parent’s callable tools and checks only the result, silently dropping a missing name
or launching with --tools '' if none remain, while the troubleshooting row in
docs/runtimes/pi.md still says missing selections fail.
Agent Prompt
## Issue description
Exact native tool names in persona `tools:` now pass registration even when no loaded, vetted extension supplies them. Dispatch can silently drop the missing name from the child’s selection or launch the child with an empty tool list instead of reporting the missing tool.

## Fix Focus Areas
- internal/runtime/pi_agent.go[314-319]
- internal/runtime/pi_personas.go[344-361]
- internal/runtime/pi_personas.go[454-481]
- internal/runtime/pi_extension/fullsend-agent.js[454-478]
- internal/runtime/pi_extension/fullsend-agent.js[531-540]
- internal/runtime/pi_extension/fullsend-tools.js[83-99]
- docs/runtimes/pi.md[823-823]

## Recommended Fix
Record each persona’s requested native names in its manifest entry and, before child inference, validate them against the loaded, vetted extension registry and the parent’s callable tools. Return a clear missing-tool error for a declared native name with no verified implementation, without treating an intentionally empty parent/persona permission intersection as a missing implementation. Alternatively, continue refusing Claude-only names in personas until this validation exists. Update the troubleshooting row in `pi.md` to match the resulting behavior.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Dismiss ↗ | View ↗

)

const piToolSelectionExtensionFile = "fullsend-tools.js"
const piToolSelectionExit = 92

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remediation recommended

2. Gateway tampering is misreported as a tool-selection failure 🐞 Bug ◔ Observability

piToolSelectionExit and piGatewayConfigTamperedExit both equal 92, and piExecModel checks the
tool-selection branch first when m.Tools != nil. If a gateway run declares tools:, a rewritten
inference-gateway.json or local overlay reaches that branch and produces a selector diagnosis
rather than the gateway-specific diagnostic, directing the operator to the wrong file.
Agent Prompt
## Issue description
The tool selector and gateway-configuration integrity guard both use exit code 92. When a gateway run declares explicit tools, the selector branch consumes a gateway integrity failure before the gateway diagnostic can run.

## Fix Focus Areas
- internal/runtime/pi_tool_selection.go[10-17]
- internal/runtime/pi_extension/fullsend-tools.js[8-8]
- internal/runtime/pi_run.go[1133-1134]

## Recommended Fix
Assign the tool selector an exit code unused by other runtime guards, update both the Go constant and `SELECTION_EXIT` in fullsend-tools.js, and update any tests that assert 92 for selector failures. Add a test for a gateway-integrity failure on a run with explicit tools to verify that it receives the gateway diagnostic.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Dismiss ↗ | View ↗

Comment on lines +74 to +77
const bytes = readFileSync(process.env.FULLSEND_PI_MANIFEST || "/sandbox/pi-config/fullsend-manifest.json");
const want = process.env.FULLSEND_PI_MANIFEST_SHA256;
if (!want || createHash("sha256").update(bytes).digest("hex") !== want) throw new Error("manifest integrity missing or changed");
manifest = JSON.parse(bytes);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remediation recommended

5. Runs that declare tools fail without a recorded manifest digest 🐞 Bug ☼ Reliability

The selector exits 92 whenever FULLSEND_PI_MANIFEST_SHA256 is unset, but buildPiRunCommand
exports that variable only when manifestSum is non-empty, i.e. only when Bootstrap ran in the same
process. Any caller that bootstraps in one process and runs in another now fails every pi run with a
declared tools: list before inference. The existing seam was designed to allow that case: its
comment says failing closed there would break such callers.
Agent Prompt
## Issue description
fullsend-tools.js requires FULLSEND_PI_MANIFEST_SHA256, but Run exports it only when Bootstrap recorded a digest in the same process. Without it, every run that declares `tools:` exits 92.

## Fix Focus Areas
- internal/runtime/pi_extension/fullsend-tools.js[71-82]
- internal/runtime/pi_run.go[485-487]
- internal/runtime/pi_run.go[643-645]

## Recommended Fix
Pick one behaviour and make it explicit: either have Run fail with a clear guardErr when m.Tools != nil and manifestSum is empty, or let the selector fall back to reading the manifest without a digest when the env var is absent (as the hook adapter does). Document which one you chose.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Dismiss ↗ | View ↗

@qodo-code-review

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit cc928ba

@waynesun09 waynesun09 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HIGH: Required test check fails: the real-Pi MCP launch test does not stage the new tool selector (internal/runtime/pi_frontmatter_mcp_test.go around line 56; the file is not in this diff, so this note is here instead of inline)

The required test check fails at head cc928ba (run 45142513710, job 137583718330). All three subtests of TestPiBootstrap_DirectMCPRealPi fail (pattern, bare-parent, bare-persona). The errors are Error: Unknown option: --fullsend-selected-tools and Failed to load extension "/sandbox/pi-config/fullsend-tools.js": Extension path does not exist.

Bootstrap now always writes toolSelector into the child manifest, and both buildPiRunCommand and childArgs add -e /sandbox/pi-config/fullsend-tools.js. This PR does not change pi_frontmatter_mcp_test.go or testdata/pi-direct-mcp.mjs, and neither mentions fullsend-tools.js or FULLSEND_PI_MANIFEST_SHA256. So the child cannot load the selector, and pi rejects the unregistered flag. The local go test ./internal/runtime run in the PR body skipped this test because FULLSEND_TEST_PI_BIN was unset. CI sets that variable.

Suggestion: In testPiDirectMCP and testdata/pi-direct-mcp.mjs, stage fullsend-tools.js the same way as the other runner-owned extensions, or rewrite the toolSelector path. Export FULLSEND_PI_MANIFEST and FULLSEND_PI_MANIFEST_SHA256 for the child. Rerun with FULLSEND_TEST_PI_BIN set to pinned pi 1.6.0, and correct the Validation section of the PR body.

Verified: required check fails: test (TestPiBootstrap_DirectMCPRealPi, log grep); test files unchanged in diff at cc928ba; raised by: Claude

// DeclaredExtensions are the vetted harness plugins inherited by children.
// The dispatcher rechecks their tree hashes before every child launch.
DeclaredExtensions []piManifestExtension `json:"declaredExtensions,omitempty"`
ToolSelector string `json:"toolSelector,omitempty"`

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MEDIUM: New manifest fields toolSelector, strictTools and nativeTools are not documented

The PR adds agent.toolSelector, plus strictTools and nativeTools at the top level, to the digest-covered Pi manifest. None of these names appear anywhere under docs/. The manifest field table in docs/contributing/runtime-implementation.md (around lines 1136-1145) lists the other security inputs, such as declaredExtensions, extensionDigests and mcpResourceTools, but not these. toolSelector decides which selector children load. nativeTools decides which names get the vetted-origin check. The tools row in that table still says pi keeps inactive registrations callable through codemode/deferred exposure. That is no longer true for strict-selection runs, because the new tool_call handler blocks them.

Suggestion: Add table rows for toolSelector, strictTools and nativeTools that say what each one controls, and update the tools row for the strict-selection tool_call block.

Verified: read code at head; grep docs/ for the field names returned nothing at cc928ba; raised by: DeepSeek

This branch was successfully deployed

1 active deployment
site-preview — cc928ba7 Deployed Nov 23, 2026 by github-actions[bot]
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.

Support exact native Pi extension tool selections

3 participants