Skip to content

refactor(sandbox): extract harness-runner subprocess from daemon dispatch - #4428

Closed
pedrofrxncx wants to merge 1 commit into
mainfrom
wt/harness-runner-extraction
Closed

pedrofrxncx wants to merge 1 commit into
mainfrom
wt/harness-runner-extraction

Conversation

@pedrofrxncx

@pedrofrxncx pedrofrxncx commented Jul 10, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Step 1 of the sandbox daemon Go rewrite rollout (see docs-design/sandbox-daemon-go-rewrite.md §3, §6): extracts claude-code/codex harness execution out of the daemon process into a supervised harness-runner subprocess, while the daemon stays TypeScript. Isolates the riskiest seam (agent-loop execution) before the language changes.
  • Single-bundle, dual-role design: entry.ts is now a tiny mode router — HARNESS_RUNNER_MODE=1 runs the harness-runner, default runs the daemon (daemon-entry.ts, git-moved). Keeps one build artifact, since the daemon bundle is consumed as a single unit in three places (embedded in the mesh server, Docker image, desktop bundle).
  • Transport: loopback HTTP + NDJSON. The runner binds 127.0.0.1:0, announces readiness on stdout, and serves POST /run (per-spawn bearer token) streaming one DispatchSSEEvent per line, terminated by {"type":"done"}.
  • routes/dispatch.ts is byte-for-byte untouched — auth, tombstones/410, SSRF allowlist, run registry, SSE-200-immediately, and closed-controller guards all stay in the daemon. All client-facing SSE framing is still produced daemon-side.
  • Supervision: spawn-on-first-dispatch, single shared process, 30s ready timeout, no auto-respawn (a crash costs each in-flight run one harness_crashed+done; the next dispatch respawns — no re-dispatch storm). Killed on daemon shutdown (SIGTERM) and process exit (SIGKILL); a stdin-pipe watchdog in the runner covers daemon SIGKILL orphaning.

Test plan

  • daemon.dispatch.e2e.test.ts (existing, unchanged) — 8 pass
  • daemon.e2e.test.ts — 103 pass
  • daemon.git.e2e.test.ts — 15 pass
  • daemon.proxy.e2e.test.ts — 7 pass
  • New daemon.harness-runner.e2e.test.ts (fixture runner injected via new HARNESS_RUNNER_CMD env) — 6 pass: verbatim chunk relay + done framing, error propagation, mid-stream runner death → harness_crashed+done, recovery on next dispatch, SIGKILL-orphan reaping
  • Real end-to-end: dispatched claude-code against the built bundle — harness ran in the subprocess, chunks relayed as SSE ending in done; SIGTERM to the daemon killed the runner within 2s
  • Full package suite (675 pass), workspace bun run check and bun run fmt clean, lint 0 errors
  • Rebased onto latest main; all suites re-verified green post-rebase

Note

The daemon bundle still contains harness code (single artifact by design for this step) — splitting it into a separate artifact is a natural byproduct once the Go daemon ships and this runner becomes the only TS left in the image.


Summary by cubic

Extracted harness execution from the daemon into a supervised harness-runner subprocess to isolate the agent loop while keeping the /dispatch API and SSE behavior unchanged.

  • Refactors

    • Added harness-runner: a loopback HTTP server that streams NDJSON DispatchSSEEvent lines from POST /run and ends with {"type":"done"} (per-spawn bearer token).
    • Single bundle, dual role: entry.ts routes modes; HARNESS_RUNNER_MODE=1 runs the runner, otherwise the daemon via daemon-entry.ts.
    • Transport and client contract unchanged: routes/dispatch.ts stays the same; auth, allowlists, run registry, and SSE framing remain daemon-side.
    • Supervision: spawn on first dispatch, one shared process, 30s ready timeout, no auto-respawn; runner is killed on daemon shutdown and via stdin watchdog.
    • Added a minimal runner client and e2e seam to validate relay, error propagation, crash handling, and orphan cleanup.
  • Migration

    • No client changes required; SSE output is identical.
    • Build and distribution stay single-artifact (server, Docker, desktop).
    • New envs: HARNESS_RUNNER_MODE (internal), HARNESS_RUNNER_CMD (tests/override).

Written for commit b8de4a6. Summary will update on new commits.

Review in cubic

@pedrofrxncx

Copy link
Copy Markdown
Collaborator Author

Closing as stale: this PR sat past the bot's 48h merge window, main has moved on, and its CI results no longer reflect the current base. This is a housekeeping close, not a rejection of the change — if the underlying problem still exists, the bot will find it again and open a fresh, rebased PR.

[studio-bot:stale-close]

@pedrofrxncx
pedrofrxncx deleted the wt/harness-runner-extraction branch August 31, 2026 17:41
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