refactor(sandbox): single docker primitive; fix(sandbox): label + time-bound helper containers (#180 #173)#204
Merged
Merged
Conversation
…bound helper containers Extract docker.ts as the ONE shared docker-primitive module for ca-sandbox (architecture-007, #180): DOCKER_ENV (the MSYS_NO_PATHCONV Windows/Git-Bash guard) and defaultDockerRun were copy-pasted verbatim across build, cp, create, exec, registry, run, claude-inside, and cli; the {code,stdout,stderr} result shape recurred under three names (RunResult / ClaudeRunResult / DockerResult). Every module now imports the single definitions from docker.ts and re-exports the old type names for backward compatibility; the injectable-runner test seam is unchanged. Behavior-preserving: the pre-existing vitest suite passes unmodified (one existing test call site updated to add a required arg introduced by the #173 fix below, no assertions changed). typesafety-002 (build.ts's opts.env silently dropping DOCKER_ENV) was already fixed in #197's typed RunOpts. Label + time-bound the sandbox helper containers (reliability-015, #173): the throwaway clone container and the docker-cp helper carried no ca.sandbox label and no timeout, so a hung clone or a host crash mid-create could orphan a networked container prune() could never reclaim. Both now carry ca.sandbox=1 + ca.sandbox.id=<id>, and each docker step (clone, cp-helper create, cp) is wall-clock timed out. createSandbox's failure teardown now removes containers before the volume (matching destroySandbox's order), so an in-use volume is no longer left un-retried. Tests: pure unit coverage for the new labels + teardown order; docker-gated integration tests proving prune() reclaims an orphaned, labeled helper-shaped container (self-skip without a Docker engine, as documented in tech-stack.md). Closes #180 Closes #173 Claude-Session: https://claude.ai/code/session_01PVTCDji6bEuf9SifQ8tfsa
Completes the previous commit: create.ts's clone container and docker-cp helper now carry ca.sandbox=1 + ca.sandbox.id=<id>, each docker step is wall-clock timed out, and createSandbox's failure teardown removes containers before the volume. Adds create.test.ts coverage (pure + the docker-gated prune() proxy tests). This was already reflected in the previously-committed rebuilt sandbox.js; only the .ts sources were left unstaged in the prior commit. Claude-Session: https://claude.ai/code/session_01PVTCDji6bEuf9SifQ8tfsa
…lper labels) Payload change in plugins/ca-sandbox/tools/ requires a version bump (per-PR CI gate). Claude-Session: https://claude.ai/code/session_01PVTCDji6bEuf9SifQ8tfsa
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Lane D — ca-sandbox dedup + container-lifecycle hardening.
What
plugins/ca-sandbox/tools/docker.tsprimitive — a singleDOCKER_ENV(theMSYS_NO_PATHCONVWindows guard), onedefaultDockerRun/makeDockerRun, one canonical{code,stdout,stderr}RunResult. The ~8 duplicated copies across build/claude-inside/cli/cp/create/exec/registry/run now import it;ClaudeRunResult/DockerResultcollapse to aliases. Injectable-runner test seam preserved. (typesafety-002 was already fixed in fix(plugins): tribunal quick-kills: atomic writes, typed spawn opts, fail-closed CI #197.)ca.sandbox=1+ca.sandbox.id=<id>(so the AC-11 prune sweep can reclaim them), adds wall-clock timeouts to the clone/cp steps, and reorders createSandbox failure teardown to remove containers before the volume (closes a prior orphan-on-in-use-volume leak).Verification
npm run typecheck0 errors;npm test164 passed / 31 docker-gated skipped (no Docker engine — expected);npm run build+git diff --quiet -- sandbox.jsclean (rebuilt bundle committed). No pre-existing test assertions modified (refactor parity).MSYS_NO_PATHCONVguard survives on all 8 command paths, noshell:trueintroduced, every container-isolation control intact, and the Label and time-bound the sandbox helper containers to avoid orphaned containers #173 change strictly reduces leak surface. 3 LOWs, all no-action (timeout is a client-side bound backstopped by label+prune; stand-in test acceptable; global-prune blast radius arguably-correct).Bumps ca-sandbox 0.1.2 → 0.1.3.
Closes #180
Closes #173
https://claude.ai/code/session_01PVTCDji6bEuf9SifQ8tfsa