Skip to content

Built-in long tail: --no-mcp keeps it, desktop only for a desktop, one set - #615

Merged
FMXExpress merged 9 commits into
mainfrom
claude/opencode2-h-longtail
Oct 26, 2026
Merged

FMXExpress merged 9 commits into
mainfrom
claude/opencode2-h-longtail

Conversation

@FMXExpress

@FMXExpress FMXExpress commented Oct 21, 2026 •

Copy link
Copy Markdown
Owner

Fewer tool schemas in every request, and --no-mcp no longer carries all of them. Targets main; not stacked. main (#608 through #614) is merged in; the five conflicts were independent additions side by side and both sides are kept.

What "deferred" means

Nothing is removed. A deferred tool is still callable and still listed by name in the prompt's "Deferred Tools" section; its schema just is not sent with every request. The model loads it with tool_search when it wants it. Tool schemas were 65% of every request on the build bench, so the long tail matters.

What this PR changes

  • --no-mcp no longer disables the long tail. The gateway, serve and TUI only reached the deferral through ConnectMCPServers, which --no-mcp skips, so those surfaces carried all 36 schemas and had no tool_search. Those three and pasclaw agent now share one --no-mcp entry, RegisterBuiltinDisclosureTools. This is most of the saving: under --no-mcp a request is now a third smaller.
  • desktop is deferred until a desktop connects. It arranges the desktop's windows and does nothing without a desktop, so API callers, channels and plain chats no longer carry its schema. A running desktop needs it from its first turn: the shell's prompt routes every screen request through it ("route it by calling the desktop tool"). Only the browser /desktop and the native app subscribe to /v1/desktop/events, and both do so on startup, so the gateway reveals desktop on subscribe. Like any reveal it is registry-wide and lasts the process, the same end state the model's own tool_search would reach, minus the wasted turn.
  • Tried and kept visible: memory_write, shell_background, memory_fetch. A hidden tool is one the model stops choosing, not one it searches for. Without shell_background a build goes through shell_exec and blocks, and no error ever says the background path existed. memory_fetch goes the same way: "remember this page" becomes web_fetch plus memory_write by hand. Rule 5 of the prompt recommends memory_write. "Never called on the bench" was circular evidence: a model cannot call what it cannot see.
  • One set, not two. The list now lives only in PasClaw.Tools.Types.ToolIsLongTail, read by both the registration sweep and the registry latch. The first cut kept a second list, and a tool registered after disclosure stayed visible.

Review fix

P2, --no-mcp registered tool_search when nothing was deferred, and it talked about MCP servers.

  • The useless schema: with --no-mcp, the only reason for tool_search is the built-in long tail. RegisterBuiltinDisclosureTools registers it only when builtin_progressive_disclosure is on; mcp_progressive_disclosure (default on) no longer adds a schema that defers nothing. af1b9af did this at four call sites; the entry replaces those four copies.
  • The MCP state: the old disclosure object kept a snapshot of the configured servers. A search that found nothing deferred, with nothing revealed yet, then named an enabled server as "still connecting, or the server failed to start … retry tool_search in a moment", in a process that never starts it. The --no-mcp disclosure keeps no server snapshot, and an empty search now says MCP is off in this process.

Numbers (bench/ragbench/README.md, six-turn RAG build, identical decisions)

Measured 2026-10-23 against today's main. Every run wrote the same five files and passed the same test. No desktop connects in this harness, so desktop stays deferred here.

run request bytes visible tools
main, default 156,142 19
main, --no-mcp 228,634 36
this PR with memory_fetch and shell_background deferred too 140,872 16
this PR as it stands (default and --no-mcp identical) 150,160 18

Keeping the two tools visible costs about 1.5 KB per request against the three-tool set. Against main the PR saves about 1 KB per request, and 34% under --no-mcp.

Tests

mcp_disclosure_tests:

  • TestBuiltinLongTailOneSet: the sweep and the latch defer the same set (desktop, db_*, and spawn_status registered after the sweep). memory_write, shell_background, memory_fetch, read_file and shell_exec stay visible, and the provider sees exactly those five. With the old three-tool set it fails.
  • TestNoMCPEntry (new), each part checked by reverting it and watching it fail:
    • With builtin_progressive_disclosure: false and the MCP flag on, nothing is registered or deferred. Without the gate it fails.
    • With an enabled MCP server in config and nothing deferred yet, the empty answer names --no-mcp and has no "connecting", "retry" or server name. Keeping the MCP snapshot reproduces the reported text exactly.
    • The latch still defers a long-tail tool registered later, select: reveals it, and the after-reveal answer has no "connecting" either.
    • All four surfaces call the new entry and never RegisterMCPDisclosureTools. Pointing serve back at the old function fails it.

desktop_reveal_tests (new, make test-desktop-reveal, real binary): a gateway on a scratch home lists no desktop in /v1/tools while tool_search is there. After a client subscribes to the desktop feed and reads its hello, desktop is listed and tool_search stays. Without the reveal it fails.

make test now runs test-mcp-disclosure. It was defined but never listed under test, so none of these cases ran in the suite.

End to end: pasclaw serve --no-mcp on a scratch home, GET /v1/tools. The default config lists tool_search; builtin_progressive_disclosure: false lists no tool_search and every tool visible.

Full make test green: 52 passes, plus mcp_disclosure_tests, which prints its own success line.

Docs

docs/mcp.md ("Built-in long tail": the set, the desktop reveal, --no-mcp), docs/configuration.md (builtin_progressive_disclosure row, previously undocumented), bench/ragbench/README.md (today's runs).

🤖 Generated with Claude Code

https://claude.ai/code/session_01KYD1zZPD7GuM8pF1btwi2U

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-21T21:02:01.054668Z fbf34b2 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fbf34b2adb

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/cmd/PasClaw.Cmd.Gateway.pas Outdated
Comment on lines +371 to +376
else if Reg <> nil then
{ --no-mcp skipped the only call that registers tool_search and
defers the built-in long tail, so every request carried all 36
tool schemas (28.5 KB) instead of 19 (15.7 KB). Same fix the
CLI's ConnectMCP already had. }
RegisterMCPDisclosureTools(Reg, Cfg);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Skip disclosure when --no-mcp has no deferred built-ins

When --no-mcp is combined with the documented builtin_progressive_disclosure: false opt-out, the default MCPProgressiveDisclosure = true still makes this call register tool_search, even though no MCP clients were started and no built-ins were deferred. The gateway, serve, and TUI therefore add a useless schema to every request; if MCP servers are configured, the handler can also incorrectly report that they are still connecting and suggest retrying. On the --no-mcp path, registration should depend only on built-in disclosure or otherwise suppress MCP-only state.

Useful? React with 👍 / 👎.

…disables it

An improve-mode loop run against PasClaw's own building ability, with
the harness checked in under bench/ragbench. The metric is request
bytes (about tokens) to accomplish one fixed task: a gateway runs
"build a Python RAG pipeline" through /v1/chat with the relay
provider, and worker.py stands in for the model, recording every
request's size and answering from a fixed playbook, so a before/after
comparison measures PasClaw's overhead and not model variance.

Benchmark. 6 turns, 156,064 request bytes on a default gateway. With
--no-mcp, 228,556.

Profile. Tool schemas were 15,703 of a 24,214-byte request (65%); the
system prompt 7,773 (32%, Rules 4,499); the conversation 491 bytes
growing to 3,760 by the last turn. Tool results were already terse.
Of 19 visible tools the task called three. Four of the visible ones
act on the agent's own state or UI rather than on the task -- desktop,
memory_write, memory_fetch, shell_background -- and were 3,972 bytes
on every request. The --no-mcp number had a different cause: the
gateway, serve and TUI only reached RegisterMCPDisclosureTools
through ConnectMCPServers, which --no-mcp skipped, so those surfaces
carried all 36 schemas and had no tool_search. The CLI's ConnectMCP
already handled this (Codex P1 on PR #547); the other three did not.

Improve. Those four names join the long-tail set, and the set now
lives in one place: PasClaw.Tools.Types.ToolIsLongTail, read by both
the registration sweep (DeferBuiltinTools) and the registry's
DeferLongTail latch. The first cut kept a second list in the sweep,
and shell_background -- registered by the background coordinator
after disclosure -- stayed visible; one predicate makes that
impossible. The three --no-mcp call sites now register disclosure the
way the CLI does.

Verify. Same playbook, same files written, same test output:
156,064 -> 132,562 bytes (-15.1%), 15 visible tools. --no-mcp:
228,556 -> 132,562 (-42.0%), now identical to the default. What the
measurement does not cover: a task that needs a deferred tool pays one
extra tool_search turn (about 20 KB on this profile), so a db_- or
spawn-heavy task is not represented; nor is model quality, which a
fixed playbook cannot see.

Research. The next cost by size is the Rules section (4.5 KB, 19% of a
request, re-sent every turn); trimming it is a prompt-quality change
this harness cannot judge, so it is noted in the README, not done.

Tested in mcp_disclosure_tests: the sweep defers the named and
prefixed tools registered before it, the latch defers the ones
registered after it, read_file and shell_exec stay visible, and the
provider sees exactly the visible set.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LGQKz579j1ZnDRwmr6h1V6
…e, record per-turn gap_ms, add probe.py

The first harness left a gateway behind whenever the build had no
run/gateway.json (main) or ignored SIGINT, and the next run then talked
to the stale one. The runner now refuses to start when the port already
answers, falls back to pgrep for the pid, and escalates INT -> TERM ->
KILL. worker.py records the gap between its answer and the next request
(gap_ms), which is what the overhead loop measures; probe.py splits that
gap at the queue.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LGQKz579j1ZnDRwmr6h1V6
…ust not cost a search turn

Deferring memory_write saved 1.4 KB per request on the build bench, where
it is never called, but the system prompt's own memory rule tells the
model to call it for dated facts, and a tool the prompt recommends has to
be in the tools array when the model reaches for it. desktop,
memory_fetch and shell_background stay deferred. Re-measured on main:
136,942 request bytes for the six-turn task, 16 schemas visible.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LGQKz579j1ZnDRwmr6h1V6
With --no-mcp there are no MCP clients, so the only reason to carry
tool_search is the built-in long tail. An operator who set
builtin_progressive_disclosure: false was still getting the tool (and
its schema on every request) because the gateway, serve, TUI and CLI
paths registered it unconditionally (Codex P2 on #615). All four now
gate on that flag. The MCP-side status text tool_search prints for
configured-but-unstarted servers is unchanged; it is only reachable
when the tool is registered for deferred built-ins.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LGQKz579j1ZnDRwmr6h1V6
main moved on by #608 through #614 since this branch was cut. Five
conflicts, all two independent additions side by side, all kept:

  - Cmd.Gateway / Cmd.Serve / Cmd.TUI uses clauses: this branch's
    PasClaw.MCP.Disclosure (for the --no-mcp registration) beside
    main's PasClaw.Gateway.RunFile, and in the TUI beside Worktree,
    Cmd.Attach and Client.Api.
  - docs/configuration.md: the builtin_progressive_disclosure row beside
    main's code-mode, background-jobs, permissions, worktree, cli.attach
    and shell-timeout rows.
  - docs/mcp.md: "Built-in long tail" beside main's "Code Mode".

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01KYD1zZPD7GuM8pF1btwi2U
…CP servers

The rest of the Codex P2 on #615. af1b9af gated the four --no-mcp
registrations on builtin_progressive_disclosure, which removed the
useless schema for an operator who opted out of built-in deferral. The
finding's second half was still there: tool_search on the --no-mcp path
was the MCP disclosure object, which snapshots the configured servers.
A search that found nothing deferred, with nothing revealed yet, then
named an enabled server as "still connecting, or the server failed to
start ... retry tool_search in a moment" -- in a process that never
starts it. That sends the model into a retry loop for a tool that will
not appear.

RegisterBuiltinDisclosureTools is the --no-mcp entry, used by
`pasclaw agent`, gateway, serve and the TUI in place of the four copies
of the gate:

  - registered only when builtin_progressive_disclosure is on
    (mcp_progressive_disclosure, default on, is irrelevant with no MCP
    client), and returns nil otherwise;
  - the disclosure carries no MCP-server snapshot, and an empty search
    says MCP is off in this process (--no-mcp) instead.

The deferral itself (sweep plus latch) is unchanged.

Tested in mcp_disclosure_tests, each part negative-verified:

  - opt-out with the MCP flag on: nil, no tool_search, nothing deferred.
    Without the gate: fails.
  - built-in deferral on, an enabled MCP server in config, nothing
    deferred yet: the answer names --no-mcp and has no "connecting",
    "retry" or server name. Keeping the MCP snapshot reproduces the
    reported text exactly ("still connecting ... replicate -- retry").
  - the latch still defers db_query registered later, select: reveals
    it, and the after-reveal answer has no "connecting" either.
  - the four surfaces call RegisterBuiltinDisclosureTools and not
    RegisterMCPDisclosureTools. Pointing serve back at the MCP entry
    fails it.

And end to end: `pasclaw serve --no-mcp` on a scratch home, GET
/v1/tools -- default config lists tool_search (16 visible tools);
builtin_progressive_disclosure: false lists no tool_search (30 visible).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01KYD1zZPD7GuM8pF1btwi2U
test-mcp-disclosure was defined but never listed under `test`, so the
suite did not run it: this PR's long-tail and --no-mcp cases, and every
older tool_search case in mcp_disclosure_tests, only ran when someone
asked for that target by name. Listed beside the other MCP targets. It
already isolates PASCLAW_HOME (its config round-trip calls SaveConfig).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01KYD1zZPD7GuM8pF1btwi2U
Deferring `desktop` was right for an API caller, a channel or a plain
chat -- it does nothing without a desktop -- and wrong for the one
surface that uses it. The browser desktop's shell prompt says "route it
by calling the `desktop` tool", so with the schema withheld the model
was told to call a tool it did not have, and had to spend a tool_search
turn before it could tile a window.

The gateway can tell when a desktop is running: the browser /desktop
and the native app are the only subscribers to /v1/desktop/events, and
both subscribe as soon as they start (before any turn, and again on
reconnect). HandleDesktopEvents now reveals `desktop` on subscribe.
A reveal is registry-wide and lasts the process, exactly as the model's
own tool_search would make it -- this only saves that turn. No-op when
the tool is not deferred or not registered. Everything else in the long
tail is unchanged, and so is `desktop` for a gateway no desktop has
connected to.

Tested with the real binary (new desktop_reveal_tests, in `make test`):
a gateway on a scratch home lists no `desktop` in /v1/tools while
tool_search is there; after a client subscribes to the desktop feed and
reads its hello, /v1/tools lists `desktop`, and tool_search stays for
the rest of the long tail. Without the reveal it fails. The test stops
its gateway on failure too (Fail_ halts, and Halt skips finally).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01KYD1zZPD7GuM8pF1btwi2U
A hidden tool is not one the model searches for, it is one it stops
choosing. Without shell_background's schema, a build goes through
shell_exec and blocks on it, and no error ever says the background path
existed. The "never called on the bench" evidence for deferring it was
circular: a model cannot call what it cannot see. memory_fetch the same
way -- "remember this page" turns into web_fetch plus memory_write by
hand, or nothing.

So the single-tool part of the set is `desktop` alone, revealed as soon
as a desktop connects. The spawn_* verbs that take a shell_background
handle stay deferred with the spawn family, as on main; the shell's
result arrives in the next turn on its own.

Re-measured with bench/ragbench (six turns, identical decisions, every
run wrote the same five files and passed the same test):

  main, default                              156,142 bytes  19 visible
  main, --no-mcp                             228,634        36
  this PR, all three deferred                140,872        16
  this PR, desktop only (= with --no-mcp)    150,160        18

About 1.5 KB per request is the price of the two tools, against the
three-tool set; against main the PR still saves about 1 KB per request,
and a third of every request under --no-mcp. The README has the table;
docs/mcp.md and the builtin_progressive_disclosure row now say 18 of 36.

TestBuiltinLongTailOneSet now asserts both stay visible through the
sweep and the latch (a spawn_status registered after the sweep proves
the latch still defers). With the old three-tool set it fails.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01KYD1zZPD7GuM8pF1btwi2U
@FMXExpress FMXExpress changed the title Built-in long tail: one set, four more tools, and --no-mcp no longer disables it Built-in long tail: --no-mcp keeps it, desktop only for a desktop, one set Oct 23, 2026
@FMXExpress
FMXExpress merged commit e360893 into main Oct 26, 2026
FMXExpress pushed a commit that referenced this pull request Oct 26, 2026
main moved on by #608 through #615 since this branch was cut. Two
conflicts:

  - Makefile, the .PHONY list and the `test` prerequisites: main's lines,
    plus this branch's one target, test-workspace-listing (which the
    branch's .PHONY line also carried twice).
  - PasClaw.Agent.Prompt interface: this branch's WorkspaceTopLevel /
    SafeEntryName beside #614's BuildInstructionsSection. Both kept.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01KYD1zZPD7GuM8pF1btwi2U
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.

2 participants