Repository navigation
fix(monitor): wake the session once when its watched PR merges or closes - #37776
Conversation
UX Review (Opus 5.5) — ⏭️ skippedRevision |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks. The pin removed for "a dashboard loop does not pay for one" is reversed openly: the RFC is amended with its reason and the observed misses, and Notes
[DESIGN-REVIEWED] 15456d9 Description read[DESCRIPTION-READ] 9e94d7809218509c0d3f37612fd0229ffb2b671c1f5837cb65ade0d043a78bea That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
First Principles Review (Opus 5.5) — ✅ human override accepted@iamwhatever overrode this lane for |
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
Opus 5.5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
2772e94 to
1ce62bd
Compare
|
Fixes on head 1ce62bd (one amended commit) for the reds on 2772e94:
|
1ce62bd to
df9a206
Compare
|
Head df9a206 (same single commit, amended) for the reds on 1ce62bd:
|
df9a206 to
b01ab2b
Compare
|
Head b01ab2b (single commit, amended) for the reds on df9a206:
|
b01ab2b to
c94c8ba
Compare
|
Head c94c8ba (single commit, amended) for the GPT 6.1 finding on b01ab2b (final wake marked delivered before provider admission):
|
A dashboard PR loop settled on the merge with only the user's bell, so the agent waiting on it was never woken; every gated loop with a pull-request reading now gets one final turn opening with the result. monitor_update on such an ended loop is refused in the same call instead of acknowledged.
c94c8ba to
15456d9
Compare
|
Head 15456d9 (single commit, amended) for the GPT 6.1 finding on c94c8ba (final-wake row written before admission):
|
|
/ai-review override first-principles 15456d9 product-shape: A watched PR's merge or close wakes its session once on every surface; rfc-gated-pr-poll-loops §3.4 is amended in this PR by owner decision. |
|
AI-review override not recorded: |
|
/ai-review override first-principles 15456d9 owner-decision: owner decision #37776 (comment) : a watched PR's merge or close wakes its session once on every surface; rfc-gated-pr-poll-loops section 3.4 is amended in this PR. |
Human judgment recorded@iamwhatever recorded a owner-decision release (class
This decision applies only to this commit. A new push requires a new judgment. |
Code change approver recommendation: A person should decideWhy: the decider thinks the change is probably fine but estimates a 14% chance that this change introduces a defect, above the 12% limit for approving on its own. Both defects are fixed. RC1: the gate's terminal branch now marks a final turn as owed for every gated PR loop (it was channel-only); a dashboard loop with no PR reading still settles immediately with the bell. The existing surface-agnostic delivered-terminal settlement in firing.py then settles the loop and emits the bell. The dashboard fire counts the final turn as delivered only once the runner accepts it (admission future plus a synthetic completion hook with no side effects), and a turn that never starts falls back to BUSY so the debt stays owed. notify_turn_complete returns early for inactive loops, so settled loops are never re-armed. RC2: the in-band preflight refuses monitor_update only where the turn boundary is already certain to refuse it: a gated loop stopped with monitor_terminal is always denied in _monitor_update, and a structured monitor with an outcome makes _update_monitor_admitted return None. Retained user stops keep the existing refusal, and monitor_start is unchanged. The RFC is amended openly with an owner-decision override, no docs/decisions entry covers the old behaviour, and the new tests cover the gate, the fire, a busy session, close-then-merge, unstart An automated recommendation, not a review: a maintainer still decides. It approves on its own only when the estimated chance of a defect is at most 12% and the change has at most 400 changed lines. Decider v3c (217fe607) · commit |
KiroCrewCaptain
left a comment
There was a problem hiding this comment.
Approving. On this head the review checked these points. The gate records the owed final turn durably and rolls it back if the write fails. A dashboard final turn counts as delivered only once the runner accepts it. The monitor_update refusal fires only where the turn boundary always refuses. The review also reverted the gate condition and the in-band refusal, and the new tests went red each time. No security, sandbox or approval boundary changes.
Done well: an owed final turn that times out or is refused while it is being prepared keeps its debt, so the watch never settles on a turn nobody received.
The design is signed off under the standing maintainer sign-off for changes by team members.
Optional:
- The
[monitor finished]opener is not yet in the goal-conductor SKILL.md automation-opener lists (around lines 244 and 710) or in docs/system-specs/common/injected-messages.md. A conductor may read its final wake as a turn a person typed. terminal_wake_line(autonudge_service/model.py:880) falls back to "merged" or "closed without merging" for any kind of watch. A channel work-ledger watch with no reading would report that its own session key "closed without merging". Neutral wording for watches that are not PRs, plus a test for the empty-note case, would close this.- The Backwards compatibility section says channel loops are unchanged. Their final turn now opens with the new line, and a later, different ending replaces the owed debt.
…ses (#37776) A dashboard PR loop settled on the merge with only the user's bell, so the agent waiting on it was never woken; every gated loop with a pull-request reading now gets one final turn opening with the result. monitor_update on such an ended loop is refused in the same call instead of acknowledged. Co-authored-by: Joe Guo <zejiangg@amazon.com> (cherry picked from commit 944c87d)
Problem / Motivation
Goal: a session that watches a pull request with
monitor_startis woken when that pull request merges or closes, andmonitor_updatenever acknowledges a change to a loop that has already ended.Two defects, both measured on a dashboard host over 2026-11-14/15 (seven misses on five worker sessions):
autonudge_service/gate.py, theif terminal:block) gave only a channel loop (Slack/Discord) the owed final turn. A dashboard loop deactivated on the tick that read MERGED/CLOSED and emitted only the user's bell notice ("No action needed for this watch"), so the agent got no turn. A worker waiting on its PR's merge never reporteddone; its conductor found out on its own 15-minute patrol, or later. Seen on test: expect the kirocrew.step span in the otlp wire tests #37171, refactor(work-ledger): keep only the critical create refusal from host pressure #37164, refactor(goal-conductor): show remote dispatch only while its preview is on #37612, fix(crew): close the two conductor-mode rule gaps #37617, docs(decision): every Bot thread tracks in the ledger #37611, fix(mate): every Bot thread tracks in the work ledger #37676 (stop logreason=monitor_terminal, nofired cycleline after the merge).monitor_updateon an ended loop answered "update requested". The in-band preflight (mcp_tools/control_parts/monitor.py,_arming_preflight_refusal) let a SUCCESS outcome through because SUCCESS is re-armable formonitor_start. But the turn boundary is certain to refusemonitor_updateon that loop (session_directive_apply_monitor.py: "its subject already merged ... arm monitor_start again only for a NEW subject"). That refusal lands after the turn as a transcript notice the model does not act on, so the agent believed it was watching its next PR while nothing was. Seen twice: one worker retargeting from test: expect the kirocrew.step span in the otlp wire tests #37171 to feat(conductor): look first, grill the plan, correct mid-round, and check every open item hourly #37030, and one from docs(decision): every Bot thread tracks in the ledger #37611 to fix(mate): every Bot thread tracks in the work ledger #37676 (gateway logsession-directive DENIED at apply ... kind='monitor_update').Why it matters
Every long task that hands a worker a PR to drive to merge relies on this wake. Without it the worker idles until a person or the conductor notices, and the conductor's acceptance waits on a
donereport that never comes.Not a goal
monitor_watchcontroller path (monitoring/decision.py), which already has the opt-inwake_on_terminal; unchanged.pr-readiness-sweep.yml), not this code.monitor_updaterevive an ended loop for a new target.What changed (motivation → approach → change)
src/kiro_crew/autonudge_service/gate.py: the terminal branch no longer splits onis_channel_key. Every gated loop records the owed turn inmonitor.terminal_pending(plus a one-linemonitor.terminal_notebuilt from the typed reading), fires, and settles through the existing delivered-terminal path (firing.py→_settle_delivered_terminal) once the turn lands. A busy session leaves the debt for the next tick, as it already did for a busy channel thread. The bell notice is unchanged; it is sent at settlement.src/kiro_crew/monitoring/models.py: newMonitorState.terminal_note: str = ""(older records read""; the fire then falls back to target + outcome).src/kiro_crew/autonudge_service/model.py:terminal_wake_line(loop)→[monitor finished] PR owner/repo#N merged at <ts>, head <sha12>. This is the last wake; the loop stops after this turn.(closed without mergingfor a close).src/kiro_crew/slack/gateway_runtime/nudge_dashboard_fire.py: an owed final turn puts that line first in both the prompt and the transcript row, and reports delivered only once the turn STARTS (it waits on the same admission future a structured wake uses), so an unattended turn that times out behind the background cap keeps the debt instead of settling the watch unsent.src/kiro_crew/slack/gateway_runtime/nudge_channel_fire.py: the Slack thread and DM (Discord/Webex) fires put the same line first, so the final turn reads the same on every surface.terminal_wake_lineis re-exported throughkiro_crew.autonudgeand reached through the gateway facade.src/kiro_crew/session_summary.py:[monitor finished]joins_INJECTED_PREFIXES, so the final wake is read as automation, not a human turn, in session summaries.src/kiro_crew/mcp_tools/control_parts/monitor.py: formonitor_update, an inactive loop that ended on its subject (a gated loop stoppedmonitor_terminal, or a structured monitor with an outcome) is refused in the same call:monitor_update: NOT applied — this session's loop already ended: ... To watch a new subject, call monitor_start in this turn. No directive is emitted.monitor_startis unchanged: it already replaces such a loop, and that is the remedy the refusal names.monitor_starttool description: "A merge or a close ends the watch rather than waking you" → "A merge or a close wakes you ONE last time, the turn opening with the result (...), then ends the watch; report from that turn."docs/request-for-change/rfc-gated-pr-poll-loops.md(statusimplemented) recorded "On a dashboard loop, a merge or close settles the loop with the bell notice and no turn" in § 3.4, the § 3.2 table and § 7 Risks. Those three places now state the new behaviour, and § 3.4 carries an "Amended:" paragraph with the reason. The matching lines in thebabysitskill,kirocrew-prepare-pr/references/rationale.mdandlearn-cron-dashboard.mdare updated, and four code comments that said "channel loop" for the owed-turn rule now say "gated loop".Backwards compatibility
Changes behaviour for every dashboard gated PR loop: one more delivered turn per watch, at its merge or close. Channel loops are unchanged. A stored loop whose subject already ended is not revisited. A record from an older build has no
terminal_note; it reads""and the line falls back to target + outcome.Takes away: the turn-free dashboard settlement, and the "requested" ack from
monitor_updateon an ended loop.Reader: src/kiro_crew/autonudge_service/firing.py:_fire_cycle -- gateway -- moves
terminal_pendingtoterminal_deliveredon delivery and settles; already ran for channel loops, now for all;test_a_merge_wakes_the_dashboard_session_once_then_ends_the_watchReader: src/kiro_crew/slack/gateway_runtime/nudge_wiring.py:_notify_nudge_expired -- bell -- reads
terminal_pendingas terminal news; unchanged contractReader: src/kiro_crew/dashboard/session_directive_apply_monitor.py -- turn boundary -- still refuses the same update; the preflight now says so first;
test_monitor_update_on_an_ended_loop_is_refused_at_call_timeTests
New
test/test_monitor_terminal_final_wake.py, shaped on the observed misses:test_a_merge_wakes_the_dashboard_session_once_then_ends_the_watch[worker|conductor|bot]: worker slot, conductor slot, and a Bot's dashboard thread (member_slot_key) — exactly one fire, it carriesPR acme/widgets#37164 merged at <ts>, head <sha12>., then the loop is inactive with outcome SUCCESS.test_a_busy_session_keeps_the_final_turn_owed,test_a_close_without_merge_says_so_and_settles_blocked,test_no_line_when_nothing_is_owed.test_the_final_dashboard_turn_opens_with_the_result[worker|conductor|bot]: through_fire_dashboard_nudge, the nudge row starts with[monitor finished] PR ....test_a_final_turn_that_never_starts_is_not_reported_delivered: the background queue closes the turn unstarted, and the fire answers not-delivered.test_slack_gateway_coverage.py::TestFireDiscordNudge::test_an_owed_final_turn_opens_with_the_result: a Bot DM's final turn opens with the result.test_monitor_update_on_an_ended_loop_is_refused_at_call_time,test_monitor_update_on_an_ended_structured_monitor_is_refused: no directive, namesmonitor_start. Controls:test_monitor_start_still_replaces_the_ended_loop,test_monitor_update_on_a_live_loop_still_emits.test_session_summary_extract.py::test_a_monitors_final_wake_is_automation.Changed:
test_prepare_pr_gated_poll_loop.py(test_a_merge_or_close_ends_the_loop_after_one_turn),test_monitor_start_ack.py(new description sentence),test_autonudge_settlement.py(test_every_loop_gets_a_final_turn_before_it_settlesreplaces the dashboard-quiet case;test_a_terminal_subject_stops_the_loop_after_one_turn),test_review_repair_routing_skill.py(new babysit sentence).-n 2): the 15 autonudge / monitor / wake / gateway-nudge test files touching these modules, 631 passed; RC2 tool files again after the last edit, 122 passed. After the review fixes: 19 gateway-fire / autonudge / monitor files 1033 passed, facade contract files 697 passed (mirror guard re-run green after the manifest line). Last push: every test file naming the touched paths (140 files) plus the summary tests, 6549 passed. Mutation: putting back the channel-only condition fails all 4 RC1 tests in the new file, and disabling the new refusal fails both RC2 refusal tests.Manual verification
N/A — unit coverage of the gate, fire and tool paths; no running gateway was touched.
Related Issues
Fixes #37774
Sibling sweep
Swept: git grep -n "is_channel_key(loop.slot_key)" -- src/kiro_crew/autonudge_service/
Sibling: src/kiro_crew/autonudge_service/firing.py:813 -- not affected -- channel self-re-arm; a dashboard loop re-arms from the turn-complete hook
Sibling: src/kiro_crew/autonudge_service/subject_reads.py:_settle_terminal -- not affected -- a held loop delivers no turn, so it still settles at once on every surface
Pattern harvest
Not generalizable: the turn-free settlement was one recorded choice in one branch (rfc-gated-pr-poll-loops § 3.4), amended here; the in-band preflight already exists for the other certain refusals and only missed this one case.
Known limits
Checklist
Contribution License Agreement
Contributions are accepted under the project's Apache-2.0 license; see the Licensing section of CONTRIBUTING.md.