openclaw/docs/tools/code-mode
Peter Steinberger c610d6c85c
fix(code-mode): exec backgrounds after 1 s and forces extra poll turns (#160841)
* fix(code-mode): use remaining exec budget before backgrounding

Implicit bridged exec calls yielded after at most one second, forcing later
model turns to collect short shell commands. An observed 36-turn run spent
11 turns polling commands that took 1-8 seconds, with each poll adding a
3-5 second model round trip.

Use max(1, floor(remainingMs) - 250) for exec calls without yieldMs or
background:true. Share the resume margin with the existing execution floor:
a fresh 10-second call yields at 9750 ms, and 400 ms remaining yields at
150 ms. Explicit options and the resume-floor behavior stay unchanged.
Document inline completion and remove the 1-second-yield example.

Validation (wall times):
- node scripts/run-vitest.mjs src/agents/code-mode.bridge.test.ts --maxWorkers=1
  22 passed; 227.56 s. Before the production fix, the same updated tests
  failed only on 1000 vs 9750 and 100 vs 150 (20 passed, 2 failed; 196.08 s).
- node scripts/run-vitest.mjs src/agents/code-mode.bridge.host-denial.test.ts --maxWorkers=1
  35 passed; 129.84 s.
- pnpm changed:lanes --json
  Selected core, coreTests, docs; 6.23 s.
- node_modules/.bin/oxfmt --check src/agents/code-mode-bridge.ts src/agents/code-mode-execution.ts src/agents/code-mode-runtime.ts src/agents/code-mode.bridge.test.ts docs/tools/code-mode/tool-surface.md docs/gateway/background-process.md
  All six files passed; 1.66 s.
- node scripts/run-oxlint.mjs --tsconfig config/tsconfig/oxlint.core.json src/agents/code-mode-bridge.ts src/agents/code-mode-execution.ts src/agents/code-mode-runtime.ts src/agents/code-mode.bridge.test.ts
  Passed without diagnostics; 32.83 s.
- node scripts/run-tsgo.mjs -p tsconfig.core.json --incremental --tsBuildInfoFile .artifacts/tsgo-cache/core.tsbuildinfo
  Passed; 22.13 s.
- node scripts/run-tsgo-core-test-shards.mjs --changed-paths-json '["src/agents/code-mode.bridge.test.ts"]'
  agents-tools passed; 119.20 s including selection, 16.8 s compiler lane.
- node scripts/check-docs-mdx.mjs docs/tools/code-mode/tool-surface.md docs/gateway/background-process.md
  Two files passed; 0.92 s.
- git diff --check
  Passed; 1.40 s.
- Codex autoreview: one round, scoped-clean through P2; 294.13 s.

The initial baseline could not collect tests because installed TypeScript
was older than the lockfile. pnpm install --frozen-lockfile restored the
locked dependencies without tracked dependency changes. Agent-loop has no
yield-value assertions, so it was not run. Full check-changed, broad guards,
live services, and CI were intentionally not run for this scoped work.

* fix(code-mode): keep settlement slack above the guest resume floor

Reserving exactly the minimum 250 ms resume budget left no allowance for
dispatch and result settlement. A command running to its yield could leave
too little time to resume, park the snapshot, and require another wait.

Keep the resume floor unchanged and derive a 500 ms exec yield margin as
twice that floor. Implicit exec now yields at 9500 ms for a fresh 10-second
budget and requests 1 ms when 400 ms remain. Explicit yieldMs and background
options stay unchanged. This preserves the intended inline completion
improvement for the observed run that spent 11 of 36 turns polling commands.

Include the already-reviewed exec docs example using background:true and
a bounded 30000 ms process poll, without rewriting that supplied edit.

Validation (wall times):
- node scripts/run-vitest.mjs src/agents/code-mode.bridge.test.ts --maxWorkers=1
  22 passed; 58.77 s; peak RSS 7041138688 bytes.
- node_modules/.bin/oxfmt --check src/agents/code-mode-bridge.ts src/agents/code-mode-runtime.ts src/agents/code-mode.bridge.test.ts docs/tools/exec.md docs/tools/code-mode/tool-surface.md
  All five files passed; 0.61 s.
- node scripts/run-oxlint.mjs --tsconfig config/tsconfig/oxlint.core.json src/agents/code-mode-bridge.ts src/agents/code-mode-runtime.ts src/agents/code-mode.bridge.test.ts
  Passed without diagnostics; 19.44 s.
- node scripts/run-tsgo.mjs -p tsconfig.core.json --incremental --tsBuildInfoFile .artifacts/tsgo-cache/core.tsbuildinfo
  Passed; 13.39 s.
- node scripts/check-docs-mdx.mjs docs/tools/exec.md docs/tools/code-mode/tool-surface.md
  Two files passed; 0.97 s.
- git diff --check
  Passed; 0.50 s. Staged diff check also passed.
- Codex autoreview through P2: two rounds. The first reported the old
  INDEX-only calculation, already fixed in the working tree (126.84 s).
  Staging the intended candidate resolved it; the second was scoped-clean
  with no actionable findings (111.73 s).

No live timing remeasurement, broad suites, full check-changed, or CI run.
2026-09-28 18:55:27 -07:00
..
configuration.md fix(anthropic): finish Opus 5.5 defaults and thinking display (#156093) 2026-09-22 23:59:18 -07:00
executors.md
guest-api.md fix(code-mode): nested tool errors lose their message when details only flag the error (#159359) 2026-09-26 22:11:08 -07:00
internals.md perf(code-mode): reuse warm workers across limits and bursts (#156800) 2026-09-24 00:35:41 +00:00
maintainers.md fix(agents): preserve tool authority through hook rebuilds (#159532) 2026-09-27 02:18:55 -07:00
output.md
quickstart.md
tool-surface.md fix(code-mode): exec backgrounds after 1 s and forces extra poll turns (#160841) 2026-09-28 18:55:27 -07:00
troubleshooting.md fix: distinguish Code Mode guest errors after tool calls (#160217) 2026-09-28 12:07:09 -04:00