Skip to content

fix: a turn whose tool server never started fails and says why - #69

Merged
blockmandev merged 1 commit into
mainfrom
fix/tool-bridge-under-sbx
Oct 24, 2026
Merged

blockmandev merged 1 commit into
mainfrom
fix/tool-bridge-under-sbx

Conversation

@blockmandev

Copy link
Copy Markdown
Member

Fixes #68.

Root cause (measured, Windows 11, sbx native, network allow)

sbx's write-restricted token runs the command as your own user. A named pipe created with default security grants write only to SYSTEM, Administrators and the creating user:

D:(A;;FR;;;WD)(A;;FR;;;AN)(A;;FA;;;SY)(A;;FA;;;BA)(A;;FA;;;<user>)

The restricting SIDs (run SID, Everyone, logon) are never granted write, so every write-open of such a pipe is refused.

Node creates exactly such pipes for a child's stdio:

  • Node: under sbx, child_process.spawn with stdio: 'pipe' fails with EPERM; 'ignore' and 'inherit' work.
  • Claude Code therefore starts no MCP server. Its init line says {"name":"incode","status":"failed"}, the model runs with none of incode's tools, and it writes tool calls out as text.
  • incode reported that as is_error: false, or the turn ran on to the wall clock.

The step-by-step probes are on #68: plain vs CLAUDE_CONFIG_DIR only vs sbx, a bare Node spawn per stdio mode, and the pipe SDDL.

Lifting the sandbox limit itself is sbx work, the same direction as #38. This PR makes incode stop calling such a turn a result.

Change

  • Init line: an init line naming incode's server failed now ends the turn at once, with the reason.
  • End of turn: a turn that produced a result without the tool server ever asking for the tools is refused.
  • Cleanup: the Claude route kills the CLI's process tree on any error, not only on cancel. That's what its comment promised and what the codex route already does.
  • Trace: the tool server traces its start, a failed start and a failed connect, so INCODE_TRACE names which half broke.
  • Codex: the codex route is not held to the list check yet, because whether codex always lists before the model runs is unmeasured (codex through incode's tools: verify with a real login, then make it the default #19).

Verified

  • Live, same task:
    • Plain: still correct (marker-91c2, 11 s).
    • Under sbx: now is_error: true in 35 s with the reason. Before: fake success, or a kill at the wall after 281 s.
  • New tests: a toolless turn; a reported server failure, stopped in under 5 s, with the CLI not left running (Unix); the init-line reader; run_bridged directly.
  • Each new check fails with its fix taken out. The exception is the kill check on Windows, where the job object ends the CLI on drop anyway (noted in the test).
  • Fakes and CI: the stand-in CLIs now ask for the tools as a real one does. The bridged codex flow test now also runs on Windows.
  • Local gate: fmt and clippy -D warnings clean; 2340 lib + 59 bin tests passed.

…68)

Root cause, measured on Windows 11 under sbx (native, network allow):
sbx's write-restricted token runs the command as the user, and a named pipe
created with default security grants write only to SYSTEM, Administrators
and the creating user, not to the token's restricting SIDs. Node creates
such pipes for a child's piped stdio, so `child_process.spawn` with
stdio 'pipe' fails with EPERM ('ignore' and 'inherit' work). Claude Code
therefore starts no MCP server: its init line reports incode's server as
"failed", the model runs with none of incode's tools, writes tool calls out
as plain text that nothing runs, and incode reported the turn as success
(or it ran on until the wall clock).

That sandbox limit is sbx's to lift (the #38 design). This change makes
incode stop treating such a turn as a result:

- tool_bridge: the bridge records when the tool server asks, with the
  turn's token, for the tools (`Bridge::tools_listed`); `require_tools`
  and `no_tools` give the one refusal; the server half now traces its
  start, a failed start and a failed connect, and the parent traces the
  list request, so INCODE_TRACE names which half broke.
- Claude route: an init line naming incode's server "failed" ends the turn
  at once; a turn that produced a result without the list request is
  refused at the end. `finish` now kills the CLI's tree on any error, not
  only on cancel, as the codex route does, so a stopped turn leaves
  nothing running.
- `drive`'s line handler may end the turn with an error (`LineHandler`).
- The codex route is not held to the list check: whether codex always
  lists before the model runs is not yet measured (#19).

Tests: the stand-in CLIs now ask for the tools as a real one does; new
tests for a toolless turn, a reported server failure (stopped within 5 s,
and on Unix the CLI no longer running), the init-line reader, and
run_bridged directly. The bridged codex flow test now runs on Windows too.
Each new check fails with its fix taken out.
@blockmandev
blockmandev merged commit 2ac5369 into main Oct 24, 2026
12 checks passed
@blockmandev
blockmandev deleted the fix/tool-bridge-under-sbx branch October 24, 2026 16:09
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.

Under sbx on Windows, incode's tool server never reaches the parent, and the toolless run is reported as success

1 participant