Skip to content

fix(sandbox): honor memory overrides and retry disk relief - #4169

Merged
yannickmonney merged 7 commits into
mainfrom
fix/sandbox-host-room-fairness
Oct 13, 2026
Merged

yannickmonney merged 7 commits into
mainfrom
fix/sandbox-host-room-fairness

Conversation

@yannickmonney

@yannickmonney yannickmonney commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Sandbox host-room fairness repair

Implements the manager-approved bounded waiter lease contract for TALE-499, on top of the existing MEDIUM 1/3 repair in this PR.

  • An explicit SANDBOX_MAX_SESSIONS disables adaptive memory admission while retaining count and disk guards; adaptive protection remains the default.
  • Adaptive boot rejects impossible memory reserves and logs memory refusals.
  • Disk relief samples immediately around locked removals and pauses only after repeated low gains.
  • A waiter is marked in-flight before slow reclaim/memory probes, so its place cannot expire during its own re-ask.
  • Waiters have a bounded ten-minute lease renewed by re-asks or the shared client liveness ping; explicit destroy, admission, and queue-cap eviction invalidate generations, preventing late resurrection.
  • Added regressions for slow re-asks, cancellation, queue-cap eviction, liveness renewal, and retained MEDIUM 1/3 behavior.
  • EN/DE/FR environment references, upgrade notes, .env.example, sandbox README, and manual coverage remain aligned.

Verification

  • Full services/sandbox/src/session/session-routes.test.ts: 132 passed, 0 failed.
  • Focused client capacity/drain tests: 4 passed, 0 failed.
  • Scoped sandbox TypeScript check: exit 0.
  • Scoped oxlint and oxfmt: exit 0.
  • No stack, browser, E2E, container/image build, whole-platform suite, or whole-workspace typecheck was run.

The branch is ready for independent review. CI was started for the updated head; earlier queued runs were cancelled by the head update, and the current source checks remain queued in the saturated CI pool.

@yannickmonney
yannickmonney force-pushed the fix/sandbox-host-room-fairness branch from 18cb8bf to 448200e Compare October 4, 2026 02:50
@yannickmonney
yannickmonney marked this pull request as ready for review October 4, 2026 02:50
@yannickmonney
yannickmonney force-pushed the fix/sandbox-host-room-fairness branch from 448200e to 38c9bc2 Compare October 4, 2026 02:56
@yannickmonney

Copy link
Copy Markdown
Contributor Author

Request changes — PR #4169

Exact reviewed head: 38c9bc263508ebe2be3f49e19100060c2a835347.
Independent reviewer: Codex #9, agent b7c66e31-fc10-4e92-ae49-80c467ee7feb, TALE-537, run 7f588926-aed3-4106-a4f8-b2ddea5d927d.
Implementation: Codex #1, agent af98a247-0225-43ff-b469-5b5b5702b4e0, continuation run a48cdd19-ffad-4d65-8926-830e594c32d6.
Contract: TALE-499 / #4124 and manager Answer 335b2fe3-94db-4822-aeed-02e40579cd33; held-start evidence in issue comment 5970985934.

No agent #2 verdict existed on the PR at the initial or subsequent pre-publication reads. This is a review record, not a native task decision, merge authorization, or CI acceptance.

Blocking findings

1. MEDIUM / P2 — the renewed lease still expires after the old hint window; held-start liveness is not implemented

services/sandbox/src/session/session-routes.ts:716 expires a non-in-flight waiter when either its ten-minute lease expires or lastAtMs exceeds 2 * hintMs + 15_000. Thus the front waiter still disappears after 25 seconds, even immediately following a successful /wait renewal. The named ten-minute constant does not control its effective lifetime.

services/platform/backend/core/node_only/sandbox/helpers/session_client.ts:580 calls liveness once, immediately after a queued 429, then throws the busy error. There is no renewal while the subsequent start is held behind a start-worker slot. This retains the second MEDIUM 2 path documented in comment 5970985934: a queued retry can wait through another start's readiness and drive window, far beyond 25 seconds. The existing focused client tests do not exercise a held start or recurring liveness.

Executed reproduction: enqueue front waiter, renew successfully, inspect admission at +26 seconds. Expected one predecessor; actual zero. Remove the independent hint-based expiry, implement the approved held-start liveness ownership in the shared client, document the actual default, and prove preservation under a delayed start rather than merely calling the route once. The README at services/sandbox/README.md:239 still says MEDIUM 2 is unresolved and the partial fix does not change waiter lifecycle.

2. MEDIUM / P2 — expiry can be undone by a late liveness call or re-ask

services/sandbox/src/session/session-routes.ts:795 renews any map entry without checking whether its lease has already expired. Expiry is lazy, so an abandoned entry can remain in the map past its deadline and be revived at the front by a late ping. The added liveness regression at services/sandbox/src/session/session-routes.test.ts:3224 actually expects success after eleven minutes with no intervening renewal, codifying that resurrection.

Similarly, reserveCreate marks an existing entry in flight at services/sandbox/src/session/session-routes.ts:628 before checking whether it expired. waitersAhead then exempts it from expiry. An expired front waiter can regain its old position ahead of a continuously live successor instead of rejoining at the back. Also, the expiry branch at line 720 deletes without advancing waiterGenerations; cancellation and cap eviction use invalidation, but expiry does not.

Executed reproductions: a ping at +11 minutes returns 200 instead of 404; an expired re-ask receives position 0 instead of position 1 behind a successor renewed every 20 seconds; expiry leaves the epoch unchanged. Check expiry before renewal/in-flight protection and consistently invalidate expired ownership. A stale operation may be refused or start a new back-of-line request, but may not preserve expired priority.

3. MEDIUM / P2 — cancellation is not fenced inside the admission lock

services/sandbox/src/session/session-routes.ts:631 runs the first admission without verifying the captured waiter generation. The later generation comparison at line 647 is outside the serialized callback, leaving the same race before the second admission at line 650.

Executed white-box reproduction: hold the admission promise, start a queued waiter re-ask, invoke the exact invalidation used synchronously by handleDestroy, then release admission. The stale request returns admitted (null) and appears in pendingCreates, despite cancellation having advanced its generation. The new cancellation test only covers cancellation while the memory probe is already in progress; it misses cancellation while admission is queued.

Check the epoch inside every serialized admission callback, atomically with reserving capacity. Retain the existing explicit cancellation API and add a queued-admission cancellation regression.

4. MEDIUM / P2 — merge resolution removes unrelated existing regression coverage

The merge base is current fetched origin/main, 9b7463b707c5e44349f0a8c51e764a39e3e5c4fb. Against it, services/sandbox/src/session/session-routes.test.ts loses 964 lines and removes 23 existing test declarations (one has a replacement declaration), including warm-activation reservations/FIFO, durable pin failures, incarnation-safe adoption/liveness, pending backend capacity, deletion-state failure, staging reconciliation, and split-UTF-8 output. Production implementations of those features remain. Passing the smaller suite does not verify the removed cases.

This overlaps already-landed sandbox work from #4174, #4188 and #4094. Merge 9fbc87573 lists this test file as a conflict; the final waiter commit adds tests but does not restore the removed coverage. The conflict resolution in services/platform/tests/manual/reference/automation.md also removes unrelated coverage records, including project Audience and task comment actors, and downgrades other runtime evidence. Restore current-main coverage and append only this task's additions. The final continuation's production edits are local to waiter/client/routing code, but its merge result is not scope-preserving.

Verification and limitations

  • Initial disk: 238 GiB free; final observed disk: 220 GiB free, both above the 20 GiB floor.
  • Reviewed git-archived source at the exact SHA in this task's delivery box; standing checkout left unchanged. Reused existing dependencies read-only, including an already-installed eventsource-parser; installed nothing.
  • Bun 1.4.2, original exact-head session-route suite: 133 passed, 0 failed with --timeout 15000. Initial default-timeout run: 132 passed, queue-cap test timed out after 5 seconds; isolated rerun passed in about 10 seconds. This is a timeout limitation, not a claimed functional queue-cap failure.
  • Exact-head host-memory, host-disk and buildkit lifecycle files: 66 passed, 0 failed. MEDIUM 1 and 3 synthetic regressions remain green.
  • Vitest 4.1.11, focused client capacity/drain tests: 4 passed, 43 deliberately skipped. Used a one-worker node-only review config, not the platform-wide test graph. Initial launch/import prerequisites were resolved using existing binaries/dependencies only.
  • New delivery-box-only adversarial checks against unchanged production source: 5 failed as expected, establishing the lease window, expired ping, unchanged expiry epoch, queued-admission cancellation, and expired re-ask priority defects. These are white-box mechanism proofs, not a live platform held-start integration test.
  • Passive gh pr checks 4169 readback: one source-resolution check passed; five checks pending. CI is not all green. No CI rerun, cancellation, or watch was performed.
  • Unrun: full platform suite, whole-workspace typecheck/check, lint/typecheck of unchanged production source, browser/E2E/manual verification, real held-start job integration, Docker/Kubernetes/image/runtime tests, and removed root regression cases. Existing synthetic tests do not prove a deployed image's statfs or real disk pressure behavior.

Disposition: request changes. MEDIUM 1/3 have positive targeted evidence; MEDIUM 2's approved lease and no-resurrection contract is not satisfied. Author/manager should arrange a scope-preserving repair and new exact-head independent review under the existing admission/review guards. No task move, native review decision, push, or merge was made.

yannickmonney and others added 5 commits October 13, 2026 12:29
The waiter lease marked a waiter in flight with a flag and outdated
asks with a per-id generation counter. A re-ask that ended without
re-queueing (an unreadable Kubernetes inventory after its reclaim, an
error) left the flag set, and expiry never prunes a waiter in flight, so
the place was held forever. The counters were never pruned either: one
entry per session id for the spawner's lifetime.

Register each create's ask only while it runs and drop it in finally.
A waiter is spared by expiry while an ask of its id runs, and a destroy,
an admission or an eviction marks the id's running asks stale so a late
answer cannot put the waiter back. Nothing outlives its ask.
A create refused with a place in the spawner's line renews that place
before it reports the refusal. The renewal was best effort through
.catch(() => undefined), which dropped its failure without a trace, and
no test pinned the call. Log the failure, keep the refusal as the answer,
and cover the renewal, a refusal without a place, an id nothing waits
under and a failing renewal.

Also drop the duplicated doc comment the renewal left above its function.
The README still called the waiter lifecycle open, the sessions guide
still said a single removal that frees nothing pauses disk relief for six
hours, and neither said that an explicit SANDBOX_MAX_SESSIONS turns memory
admission off. Describe what the code does: the lease and the asks that
keep or lose a place, three low gains in a row before the pause, and the
explicit cap leaving the count, CPU and disk guards in force. Bring the
coverage row up to date.
@yannickmonney
yannickmonney force-pushed the fix/sandbox-host-room-fairness branch from 38c9bc2 to 9efbe93 Compare October 13, 2026 10:51
@yannickmonney
yannickmonney merged commit 52ba9f5 into main Oct 13, 2026
@yannickmonney
yannickmonney deleted the fix/sandbox-host-room-fairness branch October 13, 2026 12:27
tale-review-bot pushed a commit that referenced this pull request Oct 30, 2026
The v0.5.89 notes said the upgrade needs no database migration or
manual configuration change and described only the native CLI fix.
The release adds migration 0204_usage_ledger_provider.sql, moves the
API contract from 3.43.0 to 3.44.0, and turns coding-agent sign-in on
by default, although the v0.5.88 notes said it stays off unless an
operator turns it on.

The Upgrade notes now name the migration, applied at boot, and the
contract version. They say that sign-in is on by default, which public
surfaces that opens, what it needs, and the two switches that keep
agents on API keys, with a pointer to the v0.5.90 notes that repeat
it. They also name what else asks something of an operator: the two
sandbox settings of #4169 that behave differently, the model-access
rules without a target that block model-access changes since #4216,
and the OIDC claim mappings that form saves before #4212 removed.

The Highlights add agent sign-in, the Connected agents settings page,
trigger readiness in the automations list and agent runs in a task's
activity. A last bullet says the notes were corrected after
publication. The published Release body is not changed by this
commit; a person edits it.

Closes #4970
Task: TALE-199
tale-code-bot added a commit that referenced this pull request Oct 31, 2026
The v0.5.89 notes said the upgrade needs no database migration or
manual configuration change and described only the native CLI fix.
The release adds migration 0204_usage_ledger_provider.sql, moves the
API contract from 3.43.0 to 3.44.0, and turns coding-agent sign-in on
by default, although the v0.5.88 notes said it stays off unless an
operator turns it on.

The Upgrade notes now name the migration, applied at boot, and the
contract version. They say that sign-in is on by default, which public
surfaces that opens, what it needs, and the two switches that keep
agents on API keys, with a pointer to the v0.5.90 notes that repeat
it. They also name what else asks something of an operator: the two
sandbox settings of #4169 that behave differently, the model-access
rules without a target that block model-access changes since #4216,
and the OIDC claim mappings that form saves before #4212 removed.

The Highlights add agent sign-in, the Connected agents settings page,
trigger readiness in the automations list and agent runs in a task's
activity. A last bullet says the notes were corrected after
publication. The published Release body is not changed by this
commit; a person edits it.

Closes #4970
Task: TALE-199
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