Skip to content

fix(cloud): stop false-positive agent-exited 410 on resumed terminals - #5477

Open
Pritom14 wants to merge 4 commits into
mainfrom
fix/cloud-terminal-exit-false-positive
Open

Pritom14 wants to merge 4 commits into
mainfrom
fix/cloud-terminal-exit-false-positive

Conversation

@Pritom14

@Pritom14 Pritom14 commented Sep 16, 2026

Copy link
Copy Markdown
Collaborator

Code changes: +32 -2
Tests: +14 -12
Others: +0 -0

What

Fixes a false-positive "agent terminal has exited" (HTTP 410 TERMINAL_SESSION_EXITED) on any resumed cloud session.

Why

IssueTerminalTicket decided the agent had exited if ANY agent terminal for the session was closed or failed. But every resume closes the previous agent terminal and opens a fresh one, so a session that has been paused and resumed even once always carries a closed terminal. The result: the browser terminal-ticket mint returned 410 in a loop for a live session, and the UI showed "Connected" with no terminal. This came in with #5350 and only surfaces once a session has been resumed.

How

The agent is treated as exited only when a dead terminal exists AND no live one does. Both occurrences of the check in worker_transport_store.go now require NOT EXISTS an opening/open agent terminal, so a resumed session with a live open terminal is no longer misreported.

Testing

cloud gofmt, build, vet, and go test ./internal/httpapi/ pass. Verified against the l-a run where a resumed orchestrator with a live open terminal was being 410-blocked.

Fixes #5350's IssueTerminalTicket exit-detection: it flagged the agent
'exited' whenever ANY agent terminal was closed/failed, but every resume
closes the old terminal and opens a new one, so a resumed session was
always mis-reported as exited (410) even with a live open terminal.
Now only exits when a dead terminal exists AND no live one does.

Belongs to #5350's lineage (main), parked here so the combined deploy
carries it; should become a standalone main fix.
@mohakchakraborty2004

Copy link
Copy Markdown
Collaborator

Fixed two issues in this PR:

a terminal is now considered live only when it has not expired and its worker is still connected. This prevents old terminal records from blocking the correct “agent exited” result

fixed the flaky backend test cleanup by waiting for the shared authentication read to finish before the test ends.

Also ran the Cloud build, vet, and race tests successfully.

@mohakchakraborty2004

Copy link
Copy Markdown
Collaborator

@Pritom14 please resolve the merge conflicts

@i-trytoohard i-trytoohard added bug Something isn't working comp/daemon Go daemon, process lifecycle, and backend control plane. labels Sep 17, 2026
@i-trytoohard i-trytoohard added this to the Agents & orchestration milestone Sep 17, 2026
t and others added 2 commits September 17, 2026 15:05
Resolve the one conflict in backend/internal/service/agent/codex_accounts_test.go
toward main: main hardened this test (shared-call wait + TempDir-race fix, the
'shared' rename) and this branch carried the older version. The branch's actual
change — the false-410 exit-detection narrowing in worker_transport_store.go —
auto-merged cleanly on top of #5350's relay (both AND NOT EXISTS(opening/open)
blocks intact). Taking main's test also fixes the flaky
TestAuthenticationRequestCancellationDoesNotCancelSharedRead CI failure.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
TestRunInstallScriptCancellationCleansUp flaked on loaded CI runners. The
50ms context deadline can fire while the download is still in flight, before
RunInstallScript creates installers/tmp, so os.ReadDir returned ENOENT and the
test treated "nothing leaked" as a failure. Accept a non-existent scratch dir
as a clean outcome and only fail on surviving entries.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working comp/daemon Go daemon, process lifecycle, and backend control plane.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants