Skip to content

agent: rewrite on Void; container driven through ctx.container - #10

Merged
ryuzdev merged 3 commits into
mainfrom
agent-void-sandboxes
Nov 2, 2026
Merged

ryuzdev merged 3 commits into
mainfrom
agent-void-sandboxes

Conversation

@ryuzdev

@ryuzdev ryuzdev commented Nov 2, 2026 •

Copy link
Copy Markdown
Member

The agent template is rewritten on stock Void (owner request: "refactor agent template and make sure it uses Void Sandboxes").

Shape

  • Void app. Routes under routes/ (GET /, POST /sandboxes/:name/{repository,task}, GET /sandboxes/:name, GET /sandboxes/:name/diff), with JSON 404/405 middleware.
  • Agent state lives in durable-objects/agent.ts (defineDurableState). One setAlarm alarm runs the clone, harness and container pumps, Pi Durable runs over the object's SQLite storage, and both runtimes and recovery are kept.
  • Container. durable-objects/container.ts is a plain Durable Object (defineDurableObject) that drives ctx.container directly. It is declared through void.config.ts → cloudflare.containers with image: sandbox/Dockerfile. That Dockerfile has no RUN, so the Noite runner builds it after checking it and pinning its base images by digest.
  • Settings env is baked into worker.vars at build time. There is no env.ts, and secrets are omitted when unset.
  • Removed: wrangler.jsonc, scripts/build.ts, src/index.ts, src/agent.ts, the sandbox-shim.

Why not void/sandbox yet

On celld 0.6.3, Noite's runtime, void/sandbox fails three ways (lab evidence in ryuzcorp/noite#127):

  1. ctx.container.images is missing.
  2. An exec right after start() gets 404.
  3. RPC stubs and streams cannot cross isolates, and the Sandbox SDK returns every process as a stub plus streams.

So the container DO exchanges only plain data (ArrayBuffers included). It retries only the post-start 404, for at most 90 s. The README says Void Sandboxes replace it once celld supports cross-isolate RPC.

Needs

ryuzcorp/noite#127: it deploys Void's own dist/ssr/wrangler.json and builds RUN-free Dockerfile images. Merge this PR after that one; it ships in the next Noite alpha.

Verification

  • bun run check in templates/agent: typecheck, oxlint, build, and 115 tests pass.
  • Lab, on Noite #127's runner with stock celld 0.6.3:
    • Worker runtime: the clone reaches ready, a faux task runs exec, and the diff answers 200.
    • Container runtime: the same flow passes, the task going through the bash tool.
    • A request without the token gets 401.
    • After the sandbox containers were deleted (docker rm -f), the next task recovered and finished done.

Summary by CodeRabbit

  • New Features
    • Added a web interface for managing sandboxes, cloning or refreshing repositories, submitting tasks, viewing status, and retrieving diffs.
    • Added API endpoints for sandbox state, repository operations, task submission, and Git diffs, with clear JSON error responses.
    • Added worker- and container-based task execution, including durable task progress and repository state.
  • Documentation
    • Updated setup, development, deployment, and container guidance for the new application workflow.

Stock Void app (void 1.5 on Vite 8): file routes with defineHandler,
per-sandbox state in defineDurableState with a single setAlarm-driven
alarm hook, and Void Sandboxes (void/sandbox) instead of
@cloudflare/sandbox directly.

- routes/ for GET /, repository/task POSTs, state and diff GETs; JSON
  errors incl. a 404/405 middleware rewrite; AGENT_TOKEN Bearer [REDACTED]
- durable-objects/agent.ts ports the Pi Durable harness (SQLite storage,
  worker + container runtimes, brokered model calls, recovery)
- sandbox/Dockerfile stays RUN-free with the shim pinned to bun.lock
  (test/dockerfile.test.ts fails on drift); the agent server bundle is
  COPYed into the image and started with node
- worker.vars in void.config.ts bake Settings env at build time; no
  env.ts, no celld-config plugin, no dist/wrangler.json
- adapters (tools/clone-deps/server-client) take injected sandbox
  clients; tests drive every seam with fakes (109 pass)
celld 0.6.3 cannot pass RPC stubs or streams across isolate boundaries,
and Void's sandbox client returns both, so every sandbox call failed.
Keep Void (routes, defineDurableState, baked vars, RUN-free image) but
replace void/sandbox with a native container Durable Object that owns
the ctx.container handle: exec runs to completion in-isolate and
returns plain data, container HTTP crosses via stub.fetch().

- durable-objects/container.ts: AgentContainer (defineDurableObject)
  with plain-data exec/execDetached and a /<port>/... fetch proxy;
  bounded retry of the post-start 404 race, per-exec kill deadlines
- src/container-adapter.ts: sandbox client over the container stub
  (stat/readFile/writeFile composed from exec); timeouts cross as ms
- agent.ts, tools.ts, clone-deps.ts, server-client.ts: off
  void/sandbox, AbortSignal -> timeoutMs
- void.config.ts: plain containers[] entry (image names the
  Dockerfile); no sandbox: section
- sandbox/Dockerfile: drop the sandbox-shim (nothing consumes it),
  EXPOSE the agent server port
- tests: new container-adapter coverage, exact-timeout assertions,
  Dockerfile shape without the shim pin
@coderabbitai

coderabbitai Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 34 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c6795b06-4ce6-454e-a112-4f5848b8eabd
Commits

Reviewing files that changed from the base of the PR and between 6d41711 and e3ef4e9.

Files selected for processing: 17
  • templates/agent/.gitignore
  • templates/agent/README.md
  • templates/agent/durable-objects/agent.ts
  • templates/agent/durable-objects/container.ts
  • templates/agent/routes/sandboxes/[name]/diff.ts
  • templates/agent/src/clone-deps.ts
  • templates/agent/src/container-adapter.ts
  • templates/agent/src/container-pump.ts
  • templates/agent/src/diff-read.ts
  • templates/agent/src/page.ts
  • templates/agent/src/repo-clone.ts
  • templates/agent/src/task-queue.ts
  • templates/agent/test/clone-deps.test.ts
  • templates/agent/test/container-adapter.test.ts
  • templates/agent/test/container-pump.test.ts
  • templates/agent/test/diff-read.test.ts
  • templates/agent/test/task-queue.test.ts
Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: a4e0eaef-42d0-4323-8f66-dc02cacf26b1
Commits

Reviewing files that changed from the base of the PR and between bcb41ba and 6d41711.

Files ignored due to path filters: 1
  • templates/agent/bun.lock is excluded by !**/*.lock
Files selected for processing: 46
  • templates/agent/.dev.vars.example
  • templates/agent/.gitignore
  • templates/agent/.oxlintrc.json
  • templates/agent/AGENTS.md
  • templates/agent/README.md
  • templates/agent/durable-objects/agent.ts
  • templates/agent/durable-objects/container.ts
  • templates/agent/middleware/01.json-errors.ts
  • templates/agent/package.json
  • templates/agent/routes/index.ts
  • templates/agent/routes/sandboxes/[name].ts
  • templates/agent/routes/sandboxes/[name]/diff.ts
  • templates/agent/routes/sandboxes/[name]/repository.ts
  • templates/agent/routes/sandboxes/[name]/task.ts
  • templates/agent/routes/sandboxes/_shared.ts
  • templates/agent/sandbox/Dockerfile
  • templates/agent/scripts/build-agent-server.ts
  • templates/agent/scripts/build.ts
  • templates/agent/src/agent.ts
  • templates/agent/src/clone-deps.ts
  • templates/agent/src/container-adapter.ts
  • templates/agent/src/container-pump.ts
  • templates/agent/src/container/agent-server.ts
  • templates/agent/src/container/embedded.ts
  • templates/agent/src/env.ts
  • templates/agent/src/errors.ts
  • templates/agent/src/index.ts
  • templates/agent/src/page.ts
  • templates/agent/src/protocol.ts
  • templates/agent/src/repo-clone.ts
  • templates/agent/src/sandbox-name.ts
  • templates/agent/src/server-client.ts
  • templates/agent/src/tools.ts
  • templates/agent/test/build.test.ts
  • templates/agent/test/clone-deps.test.ts
  • templates/agent/test/container-adapter.test.ts
  • templates/agent/test/container-pump.test.ts
  • templates/agent/test/dockerfile.test.ts
  • templates/agent/test/sandbox-name.test.ts
  • templates/agent/test/server-client.test.ts
  • templates/agent/test/tools.test.ts
  • templates/agent/tsconfig.json
  • templates/agent/vite.config.ts
  • templates/agent/void.config.ts
  • templates/agent/void.lock.json
  • templates/agent/wrangler.jsonc
Files with no reviewable changes: 7
  • templates/agent/test/build.test.ts
  • templates/agent/wrangler.jsonc
  • templates/agent/src/container/embedded.ts
  • templates/agent/.dev.vars.example
  • templates/agent/scripts/build.ts
  • templates/agent/src/index.ts
  • templates/agent/src/agent.ts

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

Walkthrough

The agent template now uses Void and Vite, with separate agent and container Durable Objects. It adds container-backed execution, agent-server communication, JSON routes, and a management page. It removes the prior Sandbox-based implementation and custom Worker build configuration.

Changes: Agent template architecture

Layer / File(s) Summary
Void configuration and container image
templates/agent/void.config.ts, templates/agent/void.lock.json, templates/agent/vite.config.ts, templates/agent/sandbox/Dockerfile, templates/agent/scripts/*, templates/agent/package.json, templates/agent/tsconfig.json, templates/agent/.gitignore, templates/agent/.oxlintrc.json, templates/agent/AGENTS.md, templates/agent/README.md, templates/agent/.dev.vars.example, templates/agent/wrangler.jsonc, templates/agent/test/build.test.ts, templates/agent/test/dockerfile.test.ts
Void and Vite configuration replaces the custom build and Wrangler configuration. A script bundles the agent server for the container image. The example .dev.vars file and tests for the removed build script are deleted. Setup and build documentation and Dockerfile checks are updated.
Container RPC and agent-server client
templates/agent/durable-objects/container.ts, templates/agent/src/container-adapter.ts, templates/agent/src/clone-deps.ts, templates/agent/src/server-client.ts, templates/agent/src/container-pump.ts, templates/agent/src/protocol.ts, templates/agent/src/container/*, templates/agent/test/container-adapter.test.ts, templates/agent/test/clone-deps.test.ts, templates/agent/test/server-client.test.ts, templates/agent/test/container-pump.test.ts
The container Durable Object adds command execution and HTTP proxying. Adapters provide container operations to clone and agent-server clients. The client manages server readiness, task submission, event polling, answers, and aborts.
Agent state, tasks, and runtime pumps
templates/agent/durable-objects/agent.ts, templates/agent/src/tools.ts, templates/agent/src/env.ts, templates/agent/src/errors.ts, templates/agent/src/repo-clone.ts, templates/agent/src/agent.ts, templates/agent/test/tools.test.ts
The Agent Durable Object manages repository and task records, alarms, worker and container execution, state, diffs, transcripts, and model requests. Worker-mode tools and environment helpers support execution. The former AgentSandbox module is removed.
Sandbox routes and management page
templates/agent/routes/*, templates/agent/middleware/01.json-errors.ts, templates/agent/src/page.ts, templates/agent/src/sandbox-name.ts, templates/agent/src/index.ts, templates/agent/test/sandbox-name.test.ts
The routes add repository and task submission, state, and diff endpoints. The management page calls these endpoints, and middleware converts non-JSON 404 and 405 responses to JSON. Sandbox-name validation accepts lowercase letters, digits, and dashes for names up to 63 characters. The former Worker entry point is removed.

Estimated code review effort: 4 (Complex) | ~60 minutes

Change: Refactor

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant SandboxRoute
  participant Agent
  participant Container
  participant AgentServer
  Client->>SandboxRoute: Submit task
  SandboxRoute->>Agent: startTask
  Agent-->>SandboxRoute: Return task admission result
  Agent->>Agent: Persist task and schedule alarm
  Agent->>Container: Execute or proxy agent-server requests
  Container->>AgentServer: Start server or forward HTTP request
Loading

Possibly related PRs

  • ryuzcorp/noite-templates#9: Adds the authentication, asynchronous operation, confined-tool, and container-runtime behavior that this PR replaces with the Void and Durable Object architecture.
Merge Risk: Moderate · previous review 6d417

After a container recycle, task submission and diff requests can wait past the edge timeout and return a 504. The task may still be admitted, so the client cannot tell whether it succeeded. Restoring the legacy local-secret ignore rules and tightening a test and the token handling are smaller follow-ups. Resolve the request-path wait before merging, or accept it explicitly.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 57.78% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main changes: rewriting the agent on Void and driving the container through ctx.container.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 57.78% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 45 functions across 31 files. (8 skipped: 8 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches
Generate docstrings
  • Commit to this branch
  • Create a new PR
Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@coderabbitai coderabbitai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Fix comments: Fix CodeRabbit comments on this PR

Comment thread templates/agent/.gitignore Resolved
Comment thread templates/agent/src/page.ts Resolved
Comment thread templates/agent/test/clone-deps.test.ts Resolved
POST /task no longer waits on ensureCheckout (up to 90s start grace +
120s clone, past the 30s edge timeout): it records pending/starting and
answers 202, and the alarm restores before the harness submit (worker,
new pending state) or before the pump submits (container, via
prepareCheckout). A failed restore fails the task with a clear error.

GET /diff answers from the container only when the checkout exists;
when missing or cold it schedules the restore durably and answers 409
{status:restoring} at once, with short timeouts and zero start grace so
it never blocks on clone or container start.

Also: restore .dev.vars* gitignores, clear agent-token on input clear,
await the clone-deps rejects assertion.
@ryuzdev
ryuzdev merged commit 610efe3 into main Nov 2, 2026
2 checks passed
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