Fix background task liveness probe after session resume#215
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d795398521
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| # literal "Output is being written to". The path ends at the first | ||
| # whitespace after ".output". | ||
| match=$(grep -F "$task_id" "$transcript_path" 2>/dev/null \ | ||
| | grep -oE 'Output is being written to: [^[:space:]]+\.output' \ |
There was a problem hiding this comment.
Handle whitespace in recorded output paths
If the recorded Claude output path contains whitespace, this pattern fails to match anything because it requires the path to be a single non-whitespace token up to .output. In that case is_bg_task_alive falls back to the derived path for the resumed session; when that file is absent it fail-opens as alive, so a dead/orphaned background task remains parked forever for projects whose generated task-output path includes a space.
Useful? React with 👍 / 👎.
d795398 to
8929fb0
Compare
Problem
When a Claude Code session is resumed or continued, the current transcript may have a different session id from the session that originally launched a
background task. The task's
.outputfile physically lives under the old session directory, but the stop hook's liveness probe derived the output pathfrom the current transcript's session id. As a result, dead/orphaned tasks were never pruned and the loop was blocked from reaching Codex review.
Fix
Teach
is_bg_task_aliveto look up the real output file path recorded in the transcript's launch message:extract_bg_task_output_path_from_transcript()to parse the "Output is being written to: " line.tasks_dirpath when the transcript is unreadable or the message is missing.transcript_pathargument throughprune_dead_bg_task_idsandlist_pending_background_task_ids.Test
Add regression test AC-25: simulate a session resume with a new-session transcript that records an old-session output path, then assert the dead task is
pruned using the real path rather than the derived new-session path.
42/42 tests pass.