Skip to content

fix(runtime): preserve agent session capture during quit#243

Merged
forketyfork merged 2 commits intomainfrom
fix/agent-quit-capture-drain
Feb 24, 2026
Merged

fix(runtime): preserve agent session capture during quit#243
forketyfork merged 2 commits intomainfrom
fix/agent-quit-capture-drain

Conversation

@forketyfork
Copy link
Owner

@forketyfork forketyfork commented Feb 24, 2026

Issue

When quitting Architect with multiple active agent sessions, some Claude resume IDs were not captured. The shutdown path could mark sessions as dead before draining all trailing PTY output, so late claude --resume <uuid> lines were sometimes missed.

Issue linkage is not included for this hotfix-path change; linkage will be added during mandatory cleanup.

Solution

This change keeps PTY output processing enabled for spawned sessions even after process exit, so late bytes can still flow into quit capture.

It also adds a bounded post-worker drain-until-quiet pass before UUID extraction. That extra drain window captures trailing shutdown output without making quit unbounded.

Finally, it removes raw terminal-tail debug logging that emitted control-heavy text into the launcher shell and made debugging noisy.

Test plan

  • Start Architect with multiple terminals running Claude sessions that already have real conversation history.
  • Quit Architect while those sessions are active and verify shutdown completes without control-sequence bleed into the launcher shell.
  • Relaunch Architect and confirm previously active sessions resume from captured IDs instead of starting fresh.

Issue: Quitting Architect with multiple active agent sessions could miss resume IDs because trailing PTY output arrived after sessions were marked dead, and shutdown debug tail logging printed control-heavy terminal data into the launcher shell.

Solution: Keep draining PTY output for spawned sessions even after process exit so late bytes are still processed. Add a bounded post-worker drain-until-quiet pass before UUID extraction to capture trailing shutdown output deterministically. Remove raw terminal-tail debug logging to avoid control-sequence noise in the launcher shell while retaining concise capture diagnostics.
@forketyfork forketyfork marked this pull request as ready for review February 24, 2026 14:37
@forketyfork forketyfork requested a review from Copilot February 24, 2026 14:37
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 81f4a212b2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a shutdown edge case where agent resume UUIDs could be missed during quit by continuing to drain PTY output after process exit and performing a bounded “drain-until-quiet” pass before UUID extraction.

Changes:

  • Keep SessionState.processOutput() active for spawned sessions even when marked dead, allowing post-exit PTY bytes to be processed/captured.
  • Add a bounded post-worker quit-capture drain loop (poll + quiet-window + max-window) before extracting UUIDs.
  • Remove noisy “terminal tail” debug logging during quit teardown and update the architecture ADR to reflect the new drain behavior.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
src/session/state.zig Adjusts output-drain gating so quit capture can continue after session exit; adds a small unit test for the gating helper.
src/app/runtime.zig Adds bounded post-worker output draining before UUID extraction; removes control-heavy debug tail logging; adds unit tests for drain stopping conditions.
docs/ARCHITECTURE.md Updates ADR-014 to document post-exit drain behavior and the bounded drain-until-quiet pass.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Address PR review comment: #243 (comment)

Limit post-exit output draining to sessions with active quit capture, and treat PTY EIO as terminal EOF during reads. This preserves quit-time UUID capture while avoiding runtime failures when dead sessions are polled in normal loops.
@forketyfork forketyfork merged commit 6c0c145 into main Feb 24, 2026
4 checks passed
@forketyfork forketyfork deleted the fix/agent-quit-capture-drain branch February 24, 2026 14:58
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.

2 participants