Skip to content

fix(sessions): stop blaming the queue for every launch that is not up yet - #226

Merged
artempartos merged 2 commits into
developfrom
fix/honest-launch-status
Sep 9, 2026
Merged

artempartos merged 2 commits into
developfrom
fix/honest-launch-status

Conversation

@artempartos

Copy link
Copy Markdown
Contributor

What a person actually saw

Production, 2026-09-09 15:09 UTC. Connecting Antigravity from the profile page showed, for the whole launch:

Waiting for an available session slot
Authentication will start automatically when capacity is available.

Neither sentence was true. The session was granted its slot one second in, the pool was user:3 with a limit of 2 and nothing else in it, and the pod pulled its image in 2.5 s and started. Then Finish was pressed four seconds in, before the launch reached exec, and the session was reported as:

failed — Session admission is closed

Nothing had failed, and that string is the queue refusing a permit, not a diagnosis.

Why

  • A session sits in queued from the moment the row is written until the container workflow's first activity calls start! — right through dispatch. Both SessionShowContent and the profile auth modal keyed their copy on state === 'queued' alone, so that state's second meaning ("your slot is granted, the container is coming up") was rendered as a full pool. The same screen text covered a launch that had failed outright and would never come up at all.
  • admission.last_error — the refused preflight, the failed Temporal dispatch, the capacity refusal — was never exposed, so the queue message was the only explanation a user ever got.
  • finalize_session took state[:error] at face value. A finish landing mid-launch makes the next activity raise Stopped, whose message then became both error_message and the reason for failed.

What changed

  • SessionAdmission#launch_phase — queued_for_slot / starting / cluster_capacity / namespace_quota / running, derived from admitted_at, launch_state and wait_reason together. Neither signal answers it alone: wait_reason also defaults to concurrency_limit at insert, so it agrees with whichever reading you already had.
  • TerminalSessionResource carries launchPhase and launchError.
  • shared/lib/launchStatus is the single place that turns a phase into words, used by both screens; the launch's own error is rendered instead of silence.
  • GENERIC_ERROR_MESSAGES gains "Session admission is closed", and finalize_session no longer fails a session over a generic message when the finish was requested.

Tests

  • test/resources/terminal_session_resource_test.rb (new, 7 cases): a session nobody has a slot for reports queued_for_slot; a granted slot reports starting while still in queued; cluster capacity reports itself; the launch's own error reaches the payload; a session with no admission claims nothing.
  • admitted_phase_activity_test.rb: a finish requested mid-launch finishes clean (fails without the fix: Expected "finished", Actual "failed"), and a real error still fails a session the user asked to finish.
  • shared/lib/launchStatus.test.ts + four SessionShowContent cases for the copy each phase produces.

make check_all green: brakeman, eslint, fe-test, fsd, rails-test, rubocop, system-test, typescript, vite-build.

Not in this PR

The reason anything in project 27 is genuinely queued right now is 16 leaked reservations — that is #224.

🤖 Generated with Claude Code

artempartos and others added 2 commits September 9, 2026 18:55
… yet

A session stays in `queued` from the moment its row is written until the
container workflow's first activity starts it — right through dispatch.
Two screens read that state as "no slot for you" and said so, so an
authentication session that was granted its slot in one second spent its
whole launch telling the user to wait for capacity, with the user's own
limit nowhere near full. A launch that failed outright said the same
thing, with the real reason recorded only in `last_error` where nobody
could see it.

SessionAdmission#launch_phase answers what the session is actually
waiting on, the resource carries it plus the launch's own error, and
shared/lib/launchStatus is the single place that turns either into words.

Also: "Session admission is closed" is the queue refusing a permit,
which is what a `finish` landing mid-launch looks like from inside an
activity. It used to become both the session's error message and the
reason it was marked failed — pressing Finish four seconds in reported a
failed session in the queue's vocabulary. A requested finish now keeps
only whatever real error it already had.

Co-Authored-By: Claude Opus 5 <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>
The API has one action for both intents — every "Cancel session" button and
every dialog close POSTs `finish` — so a session stopped while its container
was still coming up was reported with the vocabulary of a completed run.

`ready_at` separates them: the session was never usable, so the person
cancelled it. Across three days of production, `finishing_at` without
`ready_at` described exactly the two authentication sessions this is
about and not one of 2,168 workflow steps.

Co-Authored-By: Claude Opus 5 <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>
@artempartos

Copy link
Copy Markdown
Contributor Author

Correction to the story above: the person did not press a finish button — there isn't one on that screen. The API has a single action for both intents (POST /api/v1/terminal_sessions/:id/finish), and in the auth modal it is wired to handleClose, which is what the dialog's X, Escape, a click on the overlay, and the button labelled "Cancel session" all call. So closing the dialog on a launch in progress — which is exactly what the false "Waiting for an available session slot" invites you to do — sends a finish.

SessionService.finish does have a cancel path, but only for a session still in queued. Session 13257 had already flipped to running one second in (the workflow's first activity calls start!), so it took the finishing path, the in-flight activity hit a closed permit, and the outcome was failed — Session admission is closed.

Added in d0738ba: ready_at decides the word. A session stopped by its owner before it was ever usable is cancelled, not finished. Production over three days: finishing_at without ready_at described exactly the two authentication sessions this is about and not one of 2,168 workflow steps — so the rule touches this failure class only.

make check_all green again on the updated branch.

@artempartos
artempartos merged commit 11e12e2 into develop Sep 9, 2026
7 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