Repository navigation
fix(autonudge): read a legacy loop's pull request between cycles and while held - #21377
Conversation
UX Review (Opus 5.5) — ⏭️ skippedRevision |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks: the change adds two narrow readers that keep no monitor state, both follow the RFC's § 2.1/§ 2.2 decisions, and both can be reverted cleanly. Notes
[DESIGN-REVIEWED] 28e0b37 Description read[DESCRIPTION-READ] c4b921c13aabb0d6aa45e968126470ec4c57dd2c5731b9aaab1bf8211b049b3d 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@bolichen97 overrode this lane for |
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: |
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: |
f22a9ef to
12376b3
Compare
bolichen97
left a comment
There was a problem hiding this comment.
Needs a maintainer decision before merge. The code looks correct to me, and I found no must-fix defect.
Head reviewed: 12376b3.
What blocks it: the First Principles lane gives BLOCK on this head. The approval-hold RFC is implemented on main, and it records "a held tick fires nothing and arms no timer" and "a hold nobody ends stays held". This PR changes both lines, so a held loop now settles on its own when its pull request merges or closes. The PR body says the maintainer asked for this change. That decision must be recorded by a maintainer (an RFC update merged on main, or a maintainer override on this head). A review cannot record it.
What I checked:
- The self re-arm from inside the held tick is safe:
_cancel_timerrefuses to cancel the running timer task, andhold_tickre-arms only while the loop is still held and registered. _settle_terminalwrites before it publishes, and it re-checks release, retarget and registration under both locks.monitor_terminalis a finished stop reason, so a stalesubject_outcomecannot ride a revival.- No other open PR in my queue touches these files, and main does not contain this change.
Two should-fix items are inline. Neither blocks.
| decided = getattr(settled, "value", settled) or owed | ||
| decided = ( | ||
| getattr(settled, "value", settled) | ||
| or str(getattr(loop, "subject_outcome", "") or "") |
There was a problem hiding this comment.
🟡 The expiry notice now reads subject_outcome, but the monitor_update refusal text does not, so the two endings disagree.
This PR teaches the expiry notice to fall back to subject_outcome when a loop has no monitor. The agent-facing reading of the same fact, in dashboard/session_directive_apply.py (about line 1228 at this head), still reads only monitor.outcome and terminal_pending:
decided = str(getattr(settled, "value", settled) or owed or "")An ungated loop settled while held has no monitor, so decided is "" there. A later monitor_update on that loop then falls to the else branch and tells the agent "its subject was closed without merging", even when the pull request merged. The comment above that line says the two readings use the same fields "so the agent-facing and user-facing endings cannot disagree". After this PR they can.
Why it matters: the agent can tell the user to reopen or abandon a pull request that already merged.
Suggestion: add the same fallback there: ... or str(getattr(loop, "subject_outcome", "") or "") or owed ..., and add one test for an ungated settled loop that receives a max_cycles raise. If monitor_update cannot reach a loop with no monitor, I will withdraw this.
There was a problem hiding this comment.
Fixed in 22afc39. _monitor_update in dashboard/session_directive_apply.py now falls back to the loop's own subject_outcome before owed (settled.value or own or owed), so a settled ungated loop with no monitor reads the same outcome the expiry notice does. New test test_applier_a_settled_legacy_loop_reads_its_own_outcome in test/test_autonudge_stop_auth.py raises max_cycles on such a loop and asserts "already merged" and no "without merging"; it fails with the fallback removed.
| # Settled clean, so a later conflict on this same head is news again. | ||
| svc._subject_wake_fp.pop(loop.id, None) | ||
| continue | ||
| fingerprint = f"{observation.head}:{kind}" |
There was a problem hiding this comment.
🟡 A behind wake has no rate cap, so on a strict-protection repo with a busy base it can replace the operator's interval.
fingerprint = f"{observation.head}:{kind}"The key changes with every head. Where branch protection requires an up-to-date head, each sync cycle pushes a new head. The next base commit makes that head BEHIND, and the next 300 second read ends the sleep again. A loop on a 2 hour interval can then run a model turn about every 5 minutes for as long as the base keeps moving. That spends max_cycles and the runtime budget on a cadence the operator did not choose. The Design lane raised the same point and I agree with it. The work-ledger pull-forward path already has a per-hour cap for this shape.
Why it matters: behind alone does not stop CI the way conflicting does, so the early wake buys little and can cost many turns.
Suggestion: end the sleep early only for conflicting, or route behind wakes through an hourly cap like the pull-forward one. Add a test where the head goes BEHIND after each sync. If you intend behind to wake every time, say so in the spec and I will withdraw this.
There was a problem hiding this comment.
Fixed (thread is outdated against the current diff). The between-cycle read ends the sleep only for CONFLICTING now: subject_reads.py returns early when not observation.is_conflicting, and the wake fingerprint is the head alone, so one conflicting head wakes once. BEHIND never wakes, and the spec (monitor-architecture.md) says why: where protection requires an up-to-date head, every sync is behind again at the next base commit. Covered in test/test_autonudge_subject_reads.py.
12376b3 to
9639a9d
Compare
9639a9d to
22afc39
Compare
22afc39 to
845a69e
Compare
bolichen97
left a comment
There was a problem hiding this comment.
Re-review of head 845a69e. The code looks correct to me, and I have no new findings. A maintainer decision is still needed before merge.
My two earlier findings are fixed on this head:
monitor_updateon a settled ungated loop now readssubject_outcomebeforeowed, so it agrees with the expiry notice.test_applier_a_settled_legacy_loop_reads_its_own_outcomepins it.- A
BEHINDhead no longer ends the sleep. The fingerprint is the head alone, andtest_a_head_behind_after_every_sync_never_ends_the_sleepdrives six synced heads that stayBEHINDand asserts a full 1800 second sleep.
What changed since my last review, and what I checked:
- A held loop that names no pull request now behaves as on main: its held tick arms nothing, a turn's end arms it toward its deadline, and the reconciler skips it.
_held_tick_rearmsis the one predicate for the held tick,_arm_from_deadlineand the reconciler, so the three cannot drift apart. The approval-stall and person-wait tests are back to their main versions, which supports this. _settle_terminalnow hands the held span back to the budget, usinghold_spanandcredit_held_runtimethe same wayrelease_approval_holddoes.
What remains: the approval-hold RFC is implemented on main and records "a held tick fires nothing and arms no timer" and "the cost is a paused row". This PR amends both, so a held loop that names a pull request now reads it and settles on its own. The First Principles lane now gives CONCERNS for the same reason, not BLOCK. A maintainer must record that the amended hold shape is agreed. A review cannot record it.
Two First Principles items I agree with, both optional:
- The budget credit in
_settle_terminalhas no reader I can find. Amonitor_terminalloop is inFINISHED_LOOP_REASONS, so a revival is refused, and the failed-close restore path skips an inactive loop. You can delete the credit, or name the reader. PrObservation.is_conflictingspells the sameCONFLICTING or DIRTYrule as_normalize_mergeability. One shared predicate would keep them from drifting.
No other open PR in my queue touches these files, and main does not contain this change.
|
span=2e70db09a933 fixed
|
bolichen97
left a comment
There was a problem hiding this comment.
Re-reviewed at e6e01f0. Since 07cedbc the change, apart from the rebase, is the held-loop scope.
The earlier point about ungated loops is resolved. _held_tick_rearms now admits only a gated loop that has a monitor, so hold_tick reads nothing for a held gate=False loop and never settles it, and _settle_terminal re-checks that predicate under the locks, so an opt-out landing during the read settles nothing. The subject_outcome field and its projections in the dashboard handler, the websocket observer and the directive applier are gone, since a settled loop always records its outcome on its monitor now. The new tests test_a_held_ungated_loop_survives_its_pull_request_ending and test_an_opt_out_landing_during_the_read_settles_nothing pin both paths. The RFC text in #22165 section 2.1 now states the same exemption, so code and RFC agree. The Opus lane is green on this head.
I also confirmed the GPT lane finding at test/test_autonudge_subject_reads.py:330. test_a_conflict_wake_fires_the_ungated_cycle adds an ungated 1800 second loop with the slept fixture already active, and installs the _read_state stub only after svc.add returns. The patched _nap does not yield, so the timer task armed inside add can reach the real _read_state, which submits gh_pr.fetch_state to an executor before _cancel_timer runs. On a machine with a signed in gh that is a live forge call. Installing the stub before svc.add fixes it.
Still open before merge:
- The RFC in #22165 is not merged, and the First Principles lane blocks on it for both the conflict wake and the held read.
- The GPT lane block above.
- CI on this head is still running.
e6e01f0 to
7f0807e
Compare
|
span=af8c4dac894f fixed
|
bolichen97
left a comment
There was a problem hiding this comment.
Re-reviewed at 7f0807e. Against e6e01f0 the only PR-owned change, apart from the rebase, is in test/test_autonudge_subject_reads.py.
The live forge read I confirmed last round is fixed. test_a_conflict_wake_fires_the_ungated_cycle now installs the _read_state stub before svc.add, then clears _subject_wake_fp and the slept record after cancelling the armed timer, so an early read by that timer neither reaches gh nor suppresses the conflict wake the test asserts. _Reads repeats its last reading, so the early read does not consume the scripted value. The new autouse _no_live_forge fixture patches gh_pr._fetch_core, which both fetch_state paths go through, and fails any test that reaches it.
I confirmed the GPT lane finding on that fixture. It patches through the shared monkeypatch, and docs/system-specs/common/testing-conventions.md rule D11 says an autouse fixture patches only through _floor_monkeypatch. Requesting _floor_monkeypatch in _no_live_forge and using it for the _fetch_core patch is the whole fix; tests that stub _fetch_core themselves keep using monkeypatch.
Still open before merge:
- The RFC in #22165 is not merged, and the First Principles lane blocks on it for the held read and the conflict wake.
- The GPT lane block above.
- Some backend test shards on this head are still running.
7f0807e to
45d8475
Compare
|
span=af8c4dac894f fixed
|
bolichen97
left a comment
There was a problem hiding this comment.
Re-reviewed at 45d8475. Against 7f0807e the only PR-owned change, apart from the rebase, is the _no_live_forge fixture in test/test_autonudge_subject_reads.py. Every other file in the diff is byte-identical to the previous head.
The fixture now requests _floor_monkeypatch and patches gh_pr._fetch_core through it, which is the fix rule D11 asks for. A test's own monkeypatch.undo() can no longer lift the guard, and tests that stub _fetch_core themselves still override it through monkeypatch. The GPT lane reports no blocking findings on this head.
Still open before merge:
- The RFC in #22165 is not merged, and the First Principles lane still blocks on it for the held read and the conflict wake. That sign-off belongs to the maintainers.
- Some backend test shards on this head are still running.
The RFC document itself did not change since my last read, so this PR still matches the text it implements.
|
span=a5fa062e8cc8 needs-a-decision
|
…while held An ungated (gate=false) prompt loop naming one pull request now reads the pull request's state every five minutes while it sleeps and runs its cycle early, once per head, when the head conflicts with its base (BEHIND does not wake it: under up-to-date protection every sync is behind again). The read never suppresses a cycle and never ends the loop on a merged or closed reading, so the gate=false opt-out keeps its promise. A loop held for an unanswered tool approval reads the same state on every held tick: a pull request that merged or closed during the hold settles the loop as monitor_terminal with the usual expiry notice. The reconciler now rescues a held loop whose timer died, since a held loop keeps its own timer.
…mer tests Main's _nosleep fixture now replaces firing's asyncio namespace; the timer's cycle wait lives in subject_reads._nap, so the fixture stubs that seam too.
|
AI-review override not recorded: class |
1 similar comment
|
AI-review override not recorded: class |
|
/ai-review override first-principles 28e0b37 owner-decision: agent: This PR implements RFC #22165; the product owner approved its accepted text in this comment: #22165 (comment) |
Human judgment recorded@bolichen97 recorded a owner-decision release (class
This decision applies only to this commit. A new push requires a new judgment. |
bolichen97
left a comment
There was a problem hiding this comment.
Approving at 28e0b37. All checks pass, no change requests, and the branch is mergeable.
What I checked:
subject_reads.sleep_until_cycleonly shortens an ungated loop's sleep, once per head, when the head conflicts with its base. It never suppresses a cycle or acts on a terminal reading, so thegate=Falsepromise holds.BEHINDdoes not wake it.hold_tickreads only a held gated loop that names one pull request (_held_tick_rearms). A merge or close settles it withmonitor_terminal, persisted before it is applied to the live loop. A refused write leaves the loop held.- The reconciler rescues only those held gated loops. Other held loops keep main's behavior.
gh_pr.fetch_stateis one call with no check board, and it is not published as a monitor reading.is_conflictingreuses the structured monitor's normalizer._subject_wake_fpis cleared inremove_sync. The spec update inmonitor-architecture.mdmatches the code.- No new regex, and no new refusal.
Problem / Motivation
Goal: A babysit loop notices when its pull request conflicts with its base or has ended, even when it is ungated or paused for an approval.
Two gaps in legacy prompt loops (
monitor_start), both seen on live babysit loops:gate=false(what prepare-pr babysit loops use, because they read review comments) keeps the loop off the observation gate entirely, so nothing reads the pull request between cycles. A loop on a 2-hour interval sits up to 2 hours on aCONFLICTINGhead, and GitHub runs nopull_requestchecks on a conflicted head meanwhile.activeand paused indefinitely. One live loop sat held for ~17 hours after its PR had merged.Kyle asked for these behaviours. They are recorded in
docs/request-for-change/rfc-legacy-loop-reads-stops-waits.md(RFC PR #22165, docs only), which this stack rebases onto once it merges; this PR edits no RFC.Why it matters
Babysit loops are how PRs get driven to merge unattended. A conflict that waits out a long interval stalls CI for that whole window, and a loop frozen on a merged PR looks alive in the popover while it will never do anything again — the user has to notice and clean it up by hand.
Not a goal
gh/gitstatus reads run without an approval prompt (that would reopen what fix(security): keep git out of read-only shell auto-approve #20770 closed).gate=falsepromises: an ungated loop is still never suppressed and never ended by a reading of its subject, while it runs or while it is held.monitor_watch), which already observe their subject.What changed (motivation → approach → change)
Both gaps share a cause: the only reader of a legacy loop's pull request is the gate, and neither an ungated nor a held loop reaches it. A gate-only reader cannot be reused, because putting a
MonitorStateon an ungated row turns it into a structured monitor, and the gate's verdicts can suppress or end a loop.So a new owner,
autonudge_service/subject_reads.py, adds two narrow readers that keep no monitor state and use onegh pr viewper read (gh_pr.fetch_state, no check board):_timersleeps throughsleep_until_cycle. For agate=falseloop naming one pull request with an interval over 5 minutes, it sleeps in 5-minute chunks and reads the state between them. A head that newly conflicts with its base (PrObservation.is_conflicting) ends the sleep, once per pull request and head, and the cycle runs through the normal ladder.BEHINDdoes not wake it: with up-to-date protection on a busy base every sync is behind again at the next base commit, so it would re-sync every 5 minutes. Merged, closed, unread, behind and clean readings only keep sleeping.hold_tick. For a held gated loop naming one pull request it reads the state, settles the loop asmonitor_terminalwhen the PR merged or closed (outcome on its monitor, as the gate records it), and re-arms itself one read interval out. Only such a loop owns that timer: every arm of it (a turn ending, a deferred re-arm, a reconciler rescue) goes through_arm_from_deadline, which still sets and saves its cycle deadline but arms it one read interval out, so a release fires within the overdue beat, and the reconciler rescues it when the timer dies. A held ungated loop, or one naming none, reads nothing: its held tick re-arms nothing, a turn's end arms it toward its deadline, and the reconciler skips it, as on main. So a merged or closed pull request never deactivates agate=falseloop or makes it refuse a resume. A settlement hands the held time back to the runtime budget the way a release does.Supporting edits:
probes/gh_pr.py:fetch_stateandPrObservation.is_conflicting(built on the structured monitor's_normalize_mergeability, so one predicate says what conflicts).src/kiro_crew/autonudge.py: the in-memory wake fingerprint map.docs/system-specs/modules/monitor-architecture.mddescribes both readers. The decisions are § 2.1 (a held gated loop reads its pull request and settles when it merges or closes, a held ungated loop reads nothing; supersedes the approval-hold RFC's "While held" and "a held tick fires nothing" text) and § 2.2 (an ungated loop wakes early on a new conflict only) ofrfc-legacy-loop-reads-stops-waits.md.Backwards compatibility
Compatible: no new stored field; every loop that is gated, monitor-backed, names no pull request or sleeps 5 minutes or less sleeps exactly one plain sleep; a held loop still fires nothing and spends no bound, and a held ungated loop behaves exactly as on main.
Removes nothing: no field, key, route or behavior a caller depends on is removed; the reconciler's held-loop skip now applies only to a held loop that is ungated or names no pull request, because a gated one naming a pull request owns a timer.
Tests
test/test_autonudge_subject_reads.py(new, 39 tests):is_conflictingacross mergeability/state pairs;fetch_stateis one core read; the ungated sleep wakes once per head, re-wakes on a new head, after a settled clean read or after a retarget to another pull request on the same head, does not forget a conflict on anUNKNOWNread, never wakes on a head that isBEHINDafter every sync, and only sleeps on merged/closed/unread readings or for a held/inactive loop; a conflict wake fires the cycle through_timer; a held gated loop settles on merged (success) and closed (blocked) with the outcome on its monitor, stays held on an open or unread subject, stays held when the settlement write is refused, is not settled by a read that raced a release or an opt-out togate=false, settles nothing when cancelled while waiting for the store lock, publishes the settlement only after the write lands, and hands the held time back to the budget clock; a held ungated loop survives its pull request merging or closing (reads nothing, stays active and held, re-arms nothing, never rescued); a held loop naming a pull request re-arms its read on a turn ending while keeping a persisted deadline, so a release fires on the overdue beat, and is rescued by the reconciler, while one naming none reads nothing, re-arms nothing from its held tick, is armed toward its deadline on a turn ending and is never a reconciler candidate; read time counts toward the sleep. An autouse guard fails any test in the file that reaches the real forge read, and the conflict-wake test installs its read stub beforeaddarms the timer.test_autonudge_approval_stall.py,test_autonudge_person_wait_hold.py: unchanged from main; their held loops name no pull request, so the held tick still arms nothing.test_autonudge_refactor_contract.py: the new owner module.test_autonudge_subject_reads.pypins the settlement clock and asserts the exact credited value.gate=falseguard (3 tests red), the wake dedupe, the settle revalidation, the publish-after-write order or the read-time accounting each turns a test red.-n0, 10/10 at-n 4 --dist loadgroupwith two co-tenant files, and a shuffled order of 54 ids (seed=8284) green.Manual verification
N/A — unit coverage drives
_timer,hold_tickand the settlement against a realAutoNudgeServicestore; every forge read is scripted, so no test reachesgh. Local gates: the related backend set (32,722 passed; the 5 failures also fail on cleanorigin/mainwith this venv:test_acp_client_more_coverage::TestClientEncodeRefusalDegrades×2,test_app_scaffold::test_symlink_loop_raises_a_clear_error,test_client_bindingstype hints,test_codex_session_mcpadapter), the related frontend set (24,262 passed), isort, flake8, mypy, semgrep, the flake-pattern ratchet and the comment-history gate.Related Issues
No tracking issue, by the maintainer's request; the motivation above is the record.
Pattern harvest
Rule candidate: review-prompt
Pattern: a state machine branch that "fires nothing and arms nothing" also stops observing the world; any hold/pause state should state what still watches the subject and what ends the hold.
Checklist