Skip to content

Clean up terminal state when threads are archived#1702

Merged
juliusmarminge merged 1 commit intomainfrom
t3code/archive-thread-cleanup
Apr 2, 2026
Merged

Clean up terminal state when threads are archived#1702
juliusmarminge merged 1 commit intomainfrom
t3code/archive-thread-cleanup

Conversation

@juliusmarminge
Copy link
Copy Markdown
Member

@juliusmarminge juliusmarminge commented Apr 2, 2026

Summary

  • Close per-thread terminal sessions after a successful thread.archive dispatch on the server.
  • Treat archived threads as inactive in terminal state cleanup on the web client.
  • Add orchestration lifecycle handling for thread.archived and thread.unarchived so terminal cleanup follows the latest thread state within a batch.
  • Update tests to cover archive cleanup, archived draft-thread filtering, and batch lifecycle edge cases.

Testing

  • Not run (PR description only).

Note

Medium Risk
Adds new side effects to the orchestration dispatchCommand WebSocket path and changes client-side terminal retention rules; mistakes could close active terminals or drop terminal events for threads unexpectedly. Scope is limited to archive/unarchive handling and is covered by new unit tests.

Overview
Ensures terminal resources are cleaned up when threads are archived.

On the server, ORCHESTRATION_WS_METHODS.dispatchCommand now closes the thread’s terminals after a successful thread.archive dispatch (with failures only logged), and a new test asserts the close call occurs.

On the web client, terminal state retention now treats archivedAt threads as inactive (including draft-linked state), orchestration batch effects now remove terminal state on thread.archived but not if a later thread.unarchived appears in the same batch, and terminal events for archived threads are ignored; tests were updated/added for these cases.

Written by Cursor Bugbot for commit c6d000d. This will update automatically on new commits. Configure here.

Note

Clean up terminal state when threads are archived

  • When a thread.archive command is dispatched via the WebSocket RPC, the server now calls terminalManager.close for that thread after a successful dispatch; failures are logged as warnings and do not affect the RPC result.
  • collectActiveTerminalThreadIds now excludes archived threads from the active terminal set, and draft-linked terminal state is no longer retained for archived or deleted server threads.
  • deriveOrchestrationBatchEffects adds thread.archived and thread.unarchived handling: archived threads are added to removeTerminalStateThreadIds, and a subsequent thread.unarchived in the same batch cancels that cleanup.
  • During bootstrap and live event routing in __root.tsx, archived threads are treated as inactive and incoming terminal events for archived threads are ignored.

Macroscope summarized c6d000d.

- close thread terminals after successful archive commands
- ignore archived threads in terminal retention and event cleanup
- add coverage for archive and unarchive lifecycle handling
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 2, 2026

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: f3c1ad71-269d-4036-ad04-eb73d04150cb

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch t3code/archive-thread-cleanup

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions bot added size:M 30-99 changed lines (additions + deletions). vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. labels Apr 2, 2026
@macroscopeapp
Copy link
Copy Markdown
Contributor

macroscopeapp bot commented Apr 2, 2026

Approvability

Verdict: Approved

Extends existing terminal cleanup logic to handle archived threads, following the same pattern already used for deleted threads. Changes are self-contained with graceful error handling and comprehensive test coverage.

You can customize Macroscope's approvability policy. Learn more.

@juliusmarminge juliusmarminge merged commit 9013c07 into main Apr 2, 2026
12 checks passed
@juliusmarminge juliusmarminge deleted the t3code/archive-thread-cleanup branch April 2, 2026 23:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M 30-99 changed lines (additions + deletions). vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant