fix: stabilize run terminal cleanup - #1906
Open
4pmtong wants to merge 15 commits into
Open
Conversation
8 tasks
4pmtong
force-pushed
the
fix/run-terminal-cleanup
branch
from
September 4, 2026 16:04
71e39ce to
f870a67
Compare
4pmtong
force-pushed
the
fix/run-terminal-cleanup
branch
from
September 4, 2026 16:05
f870a67 to
7514239
Compare
There was a problem hiding this comment.
Claude Code Review
Claude Code Review is paused for this repository. To reconnect it, an admin of this repository's GitHub organization (or the account owner, for personal repositories) who can also manage your Claude organization's Code Review settings needs to re-link GitHub in Code Review settings. This is a one-time step.
Tip: disable this comment in your organization's Code Review settings.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pull Request
Related Issue
No linked Issue. This bug was found internally while investigating a locally reproduced generated-web task that did not terminate.
Description
This PR fixes Runs that can remain visibly active after background terminal cleanup or workspace finalization fails. The canonical Run could already be terminal while the reusable legacy
/chattransport, follow-up ownership, Trigger execution, or stale Project runtime still reflected an active or reusable state.The final fix:
ENDfinalization and guards the transition by Run ownership, so an older handler cannot deactivate a concurrently rebound follow-up.ENDprojection, before artifact/history awaits, and reads the execution ID from that owning ChatStore even if a follow-up switches stores concurrently.stopTask,removeTask, and explicit SSE close invoked with a follow-up Run ID abort the actual shared transport.step_solveconsumer has exited before starting a fresh/chatstream.TaskLock.queue, including requests with different Run IDs.project_consumer_activerace instead of losing the trigger.missedorfailed, so a concurrently committed renderer terminal receipt cannot be overwritten; Redis cleanup and timeout counters run only when that transition wins.The Web Deploy removal and the 30-second terminal checkpoint allowance were split into and merged through #1907, so they are intentionally not part of this PR after rebasing onto
main.Testing Evidence (REQUIRED)
Automated validation completed through commit
30cfae94b:npx vitest run test/unit/hooks/useBackgroundTaskProcessor.test.tsx test/unit/store/chatStore.test.ts test/unit/store/projectStore.test.ts test/unit/components/ChatBox.test.tsx test/unit/service/triggerApi.test.ts— 172 passed. Coverage includes non-awaitedEND → NEW_TASK_STATE, the preceding Run's Trigger receipt, canonical/legacy deduplication, canonical settlement after legacy failure/close, exact-ID background admission, durable queue retention, typed admission races, backend consumer retirement, stale Project retry/reactivation, bounded Trigger delivery, and durable outbox replay.uv run pytest tests/app/controller/test_chat_controller.py tests/app/run_runtime/test_coordinator.py -qinbackend— 62 passed, 1 skipped (six existing AsyncMock warnings)..venv/bin/pytest tests/test_trigger_execution_status.py -qinserverwith the test SQLite configuration — 7 passed (one dependency compatibility warning).npm run type-check— passed.trigger_service.py; that unrelated line was not mechanically reformatted.npm run check:design-tokens— passed.git diff --check origin/main...HEAD— passed.Human UI evidence has not yet been attached. This PR changes visible frontend Run-state behavior, so the frontend/UI evidence checkbox remains unchecked until the local E2E scenario is verified and evidence is attached.
What is the purpose of this pull request?
Contribution Guidelines Acknowledgement
Pending confirmation by the human contributor; this is intentionally not checked on their behalf.