Skip to content

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

Closed

Description

@schlessera

Context

A hosted Claude turn sees two copies of every Apify tool. The copy with the plainer name never works.

  • Interactive hosted turns load the project's .mcp.json, and with it the in-worker brain mcp server. strictMcpConfig is set only for an autonomous envelope (packages/ui-backend-claude/src/sdk-options.ts:399).
  • That server always registers brain_apify_* (registerApifyTools, packages/core/src/mcp-server.ts:703, called at :786), backed by createStandaloneApify, which needs BRAIN_APIFY_LEDGER.
  • The host never passes BRAIN_APIFY_LEDGER or APIFY_TOKEN to a subprocess (HOST_ONLY_SECRET_ENV, packages/ui-sdk/src/server/subprocess-env.ts:34). Every mcp__brain__brain_apify_* call therefore refuses with accounting_unavailable / ledger_unset (packages/core/src/lib/apify/standalone.ts:83).
  • The working copies are the host's mcp__brain-ui__brain_apify_*. Both sets have the same names and descriptions, so the model cannot tell them apart.

Observed on a hosted 0.44.0 install (2026-11-06). Asked what LinkedIn data could be collected, the model called mcp__brain__brain_apify_approvals. It got ledger_unset and told the user Apify was not enabled. The user objected that it was configured. Only then did the model retry mcp__brain-ui__brain_apify_approvals, which worked. The governance record shows the failed call as a roadblock (tool_error, family mcp:brain:brain_apify_approvals).

Compute had the same problem, fixed in #3107/#3108. IN_WORKER_COMPUTE_TOOLS (packages/ui-backend-claude/src/sdk-options.ts:47-53) is disallowed in every session (sdk-options.ts:427), and packages/ui-backend-claude/tests/stable-roster.test.ts:39-41 pins that. Apify was never added next to it.

Scope

  • Add IN_WORKER_APIFY_TOOLS, built from APIFY_TOOL_NAMES with the mcp__brain__ prefix, next to IN_WORKER_COMPUTE_TOOLS. Disallow it in every Claude session, whatever the configuration, as compute is. The tool list must not depend on configuration (provider history).
  • Extend stable-roster.test.ts to assert, in every mode, that every in-worker Apify tool is in disallowedTools.
  • Check the Pi backend for the same exposure. Pi enables the fixed host Apify capability in its session environment (currentCaps, packages/ui-backend-pi/src/session-pool.ts:70-77); inspect the concrete worker registration before claiming the in-worker .mcp.json copies are exposed there. If the in-worker server's copies reach a Pi turn, close that the same way. If not, say so in the PR.

Out of scope

  • Standalone brain mcp / brain apify outside a hosted turn. With BRAIN_APIFY_LEDGER set, the operator's own process must keep working.
  • Giving workers the ledger or the token.
  • Apify policy, approvals or pricing.

Acceptance criteria

  • No hosted session's tool list exposes mcp__brain__brain_apify_*. The mcp__brain-ui__brain_apify_* tools are unaffected.
  • The exclusion holds whatever the host configures: Apify enabled or disabled; interactive, autonomous or voice.
  • A roster test derived from APIFY_TOOL_NAMES fails if a new Apify operation is added without being excluded. Mutation receipt: drop one name from the list and the test fails.

Verification

  • bun run test packages/ui-backend-claude/tests/stable-roster.test.ts
  • A hosted interactive turn with Apify enabled lists only the mcp__brain-ui__ Apify tools.

Contract impact

None. This removes an unusable duplicate from the hosted tool list. Host tool names and the standalone MCP surface are unchanged.

Bounded reproduction — 2026-11-09

Inspected source: 9c7eb25825fdad5f4485db0df472188805edb450; Bun 1.4.4 (38afee6c8), frozen lockfile, isolated temporary checkout, repository test wrapper and offline preload. Command: bun run test ./tmp/triage/apify-roster.test.ts. A temporary keyless fixture assembled the real createClaudeSdkTurn for a hosted governed session, derived the ten mcp__brain__brain_apify_* names from APIFY_TOOL_NAMES, and checked disallowedTools. All ten were absent; IN_WORKER_APIFY_EXCLUDED failed expecting an empty missing-name list. This establishes the missing exclusion in assembled options; it does not claim a paid Apify call or a live Claude tool-list observation. The fixture failed at the named behavioral assertion, after module loading succeeded. Temporary diagnostic fixtures are outside authored source; this triage changes no product code.

Triage 2026-11-09 at main 9c7eb25825fdad5f4485db0df472188805edb450: Recorded the bounded intended-assertion failure and clarified current source/verification. The existing p1 and 0.45.0 commitment are preserved. It remains standalone: the GitHub-tools epic does not own this backend correction, and no existing open epic owns its full deliverable.

Activity

  1. added
    type: fix
    area: backends
    priority: p1
    on Nov 9, 2026
  2. added this to the 0.45.0 milestone on Nov 9, 2026
  3. added
    agent-ready
    on Nov 9, 2026
  4. self-assigned this
    on Nov 15, 2026
  5. schlessera commented on Nov 15, 2026

    @schlessera
    OwnerAuthor

    Claimed for implementation. Claim token: claim-116b0db1. Branch: fix/3788-exclude-in-worker-apify.

    collisions: closure-only overlaps with open drafts, no path collision

  6. schlessera commented on Nov 15, 2026

    @schlessera
    OwnerAuthor

    Merged in #4021 as ed4eb5a0ccc319e481882d8d8368bd1968d1c262 (candidate run 43750083047 passed; the main run on the squash is in progress).

    • IN_WORKER_APIFY_TOOLS, built from APIFY_TOOL_NAMES, is disallowed in every Claude session next to IN_WORKER_COMPUTE_TOOLS. The host's mcp__brain-ui__brain_apify_* tools and standalone brain mcp are unchanged.
    • stable-roster.test.ts asserts the exclusion in every interactive mode, plus a 16-case matrix (interactive or autonomous × hosted or unhosted × Apify enabled or disabled × typed or voice). Failing first: 17 failures on IN_WORKER_APIFY_DISALLOWED*. Mutation (dropping brain_apify_revoke): the same 17 fail and name the dropped tool.
    • Installed-CLI check: with core served over stdio as .mcp.json does, the copies disappear from the deferred listing and ToolSearch after the change. They are listed and loadable on the base.
    • Pi is not exposed: it has no MCP client, and its brain_apify_* tools are host bridge tools.
    • experiments: the turn-surface live collector refuses every routed arm once the bridge roster passes the 64-entry catalogue bound #3886 is not resolved by this change: the live collector's catalogue comes from the core server's own tool listing, which disallowedTools does not filter.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

agent-readyarea: backendspriority: p1type: fix

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions