Skip to content

fix(backend-claude): disallow the in-worker Apify tools in every session - #4021

Merged
schlessera merged 9 commits into
mainfrom
fix/3788-exclude-in-worker-apify
Nov 15, 2026
Merged

schlessera merged 9 commits into
mainfrom
fix/3788-exclude-in-worker-apify

Conversation

@schlessera

@schlessera schlessera commented Nov 15, 2026 •

Copy link
Copy Markdown
Owner

Closes #3788

What changed

A hosted Claude turn no longer exposes the in-worker core server's mcp__brain__brain_apify_* tools. An interactive turn loads the brain's .mcp.json, whose brain mcp server registers all ten brain_apify_* tools whatever the configuration. A worker never receives APIFY_TOKEN or BRAIN_APIFY_LEDGER, so every call to those copies refused with ledger_unset, under the same names and descriptions as the working mcp__brain-ui__brain_apify_* tools. IN_WORKER_APIFY_TOOLS is derived from APIFY_TOOL_NAMES and sits next to IN_WORKER_COMPUTE_TOOLS in packages/ui-backend-claude/src/sdk-options.ts. Every Claude session now disallows it, whatever the host configures, as it already does compute. The host's mcp__brain-ui__brain_apify_* tools and standalone brain mcp / brain apify are unchanged.

Why this shape

  • This is the issue's stated approach and the core: expose external compute through CLI, MCP and agent guidance #3107/ui-server: admit and observe external jobs through existing worker governance #3108 compute precedent. The exclusion is unconditional, so the tool list never depends on configuration (provider history).

  • The name list is derived from the shared contract (APIFY_TOOL_NAMES, the same object registerApifyTools registers from), so a new operation is excluded without a second list.

  • disallowedTools does remove the tools from the model's list on the production path. I checked this against the installed CLI rather than assuming it. I ran a temporary, uncommitted variant of scripts/capture-turn-surface.ts that serves core as a real stdio server, as .mcp.json does, and scripts ToolSearch select:mcp__brain__brain_apify_approvals followed by a call:

    • on origin/main: mcp__brain__brain_apify_run was in the deferred listing, ToolSearch answered Tool loaded., and the call went through;
    • with this change: neither the Apify nor the compute copies were listed (brain_search still was), ToolSearch answered No matching deferred tools found, and the call got No such tool available: mcp__brain__brain_apify_approvals.

    The committed capture serves core in-process (an SDK server). There the CLI keeps listing disallowed MCP tools and only refuses the call (Permission to use … has been denied), which is why tests/installed-turn-surface.test.ts still lists both the compute and Apify copies. I added a comment there saying so; its assertions are unchanged.

  • Pi: not exposed. Pi has no MCP client and never reads .mcp.json. Its core tools are curated custom tools, and its brain_apify_* tools are host bridge tools forwarded to the host (packages/ui-backend-pi/src/bridge-tools.ts:353-360), which the fixed apify capability enables (currentCaps, packages/ui-backend-pi/src/session-pool.ts:70-75). Only a third-party MCP extension, which an operator would have to turn on, could add an MCP server, and that is outside this backend's roster.

Proof

  • Roster test (packages/ui-backend-claude/tests/stable-roster.test.ts). The existing every-mode roster test gains an apify (enabled) mode. In every mode it asserts that no mcp__brain__ + APIFY_TOOL_NAMES name is missing from disallowedTools, and that the enabled mode still auto-allows mcp__brain-ui__brain_apify_run. The byte-identical native-exclusion check now covers the Apify names too. A new matrix covers interactive or autonomous × hosted or unhosted × Apify enabled or disabled × typed or voice (16 cases). It asserts the same exclusion and that no mcp__brain-ui__ tool is ever disallowed.
  • Failing first (test file as above, sdk-options.ts from origin/main): 33 pass, 17 fail. All failures are on the named assertion: 16 × IN_WORKER_APIFY_DISALLOWED and 1 × IN_WORKER_APIFY_DISALLOWED_voice, each listing the ten missing names.
  • After the fix: 50 pass, 0 fail.
  • Mutation (drop brain_apify_revoke from IN_WORKER_APIFY_TOOLS, restored afterwards): 33 pass, 17 fail on the same assertions. Each received ["mcp__brain__brain_apify_revoke"] where it expected [].
  • SDK options snapshot re-recorded with its own helper (sdkOptionsSnapshot) for this one reviewed change. The diff is exactly the ten mcp__brain__brain_apify_* names appended to disallowedTools in each of the six modes. Nothing else moves, and the provenance comment in sdk-options-snapshot.test.ts records it.
  • Package suite (packages/ui-backend-claude, bun run test), base against this change in the same sandbox: the failing sets are identical (51 sandbox-only real-CLI/bwrap failures, including the provider-history capture, which cannot spawn a worker here). The only extra failures were the six snapshot modes, before they were re-recorded.
  • tests/installed-turn-surface.test.ts passes locally against the installed CLI.
  • bun run typecheck and bun run build: clean (new export). bun run lint: clean.
  • experiments: the turn-surface live collector refuses every routed arm once the bridge roster passes the 64-entry catalogue bound #3886: not resolved by this change. The live collector builds its routing catalogue from the core server's own listTools (brain.tools) plus the bridge peer (scripts/measure-turn-surface-live.ts:145), and disallowedTools never touches either.
bun run check:pr --base origin/main
{"version":1,"kind":"brain-check-pr-receipt","head":"4e5260d8062768cbf756f402bb6af0588bbcb1c0","base":"origin/main","mode":"focused","startedAt":"2026-11-15T14:37:03.564Z","finishedAt":"2026-11-15T14:38:13.147Z","checks":[{"name":"all lint and leakage gates","categories":["changeset"],"outcome":"passed","elapsedMs":12507.265190999999},{"name":"environment documentation","categories":["changeset"],"outcome":"passed","elapsedMs":104.22086900000068},{"name":"pending changeset package names","categories":["changeset"],"outcome":"passed","elapsedMs":101.05285200000071},{"name":"contribution changeset","categories":["changeset"],"outcome":"passed","elapsedMs":17.019437999999354},{"name":"affected fast invariants","categories":["verify","unit"],"outcome":"passed","elapsedMs":56833.450362}]}

Checklist

  • Focused local preflight/behavioral receipts passed; complete selected hosted proof is required by integration.
  • Acceptance criteria from the issue are all met (no hosted session exposes mcp__brain__brain_apify_*; holds in every configuration; derived roster test with mutation receipt).
  • The PR and backends: hosted Claude turns expose the in-worker Apify tools, which always refuse with ledger_unset #3788 carry the 0.45.0 milestone.
  • A changeset is included (.changeset/3788-in-worker-apify-disallowed.md, @schlessera/brain-backend-claude patch).
  • No personal data anywhere in the diff; Odysseus fixture data only.
  • Nothing in the machine surface moved: host tool names and the standalone MCP surface are unchanged.
  • Docs under docs/ reflect the change (docs/decisions/apify-capability.md, "Front doors and memberships").
  • No fail-closed guard added or changed: this removes an unusable duplicate from the tool list.
  • Provider history stays append-only: the exclusion is unconditional, so every turn of a session carries the same disallowedTools.

Anything left open

Collision check (bun scripts/collisions.ts --json --pr 4021) at head 4e5260d8062768cbf756f402bb6af0588bbcb1c0: no path collisions. The overlaps are closure-only, with #3056, #3059, #3069, #3116, #3437, #3581, #3622, #3806, #4002, #4007, #4008, #4012, #4013, #4016, #4018 and #4020.

The issue's live verification (a real hosted interactive turn with Apify enabled) is covered by the offline installed-CLI stdio check above, not by a paid live turn.

🤖 Generated with Claude Code

A hosted interactive Claude turn loads the brain's .mcp.json, whose core
server registers brain_apify_* unconditionally. A worker holds neither the
token nor the ledger, so every mcp__brain__brain_apify_* call refused with
ledger_unset, under the same names and descriptions as the host's working
mcp__brain-ui__brain_apify_* tools.

IN_WORKER_APIFY_TOOLS, derived from APIFY_TOOL_NAMES, joins
IN_WORKER_COMPUTE_TOOLS in every session's disallowedTools, whatever the
configuration, so the tool list never depends on it. The roster test now
asserts the exclusion in every interactive mode and across autonomous,
hosted, voice and Apify-enabled turns; the SDK options snapshot records
the ten added names and nothing else.

Closes #3788

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@schlessera schlessera added this to the 0.45.0 milestone Nov 15, 2026
@schlessera schlessera added type: fix Something is broken and must behave the way it is documented. area: backends AgentBackend implementations and the seam they share. labels Nov 15, 2026
@schlessera
schlessera marked this pull request as draft November 15, 2026 19:01
@schlessera
schlessera marked this pull request as ready for review November 15, 2026 19:01
@schlessera
schlessera merged commit ed4eb5a into main Nov 15, 2026
48 of 50 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: fix Something is broken and must behave the way it is documented.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

backends: hosted Claude turns expose the in-worker Apify tools, which always refuse with ledger_unset

1 participant