Skip to content

Fix background task liveness probe after session resume#215

Open
SwordFaith wants to merge 1 commit into
PolyArch:devfrom
SwordFaith:fix/bg-task-output-path-from-transcript
Open

Fix background task liveness probe after session resume#215
SwordFaith wants to merge 1 commit into
PolyArch:devfrom
SwordFaith:fix/bg-task-output-path-from-transcript

Conversation

@SwordFaith

Copy link
Copy Markdown

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 .output file physically lives under the old session directory, but the stop hook's liveness probe derived the output path
from 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_alive to look up the real output file path recorded in the transcript's launch message:

  • Add extract_bg_task_output_path_from_transcript() to parse the "Output is being written to: " line.
  • Prefer the real path when available; fall back to the derived tasks_dir path when the transcript is unreadable or the message is missing.
  • Pipe the new optional transcript_path argument through prune_dead_bg_task_ids and list_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.

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

Copy link
Copy Markdown

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: 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".

Comment thread hooks/lib/loop-bg-tasks.sh Outdated
# 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' \

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

@SwordFaith SwordFaith force-pushed the fix/bg-task-output-path-from-transcript branch from d795398 to 8929fb0 Compare June 15, 2026 12:49
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.

1 participant