Skip to content

fix(sandbox): bound logs and repair persistent storage cleanup - #4182

Merged
yannickmonney merged 1 commit into
mainfrom
fix/sandbox-disk-growth
Oct 3, 2026
Merged

yannickmonney merged 1 commit into
mainfrom
fix/sandbox-disk-growth

Conversation

@yannickmonney

@yannickmonney yannickmonney commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Sandbox storage could keep growing after cache expiry, session cleanup, and long-running nested containers. This change repairs three independent causes:

  • Enable registry mirror storage deletion so expired layers are actually removed. Include mirror settings in the existing helper stamp so old helpers adopt the fix after builds drain, preserving their cache volumes.
  • Rotate nested Docker logs at 10m with one retained file, and send Docker/redsocks diagnostics through the outer container logger instead of unbounded files.
  • Destroy all flat/legacy workspace copies and the actual container mount before clearing ownership. Failed creates use verified, retryable teardown so failed removal cannot orphan a workspace or erase one still in use.

Includes regression tests, operator documentation, and the automated coverage register. No database or public API changes.

Validation:

  • Complete sandbox service suite: 876 passed, zero failures. Includes regressions combining adopted Docker sessions with duplicate/moved workspaces; eight original workspace regression cases fail against the original code.
  • BuildKit suites: 106 passed (--timeout 15000 on the local host).
  • Runtime startup/network suites: 57 passed; both changed workspaces pass lint and typecheck.
  • Real Docker: 32 MB of nested output retained one 9.5 MB log with its final output readable.
  • Real registry v2.8.3: the same expired blob remained with deletion disabled and was removed with deletion enabled.
  • Independent reviews covered workspace teardown, runtime startup, and mirror rollout.

Rollout: new nested containers receive the log defaults; existing nested logging configurations and old log files are unchanged. Mirror entries whose expiry already failed are not rescheduled by registry v2; existing stopped-cache retention and disk-pressure cleanup reclaim those historical cache volumes. Active workspaces and package caches retain their existing policies.

CI at 94332bcfb79df91265006b0f63091a1f9eeb6838: all five workflows passed (Build, Checks, E2E, SAST, Commitlint), with 53 successful checks, 12 expected skips, and no pending or failed jobs. Both affected suites freshly executed on Bun 1.4.2: 876 sandbox tests passed; 305 runtime tests passed, 2 skipped. All 18 Playwright suites passed with no retry diagnostics. Image validation, smoke testing, and all four image scans completed successfully.

Trivy's aggregate code-scanning comparison is neutral because seven scan configurations on main are absent from this scoped PR run. All four requested image analyses uploaded successfully; existing image vulnerability alerts predate this PR. Scan workflows and suppressions are unchanged.

Local verification also passed formatting, conflict-marker, link and manual-reference checks, affected-workspace lint/typecheck, and 163 applicable security rules across the five changed production files with zero findings. The host's older Bun 1.3.10 encountered baseline timeouts in an earlier broad repository run; CI freshly passed the affected sandbox/runtime suites on the repository's Bun 1.4.2 pin.

@yannickmonney
yannickmonney force-pushed the fix/sandbox-disk-growth branch from 167f985 to 94332bc Compare October 3, 2026 22:28
@yannickmonney
yannickmonney merged commit 876ae3a into main Oct 3, 2026
@yannickmonney
yannickmonney deleted the fix/sandbox-disk-growth branch October 3, 2026 23:57
@yannickmonney

Copy link
Copy Markdown
Contributor Author

Post-merge independent review of #4182 at 876ae3a57 (squash of 94332bcfb, merged by root at 23:57:53Z with no review on record): the source is accepted with one MEDIUM follow-up, a rare data-loss path, plus three LOWs.

  • Reviewer: Tale agent update dashboard ui (#508) #2 3f9fdcee-79e7-430b-a430-ba179d5b5132, TALE-359 run e72629f1-3dd3-46d7-931c-3a9a08f52696.
  • Method: one read-only source reviewer. I re-read the MEDIUM's path in the merged source myself. Nothing was run.

MEDIUM: a failed fresh create can discard a preserved workspace that lives under a moved session root. Verified from source.

  • Path:
    • Create resolves its workspace with the flat-root shortcut (docker-session-backend.ts:302-304 → :163-164). With no colour roots, it skips the container-mount lookup, so preexisting is false (:323).
    • On a docker run failure that is not a name conflict, the new cleanup calls destroySession (:486-491).
    • destroySession always adds the container's /agent mount (:826-829), removes the container, and discards every listed copy (:857-859).
  • Scenario:
    • The session root moved from /old to /new, and /old is still visible to the spawner.
    • An exited tale-sbx-ses-X still mounts /old/ses-X, the only copy. The orphan reap at :448-475 runs only after a name-conflict error.
    • The platform resumes X, and docker run fails before name reservation. The daemon looks up the image first, so an "Unable to find image … locally" followed by a failed pull does this; so would an out-of-range --cpus.
    • destroySession removes the exited container and moves /old/ses-X to the trash. The create answers 502, and the next resume starts empty.
  • Before this PR, this path removed only the flat directory, so /old/ses-X was stranded but not deleted.
  • What it contradicts:
  • Why the tests miss it: the create-cleanup harness answers every Mounts inspect with '' (docker-session-create-cleanup.test.ts:34).
  • Fix idea: a failed create discards only the workspaceHostDir it created itself.
  • Test: an exited container mounting <otherRoot>/ses-X with content, an empty current root, and docker run failing with Unable to find image. Assert that <otherRoot>/ses-X survives.

LOW

  1. A destroy retried after a partial failure strands the copy mounted from a moved root.
    • The mount path is known only from docker inspect (:826), and the container is removed before any discard (:831).
    • If discarding the flat copy throws (EBUSY or EIO), the retry finds no container, discards only the flat copy, clears the owner marker (:868) and returns true. /old/ses-X is then outside every inventory.
    • fix(sandbox): keep erasure pending until workspace bytes are deleted #4094's workspaceDeletion matches only the trash prefix (workspace-trash.ts:145-157), so an erasure settles done while the bytes remain. This contradicts sessions.md:490-491.
    • Fix: discard the mounted copy first, or persist its path before removing the container.
  2. Destroy now needs a shared docker CLI slot within 5 s.
    • inspectWorkspaceMount(…, true) runs with timeoutMs: 5_000 and no priority (:252-259), and the wait for a slot counts against that budget (spawn-util.ts:274-295).
    • With the 12 shared slots held by creates, pulls or mirror runs, destroys, organization teardowns and failed-create cleanups throw "no docker CLI slot came free".
    • The file's own rule is that identity inspects are priority (:675-677).
  3. A cleanup error now replaces the create's real error. stopSession and destroySession throw inside the failure branch (:490-491), so docker run (session) failed: … (:493-495) is never surfaced. A user sees "cannot read session X's workspace mount…" instead of "Unable to find image". docker-session-create-cleanup.test.ts:98 asserts the masking.

INFO

  • One unreadable id-alphabet directory under the root, for example a stale NFS mount, makes every destroy throw host-wide (workspace-inventory.ts:48-53). That reads as stronger than the per-session deferral in sessions.md:491-492.
  • The mirror stamp now includes the egressProxy string (buildkitd.ts:988-989). Hypothesis: two spawner replicas whose strings differ recreate each other's mirrors whenever the mirrors are idle.
  • A surviving mutant: readWorkspaceDirs(…, true) in listWorkspaceDirs (workspace-inventory.ts:142). No test covers an unreadable colour root against the inventory.

Verified correct

  • The squash equals the head for all code files.
  • Workspace matching is safe: session-id matching is exact, the walk never descends into ses-*, and symlinks are never followed (workspace-inventory.ts:95-130).
  • Ownership is held until cleanup succeeds: the owner marker is cleared only after every discard succeeds, and an unknown mount or unreadable colour root defers before any rm.
  • Mirrors: registry deletion is enabled, a busy mirror is only updated in place, and an idle one is recreated on the same volume.
  • Log bounds: the inner dockerd uses json-file with 10m, max-file 1 and no compression, matching the outer cap. redsocks and dockerd log to stderr, and the one remaining file log is overwritten on each start.

Routing: the MEDIUM and LOWs go to the manager as follow-ups. Root decides whether the MEDIUM's precondition, an old session root still visible to the spawner, exists in any deployment.

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