Skip to content

Commit 39f09c4

Browse files
committed
Avoid duplicate jq pass in bg-pending short-circuit
hooks/loop-codex-stop-hook.sh previously called has_pending_background_tasks AND count_pending_background_tasks back-to-back on the short-circuit path. Both wrap list_pending_background_task_ids, so every pending-bg stop was running jq over the transcript twice. Collapse into a single list_pending_background_task_ids call: capture the id list once, use its non-emptiness for the short-circuit decision, and derive the count with `wc -l`. The public helpers has_pending_background_tasks and count_pending_background_tasks stay for other callers. No behaviour change. systemMessage wording and exit codes identical. Validation (all six suites green): - bash tests/run-all-tests.sh -> 1718 passed, 0 failed - bash tests/test-stop-hook-bg-allow.sh -> 39 passed, 0 failed - HOME=/nonexistent/readonly ... -> 39 passed, 0 failed - TZ=America/Los_Angeles ... -> 39 passed, 0 failed - TZ=Asia/Tokyo ... -> 39 passed, 0 failed - CLAUDE_PROJECT_DIR=/tmp/outer-unrelated ... -> 39 passed, 0 failed Version stays at 1.16.0.
1 parent 74671f7 commit 39f09c4

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

hooks/loop-codex-stop-hook.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,9 @@ fi
137137
#
138138
# This check MUST run before any other gate (phase detection, state parsing,
139139
# branch / plan / git-clean / summary / max-iter checks, Codex review).
140-
if has_pending_background_tasks "$HOOK_TRANSCRIPT_PATH" "$LOOP_START_TS"; then
141-
PENDING_BG_COUNT=$(count_pending_background_tasks "$HOOK_TRANSCRIPT_PATH" "$LOOP_START_TS")
140+
PENDING_BG_IDS=$(list_pending_background_task_ids "$HOOK_TRANSCRIPT_PATH" "$LOOP_START_TS" 2>/dev/null) || true
141+
if [[ -n "$PENDING_BG_IDS" ]]; then
142+
PENDING_BG_COUNT=$(printf '%s\n' "$PENDING_BG_IDS" | sed '/^$/d' | wc -l | tr -d ' ')
142143
# Mark the loop as parked; allows the same session to resume later and
143144
# makes the cross-session guard above reachable if the user opens a
144145
# different Claude session in this repo before the bg task completes.

0 commit comments

Comments
 (0)