Skip to content

fix: don't wait for sessions that are older then 120s#545

Open
Soph wants to merge 3 commits intomainfrom
soph/transcript-wait-bug-the-second
Open

fix: don't wait for sessions that are older then 120s#545
Soph wants to merge 3 commits intomainfrom
soph/transcript-wait-bug-the-second

Conversation

@Soph
Copy link
Collaborator

@Soph Soph commented Feb 27, 2026

Added a stale file check at the top of waitForTranscriptFlush: if the transcript file's mtime is older than 2 minutes, skip the poll loop entirely. The agent clearly isn't running, so the sentinel will never appear.

Files changed:

  • cmd/entire/cli/agent/claudecode/lifecycle.go — stale mtime check
  • cmd/entire/cli/agent/claudecode/lifecycle_test.go — tests for stale, recent, and nonexistent files

Not fixed (potential follow-ups)

  • The stale active session is still processed on every commit (condensation, carry-forward) — just no longer blocks for 12s
  • No automatic expiry of stale "active" sessions (would need staleness detection to transition them to IDLE)
  • The 9.1MB transcript is still read/parsed on every commit for content detection

Copilot AI review requested due to automatic review settings February 27, 2026 15:58
@Soph Soph requested a review from a team as a code owner February 27, 2026 15:58
@cursor
Copy link

cursor bot commented Feb 27, 2026

PR Summary

Low Risk
Low risk behavioral change limited to transcript-flush waiting; the main risk is prematurely skipping the sentinel wait if a transcript appears stale despite an active agent.

Overview
Avoids blocking on transcript flush for stale Claude Code sessions by adding a fast-path staleness check in waitForTranscriptFlush: if the transcript file’s mtime is older than 2 minutes, it skips the 3s polling loop and logs a debug message.

Adds unit tests covering stale files (returns quickly), recent files (still waits ~3s without a sentinel), and nonexistent files (completes without hanging).

Written by Cursor Bugbot for commit a009258. Configure here.

Copy link
Contributor

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 pull request optimizes the transcript flush waiting mechanism in Claude Code agent lifecycle management by adding a fast-path check for stale transcript files. The change prevents unnecessary 3-second polling loops when waiting for transcripts that haven't been modified in over 2 minutes, which indicates the agent is no longer running.

Changes:

  • Added stale file detection (2-minute threshold) to skip polling when agent clearly isn't active
  • Added comprehensive test coverage for stale, recent, and nonexistent file scenarios
  • Maintains existing timeout behavior for recently-modified files

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
cmd/entire/cli/agent/claudecode/lifecycle.go Implements stale file check using os.Stat and ModTime() comparison before entering the poll loop
cmd/entire/cli/agent/claudecode/lifecycle_test.go Adds three test cases covering stale (10min old), recent (just created), and nonexistent file scenarios with timing assertions

Soph added 2 commits February 27, 2026 19:21
Entire-Checkpoint: cd7235a190d2
Entire-Checkpoint: 8c595b62e952
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants