Skip to content

Cheaper run responses, safe globs for readers, shell-analysis bypass fixes, paired benchmark - #8

Draft
mths-mcfs wants to merge 18 commits into
feat/integrationfrom
feat/economia
Draft

mths-mcfs wants to merge 18 commits into
feat/integrationfrom
feat/economia

Conversation

@mths-mcfs

@mths-mcfs mths-mcfs commented Nov 16, 2026 •

Copy link
Copy Markdown
Owner

Makes run cheaper per task and closes three shell-analysis bypasses found while doing it. Base: feat/integration (#7).

Why

On 2026-11-16 the benchmark had agent-code-mode costing more than Claude Code's native tools in 7 of 8 tasks. Almost all of the gap was cache writes, coming from what each run response sent back: the full call log, the full diff and absolute paths.

What changes

  • Smaller run responses
    • Calls come back as counts per tool. Denied and failed calls are always listed in full.
    • A large diff becomes a diffStat of at most 10 files.
    • Each response is capped at 10k tokens. Whatever is cut (the diff, or output past the cap) is kept in memory for the server session and read back with a new binding, readOverflow(id). The response never names a path in the state directory.
    • grep() returns {columns, rows}, and a long string result comes as a second plain-text block.
    • Result paths are relative to the canonical cwd. Hooks and rules still get absolute paths.
  • Tool description: only the binding signatures; the server instructions are gone.
  • Glob for pure readers. cat, head, tail, wc and ls with a relative glob, using a known option set, no longer get denied:
    • The glob is expanded at prepare time.
    • Every match is resolved and checked against the working directories and the Read rules.
    • The matches are written into the command as a quoted literal list, so hooks see exactly what runs.
    • Each file's identity is checked again right before the process starts.
    • $(...), variables, redirection, -R and rg stay as before.
  • Shell-analysis bypasses. All three are already in Codex host adapter: exec policy rules, hooks, session context #5, Claude Code host adapter: permissions, hooks, session context #6 and Integrate sandbox, tools and host adapters; install, README, e2e and attack suites #7. Each now has a test that uses bash itself as the oracle, plus an attack test that fails on the parent commit:
    • Claude: cat {/outside/file,x} read a file outside the workspace under Bash(cat:*).
    • Claude: with echo é; rm -rf x, the multi-byte text hid rm from a deny rule, because words were sliced by UTF-16 index from byte offsets.
    • Codex: {rm,-f,x} and $"rm" got past a forbidden rule.
  • Benchmark
    • Arms of one host run back to back per task, with the order rotated each round.
    • Every arm gets the same warm-up run, kept out of the numbers.
    • A B0/C0 arm runs another build (--acm-ref, --acm-dist) in the same matrix.
    • The report adds real request counts, pass^k, cost per solved task and paired bootstrap 95% CIs.
    • T9–T12 are new tasks with hidden tests.
    • Run workspaces live outside the repository, so an agent cannot read the hidden tests.

Verification

  • npm run verify: 841 passed, 1 skipped.
  • Attack tests for each bypass fail on the parent commit and pass here.
  • Fixed after a correctness review of this branch (each found by reproduction):
    • ''a=~/x (Claude) and a+=~ (Codex) tilde bypasses;
    • the output cap dropping denied and failed calls;
    • the glob-listing bash inheriting BASH_FUNC_* and SHELLOPTS/PS4, which ran code during prepare.
  • Paired benchmark. Claude Sonnet 5.5, T1–T12, 3 runs, warm-up on every arm, seed 773178349. 108 valid runs, all passed. Arms: A native, B0 = c63b362 (this PR's base), B = 3454a9d. Median USD per run:
T1 T2 T3 T4 T5 T6 T7 T8 T9 T10 T11 T12
A .0051 .0179 .0060 .0118 .0194 .0200 .0246 .0603 .0253 .0411 .0348 .0193
B0 .0063 .0240 .0078 .0534 .0355 .1281 .0268 .0272 .0783 .0654 .0429 .0191
B .0044 .0201 .0052 .0151 .0208 .0229 .0286 .0149 .0226 .0381 .0314 .0155

Mean difference per run, paired cluster bootstrap, 95% CI:

  • B vs B0: −$0.0208 [−0.0373, −0.0082]. This change is cheaper.
  • B vs A: −$0.0037 [−0.0116, +0.0011]. B is cheaper in 7 of 12 tasks, but the interval crosses zero.

The B arm measured 3454a9d. Later commits only change shell analysis and the output cap's over-limit path.

Bench tasks T13–T15, hybrid arm, serve --hybrid (0e8089d)

  • New hidden-test tasks: T13 (two bugs at the seam of an async job queue), T14 (streaming CSV parser) and T15 (migrate 36 modules to a new HTTP API, with look-alikes that must not change).
  • Claude arm C (hybrid): native tools and run side by side. serve --hybrid adds one line to the run description saying when to batch with run and when a native tool is enough. Without the flag the description is unchanged byte for byte. install --host claude now emits --hybrid, because Claude Code keeps its native tools next to run.
  • Results. Opus 5.5 medium, 3 runs per arm, all runs valid and passed. Median USD per run, A / B / C:
    • T15 (long): $0.565 / $0.456 / $0.471. C chose run for 10 of its 13 calls.
    • Short tasks (T2/T13/T14): C chose native tools for 32 of 36 calls. C−A was −$0.008/run, CI [−0.020, +0.004].
    • Takeaway: C stayed close to the cheapest arm on both short and long tasks.

Known limits

  • The benchmark still saturates. Haiku passed T9–T12 in 25 of 25 runs on the native arm, so it measures cost, not quality.
  • A short race window remains between the identity check and the reader's open. Native Claude Code does not check at all.

🤖 Generated with Claude Code

mths-mcfs and others added 18 commits November 16, 2026 04:58
Prototype from the 2026-11-16 cost analysis: the run response reports call
counts and keeps every denied or failed call, clips large diffs, and returns
paths relative to the working directory; read() returns the file text
exactly; the binding docs move from server instructions to the tool
description. verbose: true returns the full call log and diff.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…lts, output cap

Denied calls, errors and changed files are always listed whole. A large
diff becomes a diffStat of at most 10 files; anything cut from the response
(diff or output above the 10k-token cap) is kept in memory for this server
session and read back with readOverflow(id), so no state-dir path leaks and
nothing accumulates on disk. grep() returns {columns, rows}; a long string
result comes as a second plain-text block. Result paths use the canonical
cwd, and names such as ..env stay relative. The tool description keeps only
the binding signatures.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… bootstrap CIs, harder tasks

Arms of one host run back to back per task with the order rotated each
round; every arm gets the same warm-up run, kept out of the numbers. A B0/C0
arm runs another agent-code-mode build (--acm-ref or --acm-dist) in the same
matrix. The report adds real request counts, pass@1 and pass^k, cost per
solved task and paired cluster-bootstrap 95% CIs. T9-T12 add multi-file,
contract-preserving and edge-case tasks with hidden tests. Run workspaces
now live outside the repository so agents cannot read hidden tests or
solutions.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…byte bypasses

cat/head/tail/wc/ls with a relative glob and a known option set have the
glob expanded at prepare time: every match is resolved inside the working
directories, checked against Read deny/ask rules, written into the command
as a quoted literal list after --, and its identity (dev, ino, type) is
checked again right before spawn. Hooks and rules see the command that runs.

Fixes in the shell analysis, each with a bash-oracle test and an attack test:
- Claude: brace expansion ({/outside,x}) let an allowed reader open a file
  outside the workspace; brace, ~user, shopt and bash -O now make the command
  uncertain.
- Claude: words were sliced by UTF-16 index from byte offsets, so text such
  as 'echo é; rm -rf x' hid rm from a deny rule; slicing is now by byte.
- Codex: {rm,-f,x} and $"rm" escaped a forbidden rule; words bash rewrites
  are marked inexact and a rule that may match them asks (denied).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… bench tests

- Glob matches and their order now come from the same bash and environment
  that run the command (locale, GLOBIGNORE, BASHOPTS), started without
  startup files or BASH_ENV; the byte-order JS matcher assumed LC_ALL=C and
  disagreed with bash under UTF-8 locales. Expansion stays off on Windows.
  The oracle test runs under C, C.UTF-8, en_US.UTF-8 and pt_BR.UTF-8.
- memory-tool-runtime D5 compared paths built from an unresolved tmpdir.
- bench: pick the run record by its warmup flag instead of readdir order;
  run npm through node's npm-cli.js and use a junction on Windows; give the
  verifier cleanup hook room on Windows.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…put cap

- Claude and Codex shell analysis: empty quotes left no mark, so ''a=~/x
  looked like an assignment and a tilde bash keeps literal was expanded
  (a Read-denied file was readable); NAME+= and NAME[i]= are assignments to
  bash too (a Codex forbidden rule was bypassed with a+=~). Tilde positions
  now follow bash, with a bash-oracle property test in both analyzers and
  attack tests.
- Output cap: denied calls and errors were cut by entry count. When they do
  not fit whole they now come grouped by (tool, reason) with exact counts,
  then with reasons clipped to 200 chars, and only then with a counted
  marker; the full list stays in the overflow.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…and test

The bash that lists glob matches during prepare inherited the server
environment minus BASH_ENV/ENV, so an exported function (BASH_FUNC_shopt%%)
or SHELLOPTS=xtrace with a command substitution in PS4 ran code before the
call was authorized. It now gets only the locale variables and GLOBIGNORE,
with glob options from BASHOPTS applied as explicit 'builtin shopt -s', and
uses builtin shopt/printf. When the environment would change the result in
a way this cannot reproduce (compat*, unknown options, noglob, posix,
GLOBSORT, BASH_COMPAT, POSIXLY_CORRECT, LOCPATH) the glob is not expanded.
The expand test no longer creates b.js and B.js on case-insensitive file
systems.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…hen BASH_ENV is set

- Read BASH_VERSINFO from the commit bash with an empty environment and only
  apply what that version reads from the environment (BASHOPTS since 4.1,
  BASH_COMPAT since 4.3, GLOBSORT since 5.3); bash 3.2 on macOS ignores
  BASHOPTS, so applying dotglob from it handed readers hidden files the
  written command would not read. Unknown version: no expansion.
- Resolve the literal directory prefix of a pattern inside the jail before
  bash lists it, and do not expand when a glob sits before the last '/';
  bash otherwise followed directory symlinks out of the workspace while
  listing. Refusals no longer name anything outside the workspace.
- Do not expand when BASH_ENV is set: the commit bash would read it and it
  can change glob options.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nstall for Claude

- T13 (two bugs at the seam of an async job queue), T14 (streaming CSV parser)
  and T15 (migrate 36 modules to a new HTTP API, with look-alikes that must
  not change), all graded by hidden tests; checkScope can allow named deletions.
- Claude arm C: native file/shell tools and `run` side by side, with its own
  tool surface check and parser fixture.
- `serve --hybrid` appends one line to the run description saying when to
  batch with run and when a native tool is enough; without the flag the
  description is unchanged. `install --host claude` now emits it, since
  Claude Code keeps its native tools next to run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…-test leak check room on slow runners

The Windows runner checked the task fixtures out with CRLF, so the verifier
tests did not find their exact snippets and a CRLF test hook broke bash.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Every case builds git workspaces and runs node --test on them, which went past
the 20 s default on the Windows runner (verifier T3 timed out on b8ee1a6).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The callers, shims and mapping-rule cases of T15 were the longest
verifier file; each part now runs in its own process.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Same reason as the dry runs: they drive main() end to end and compete
for the CPU with the other test files on Windows.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant