Skip to content

fix(sandbox): keep a waiter's place while its re-ask waits for a start slot #5224

Closed

Description

@tale-code-bot

Split from #4124 (TALE-63), whose remaining items are worked on fix/sandbox-review-follow-ups. This is the second path to #4124's MEDIUM 2 that #4124 (comment) added; #4144's body first recorded it as "a front waiter can lose its place in the spawner's line". MEDIUM 2's first path, a slow re-ask inside the spawner, was fixed by #4169: waitersAhead keeps a waiter while an ask of its own runs its probes.

What happens

I checked it from source on feature-train = 5298776c41a52560a3d6d3b6e45dcd21bb610bbf; nothing was run.

  • The spawner drops a waiter that hasn't asked again within 2 × hintMs + QUEUE_LIVE_SLACK_MS (services/sandbox/src/session/session-routes.ts:1275-1290).
    • For the front of the line that's 25 s (QUEUE_FRONT_HINT_MS 5 s, QUEUE_LIVE_SLACK_MS 15 s).
    • The 10-minute lease (QUEUE_LEASE_MS) is only an upper bound. Renewing it through POST /v1/sessions/:id/wait (renewWaiter, :1354) also refreshes lastAtMs.
  • The platform renews the place only once, right after a 429 that names it (services/platform/backend/core/node_only/sandbox/helpers/session_client.ts:1167-1176).
    • After that, its re-ask is a job on the agent start queues, which run on AGENT_START_SLOTS one-job slots.
    • A start that launches holds its slot through the session create (runnerd readiness alone may take 180 s) and its first 90 s drive window (DRAIN_WINDOW_MS, services/platform/backend/core/chat/external_turn_shared.ts:72).
  • The result: under load, a re-ask that is due can wait past 25 s. Its waiter is then pruned, and it rejoins at the back of the line.

Effect: fairness and latency, not data. A run that was first in line can be overtaken by every create that asked while it waited for a start slot.

Options

  1. While its start job is queued, the platform renews the place at the hint's pace, from outside the start slots.
  2. The spawner measures liveness from the hint's due time, plus an allowance for the platform's start latency.
  3. A waiter whose lease is renewed keeps its place until the lease ends or an explicit cancel (fix(sandbox): release resources safely under concurrent load #4150 removes cancelled waiters at once). The 2 × hint + 15 s window then only applies to a waiter that never renewed.

Acceptance

  • A waiter whose re-ask is held past the prune window by a busy start slot keeps its place.
  • A waiter that went away is still dropped, by its lease or an explicit cancel, so a ghost holds no slot or memory for longer than today.
  • Each changed side has a test that fails before the fix.
  • Re-check on the current main and release/0.6 first.

Refs #4124

Activity

  1. added
    bug
    agent-ready
    on Oct 31, 2026
  2. tale-code-bot commented on Oct 31, 2026

    @tale-code-bot
    CollaboratorAuthor

    Correction to option 3: "#4150 removes cancelled waiters at once" is wrong. The cancelled waiters #4150 removes are in the Docker CLI slot queue (DockerCliSlots in services/sandbox/src/spawn-util.ts), not in this line.

    The spawner's session waiter line has no cancel call. A place ends in one of three ways:

    • its lease ends;
    • its 2 × hint + 15 s window passes;
    • invalidateWaiter runs, on a destroy of the id, an admission or a queue-cap eviction (services/sandbox/src/session/session-routes.ts).

    That changes what option 3 costs. Take a waiter the platform renewed once and then abandoned: under option 3 it would keep its place until its lease ends, up to 10 minutes instead of about 25 s. The crawl/render lane abandons waiters this way: it marks a refused create collected without cancelling, and uses a new ID on its next continuation.

    Option 3 therefore meets the second acceptance point only with one of these:

    • a cancel call;
    • a renewed lease much shorter than 10 minutes.

    Options 1 and 2 are unaffected.

    (TALE-63, Coder)

  3. added a commit that references this issue on Nov 1, 2026
    2baf843
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent-readybug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions