Skip to content

feat(tools): freeze and slim the OpenPI tool surface for cache stability (#879) - #880

Merged
tt-a1i merged 10 commits into
mainfrom
feat/frozen-tool-surface
Oct 18, 2026
Merged

tt-a1i merged 10 commits into
mainfrom
feat/frozen-tool-surface

Conversation

@tt-a1i

@tt-a1i tt-a1i commented Oct 18, 2026

Copy link
Copy Markdown
Collaborator

Problem

Issue #879: OpenPI changed the model-facing tool set mid-session (keyword discovery, lifecycle gates, task/goal/context state) through setActiveTools, which rebuilds the system prompt and wire tools array and invalidates the provider prompt/KV cache prefix. The resident surface had also grown large (12 OpenPI tools, ~14.3k wire characters) with several unused or redundant tools. Benchmarks additionally exposed three runtime defects: background terminals died with the session, the workspace cleanup guard blocked ordinary rm in non-interactive runs, and print/JSON runs lost subagent results when the turn ended before subagent_wait.

Value

  • Stable, cache-friendly requests: the tool set is fixed at session start and only changes at explicit user boundaries (/plan, /openpi-setup, browser authorization).
  • Lower per-request overhead with the same capabilities: 8 resident OpenPI tools (5 subagent, 3 workflow), 6,124 wire characters versus 14,294 before.
  • Benchmark parity with plain Pi on correctness and cost, with the OpenPI-specific failures removed.

Approach

  • Freeze the OpenPI tool surface per session; remove keyword discovery and runtime-state-driven tool churn (Decision 0005).
  • Delete low-value surfaces based on session evidence: get_goal and the goal extension, background terminals (use Pi Bash nohup … &), the workspace cleanup guard (native Pi has none); consolidate list/status tools; Code Mode becomes opt-in.
  • Compact resident tool contracts; detailed guidance moves to the subagents/workflows Skills.
  • Plan mode: replace the per-request transient tail reminder with a reminder anchored at each persisted state change, so consecutive requests stay exact prefixes after /plan has been used.
  • Subagents: in print/JSON mode the spawn result tells the model the process exits after the turn and to subagent_wait for needed results; interactive/RPC wording is unchanged.
  • Workflows: the resident contract and Skill show the parallel([() => agent(...)]) thunk form.

Validation

  • bun run check: pass.
  • bun run test at 88502e1: Node 2,339 pass / 0 fail; Vitest 97/97 files pass.
  • Terminal-Bench 2.1, deepseek-v4.1-flash, interleaved k=3 at a055ca7 versus plain Pi (Pi 1.3.0 both arms): OpenPI 27/30, Pi 29/30 (remaining failures are model-written code: cancel-async same assertion in both arms; one sqlite run hung in a model-written script until agent timeout). Converted cost OpenPI 1,838,824 vs Pi 1,918,663 (-4.2%, medians equal); cache 82.2% vs 79.6%; tool set constant; Blocked cleanup = 0.
  • Delegation tasks: delegation-explicit 3/3 clean; pre-fix b994d55 lost subagent results 2/3 vs 0/3 at a055ca7; workflow-explicit 3/3 correct, 1 trial hit the parallel() argument error fixed in 88502e1 (not re-benchmarked).
  • gpt-6.1-sol Responses smoke (fix-git): pass, tool calling normal, response settings not rewritten.
  • Evidence: benchmark archive tt-a1i/openpi-bench-archive @ a654ea4, runs/2026-10-18_a055ca7_tb-k3-and-delegation/.

Impact

  • User-visible: /goal, /ps, background terminal footer/Web capability, and the workspace cleanup guard are removed; Code Mode is off unless explicitly enabled (saved settings preserved).
  • Model-visible context/tools: resident OpenPI tools reduced to 8 with compact descriptions; no mid-session tool changes except explicit user boundaries; plan reminders are anchored in history; print/JSON spawn guidance changed.
  • Runtime/lifecycle: long-running processes rely on Pi Bash; subagent behavior otherwise unchanged.
  • Persisted config/data: no migration; codeMode.enabled parses as opt-in.
  • Risk: removed tools are gone for users who relied on them; deletion confirmation no longer exists in interactive sessions (same as native Pi).

tt-a1i and others added 9 commits October 17, 2026 23:50
Mid-session tool toggles rewrite the cached prompt prefix: every
setActiveTools call also rebuilds the Pi system prompt. Replace keyword
capability loading and state-driven lifecycle gates with one resident
tool set fixed at session start; only /plan, the /openpi-setup episode
and setup-applied browser permission may change tools.

- Remove capability discovery (openpi_load_tools, keyword routing,
  capabilities.discovery) and the fd/rg, runtime_snapshot, tasks and
  context_pivot tools; drop retired names from child allowlists.
- Keep git_* as a plan boundary and read-only child surface.
- Enforce resident tools at runtime and add frozen-surface and
  resident-budget tests; record Decision 0005 and amend AGENTS.md.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Fold the list operations into the status/check tools, the same
optional-id pattern workflow_status already uses: subagent_check lists
all subagents when called without id (evidence reads still require
one), and bg_status lists all background terminals without id.
get_goal is removed because the goal continuation prompt already
carries the objective, usage, and budget. subagent_wait stays a
separate tool because synchronous waiting must remain an explicit
model choice (AGENTS.md).

Resident surface goes from 17 to 14 tools; measured budget 17,758
chars, ceiling 19,600 (~10% headroom).

Generated with [Devin](https://devin.ai)
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
)

- CI: drop the deleted session-tasks-panel widget assertion and point the
  packed-extension smoke at extensions/git-read (file-search is gone).
- Children: role-listed read-only inspection tools
  (CHILD_READ_DERIVED_TOOL_NAMES: grep, find, ls, git_show/diff/log) may
  activate for a child even when the parent never did, provided the parent
  holds read — restoring planning and read-only children's search without
  widening the parent surface.
- Setup config: treat the retired capabilities key as known so old configs
  load without warnings and drop it on the next write.
- git-read: neutral capture-limit wording plus a ported capture-cap test.
- subagent_check: clearer evidence-read error text.
- Web: historical rg/fd calls render as search activity; dead task/goal
  i18n keys, the /goal composer entry, and the stale capabilities fixture
  removed.
- Goal: delete the feature entirely (extensions/goal, /goal, create_goal,
  update_goal; retired for stale allowlists). Resident set 14 -> 12 tools,
  measured budget 14,963 chars, ceiling 16,500. Old sessions containing
  goal entries and goal-continuation messages still load.
- Docs: README/SETUP/site counts and prose, RUNTIME_SNAPSHOT status,
  Decision 0005 amendment.

Generated with [Devin](https://devin.ai)
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…t resident tool contracts (#879)

Remove the background-terminals extension (bg_start/bg_status/bg_kill/
bg_watch, /ps, footer widget, Web capability) — 0 calls in 236 maintainer
sessions and its session_shutdown kill broke the one benchmark use; Pi
Bash (nohup … &) covers long-running processes. Resident set is now 8
tools (5 subagent, 3 workflow); measured surface 6,592 chars (wire-only
6,124) asserted ≤ 7,300. Code Mode defaults to disabled (codemode added
~1.9k chars per request with 0 calls); explicit saved settings are kept.
Resident descriptions rewritten as compact contracts per review with
detail moved to Skills.

Generated with [Devin](https://devin.ai)
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Branch protection on main requires the "Background terminals (Windows)"
status check. The job only aggregates windows-node and test-ui results
and does not depend on the removed background-terminals extension, so
keep it until maintainers rename the required check.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Delete extensions/workspace-cleanup-guard and its tests. Native Pi has no
deletion guard, and in the 2026-10-18 Terminal-Bench runs the guard blocked
legitimate commands in nginx-request-logging and regex-log in both rounds —
compound commands like `cd /app && rm -f test_regex.py && ls ...` and even
standalone `rm -f /etc/nginx/sites-enabled/default`. In no-UI sessions Pi's
confirm always returns false, so pre-existing deletions could never be
approved. Codex exec approvals are Never and OpenCode run auto-rejects with
feedback, so peers do not block-and-retry in non-interactive runs. Bash now
runs entirely under Pi's own behavior.

Generated with [Devin](https://devin.ai)
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…879)

The context hook appended the openpi-plan-context reminder at the tail of
every provider request once any plan-mode state entry existed in the branch.
Each new turn displaced it, so request k was never a prefix of request k+1;
Pi's anthropic provider puts its only history cache breakpoint on the last
user message, so the breakpoint moved every request and the history cache
was always rewritten, never read.

Reminders are now derived per persisted state entry (malformed decodes fail
closed to the blocked text) and anchored at the entry's position in the
branch, skipping consecutive duplicate states and never splitting an
assistant tool call from its toolResult run. Verified against a real session
fixture: consecutive requests are exact prefixes once more.

Generated with [Devin](https://devin.ai)
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
In print/json mode the process disposes the runtime when the parent
turn ends, which stops any running subagent and discards its result.
The spawn result now carries exitsAfterTurn and, for those modes,
requires subagent_wait before the final answer instead of promising
automatic delivery. Interactive and rpc runs keep the old text
byte-identical.

Generated with [Devin](https://devin.ai)
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…ontract (#879)

In the a055ca7 delegation benchmark one workflow-explicit trial passed
started agent() promises to parallel() and failed with "parallel() items
must be zero-argument functions" before retrying. The resident description
listed parallel() without its argument shape and the Skill body did not
show it either, so state the thunk form in both places.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@tt-a1i
tt-a1i requested a review from a team as a code owner October 18, 2026 15:02
@github-actions github-actions Bot added documentation Improvements or additions to documentation area:workflows Workflow engine, capability, skills, or tests area:subagents Subagent delegation, skills, or tests area:background-terminals Background terminal runtime, skill, or tests area:setup OpenPI setup, configuration, or setup documentation area:github GitHub workflows, templates, ownership, or tests labels Oct 18, 2026
…#879)

The inspection e2e was ported from background terminals to the subagent
panel, but Escape does not close that panel, so at 390px it still covered
the page and the sidebar button never appeared. Close it explicitly, and
locate it as the full-page main view on mobile.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:background-terminals Background terminal runtime, skill, or tests area:github GitHub workflows, templates, ownership, or tests area:setup OpenPI setup, configuration, or setup documentation area:subagents Subagent delegation, skills, or tests area:workflows Workflow engine, capability, skills, or tests documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant