Commit 7538f74
committed
Silence ambiguous callers and scope transcript scan to this loop
Two blocking findings from the previous review:
[P1] Round 7 dropped the `-n "$HOOK_SESSION_ID"` check from the
cross-session guard to close its own P1. That inverted the
failure mode: any wrapper call (e.g. rlcr-stop-gate.sh
without --session-id) matched the guard forever once the
marker was written, and the RLCR loop never resumed
through the wrapper path.
[P2] list_pending_background_task_ids scanned the entire
session-wide Claude transcript. A long-running background
Agent/Bash that started earlier in the same session --
before the current RLCR loop was created -- counted as
"pending" for this loop. The short-circuit fired forever
for a loop that had no in-scope pending work of its own.
Fixes:
* loop-codex-stop-hook.sh:
- Add an "Ambiguous-Caller Marker Guard" before the cross-
session guard. When bg-pending.marker is present AND
HOOK_SESSION_ID is empty, exit 0 silently (no systemMessage,
no on-disk mutation). The real Claude stop hook always has
session_id populated and remains the only authoritative
driver for parking and cleanup.
- Restore `[[ -n "$HOOK_SESSION_ID" ]]` inside the cross-
session guard. That branch now fires only when both session
ids are non-empty and different.
- Compute LOOP_START_TS via derive_loop_start_iso_ts once and
pass it through every pending-tasks helper call.
* loop-common.sh:
- New derive_loop_start_iso_ts helper: parses the loop dir
basename YYYY-MM-DD_HH-MM-SS and emits
YYYY-MM-DDTHH:MM:SS.000Z for lexical comparison against
transcript timestamps.
- list_pending_background_task_ids gains an optional
since_ts argument. Launch events are filtered by
($since_ts == "" or (.timestamp // "") == "" or
(.timestamp // "") >= $since_ts). Empty since_ts
preserves old scan-everything behavior; events without
.timestamp remain included for fixture / older record
compatibility.
- has_pending_background_tasks and
count_pending_background_tasks pass since_ts through
unchanged.
Regressions in tests/test-stop-hook-bg-allow.sh:
AC-10c refixtured to avoid the AC-10 marker leaking into the
wrapper ambiguous-caller branch.
AC-19 rewritten: empty HOOK_SESSION_ID + marker -> silent
ALLOW, marker and state preserved (inverts Round 7's
"parked" expectation).
AC-21 helper filters a pre-loop launch and keeps an in-loop
launch.
AC-21b derive_loop_start_iso_ts produces the expected ISO-8601
form.
AC-21c end-to-end: pre-loop launch in transcript does not
trigger the short-circuit; Codex runs.
AC-22 wrapper without --session-id + no prior marker +
pending bg -> writes marker, surfaces systemMessage.
AC-22b wrapper without --session-id + prior marker -> silent
ALLOW, marker and state preserved.
Validation:
- bash tests/test-stop-hook-bg-allow.sh -> 37 passed, 0 failed
- bash tests/run-all-tests.sh -> 1716 passed, 0 failed
- HOME=/nonexistent/readonly bash tests/test-stop-hook-bg-allow.sh
-> 37 passed, 0 failed
systemMessage wording unchanged on existing paths. Version stays
at 1.16.0.1 parent 7fb3038 commit 7538f74
3 files changed
Lines changed: 282 additions & 30 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
267 | 267 | | |
268 | 268 | | |
269 | 269 | | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
270 | 295 | | |
271 | 296 | | |
272 | 297 | | |
| |||
290 | 315 | | |
291 | 316 | | |
292 | 317 | | |
293 | | - | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
294 | 327 | | |
295 | 328 | | |
296 | 329 | | |
297 | 330 | | |
298 | 331 | | |
299 | 332 | | |
300 | 333 | | |
| 334 | + | |
301 | 335 | | |
302 | 336 | | |
303 | 337 | | |
| |||
312 | 346 | | |
313 | 347 | | |
314 | 348 | | |
315 | | - | |
| 349 | + | |
316 | 350 | | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
317 | 356 | | |
318 | 357 | | |
319 | 358 | | |
| |||
355 | 394 | | |
356 | 395 | | |
357 | 396 | | |
358 | | - | |
| 397 | + | |
359 | 398 | | |
360 | 399 | | |
| 400 | + | |
361 | 401 | | |
362 | | - | |
| 402 | + | |
363 | 403 | | |
364 | 404 | | |
365 | 405 | | |
366 | 406 | | |
367 | 407 | | |
368 | 408 | | |
369 | | - | |
| 409 | + | |
370 | 410 | | |
371 | 411 | | |
| 412 | + | |
372 | 413 | | |
373 | | - | |
| 414 | + | |
374 | 415 | | |
375 | 416 | | |
376 | 417 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
71 | 92 | | |
72 | 93 | | |
73 | 94 | | |
| |||
77 | 98 | | |
78 | 99 | | |
79 | 100 | | |
80 | | - | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
81 | 106 | | |
82 | 107 | | |
83 | 108 | | |
84 | 109 | | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | 110 | | |
| 111 | + | |
92 | 112 | | |
93 | 113 | | |
94 | 114 | | |
| |||
111 | 131 | | |
112 | 132 | | |
113 | 133 | | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
114 | 138 | | |
115 | 139 | | |
116 | | - | |
117 | | - | |
| 140 | + | |
| 141 | + | |
118 | 142 | | |
119 | 143 | | |
120 | 144 | | |
| |||
142 | 166 | | |
143 | 167 | | |
144 | 168 | | |
145 | | - | |
| 169 | + | |
146 | 170 | | |
147 | 171 | | |
148 | 172 | | |
| |||
0 commit comments