Skip agent-fired prompts so they don't count as bedtime violations#2
Open
ColinToft wants to merge 1 commit into
Open
Skip agent-fired prompts so they don't count as bedtime violations#2ColinToft wants to merge 1 commit into
ColinToft wants to merge 1 commit into
Conversation
Without this, every wakeup-fired scheduled task or background-task
notification that lands while the user is asleep counts as a violation
the next morning, polluting the count and the escalation tone.
Five signals, any one is enough:
1. Prompt starts with <task-notification> (Monitor / agent completions).
2. Prompt starts with <bash-stderr> (background bash stderr).
3. Transcript has a matching user entry with isMeta=true. Race-y —
the entry may not be committed at hook-fire time.
4. Most recent non-user entry is type=system,
subtype=scheduled_task_fire. Helps when signal 3 loses to the
transcript-write race.
5. Some prior assistant tool_use has an `input.prompt` matching the
current prompt text (ScheduleWakeup, CronCreate, /loop, …). The
tool_use is committed long before the wakeup actually fires, so
this is race-free even when 3/4 miss.
Verified against a real transcript where signals 3/4 missed (the
user-entry write hadn't landed when the hook ran, and the most recent
non-user entry was a stop_hook_summary). Signal 5 catches it cleanly
by matching the prompt text against the ScheduleWakeup tool_use that
queued it hours earlier.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Without this, every wakeup-fired scheduled task or background-task notification that lands while the user is asleep counts as a violation the next morning, polluting the count and the escalation tone of the next day's reminders.
The hook now skips agent-fired prompts via five layered signals — any one is sufficient:
<task-notification>(Monitor / agent completions).<bash-stderr>(background bash stderr).isMeta=true(scheduled wakeups,/loopautonomous loops, local-command caveats). Race-y — the entry may not be committed to the transcript file at hook-fire time.type=system, subtype=scheduled_task_fire. Helps when signal 3 loses to the transcript-write race.tool_usehas aninput.promptmatching the current prompt text (ScheduleWakeup,CronCreate,/loop, …). Race-free because thetool_useis committed when the assistant turn ends, long before the wakeup actually fires.Why signal 5 matters
Real-world failure last night: a
ScheduleWakeupqueued at 19:24 fired ~2 hours later at 21:55, while I was asleep. The wakeup-fired prompt:isMeta=trueset on its eventual transcript entry, but the entry hadn't been committed when the hook ran (signal 3 missed).stop_hook_summary, notscheduled_task_fire(signal 4 missed).Signal 5 caught it cleanly by matching the prompt text against the
ScheduleWakeuptool_use that had queued it hours earlier — that tool_use was reliably in the transcript by the time the wakeup fired.Verified
bash -nsyntax check passes.🤖 Generated with Claude Code