Repository navigation
fix(autonudge): keep a stored loop bound's limit, or stop the loop - #19007
Conversation
An auto-nudge loop whose stored max_cycles or max_runtime_secs is a string, such as "24", raised TypeError out of every timer tick: the cap check compares cycle_count >= max_cycles and runtime_budget_exceeded compares the clock with the raw budget. The loop never ran a cycle and stayed persisted active, while the resume readers cap_reached and budget_elapsed read the same field as no limit. _load repairs every counter the timer compares, but left the two bounds as stored, because repairing one to 0 would quietly remove a cost limit the user typed. The model's stored_bound reads a stored bound. A lossless integer form (an int, a whole float, or a string holding one) is the user's limit, and _load keeps it as that int. Any other value cannot be read as a limit, so the loop fails closed: _load deactivates an active row under structural_terminal, clears its schedule, keeps the value as stored and logs a WARNING naming the field and the value, and update declines a revival while a bound stays unreadable, unless the same call supplies a fresh one. Every version declares both fields int = 0 and every writer stores max(0, int(...)), never null, so only an edited or migrated store reaches this path.
UX Review (Opus 5.5, fork) — ⏭️ skippedRevision |
Design Review (Opus 5.5, fork) — ✅ PASSDesign-level review of Design-Verdict: PASS Check that the open PR #11582 ("invalid bounds" stop reason) does not end up with a second, conflicting fail-closed branch in the same [DESIGN-REVIEWED] e3cc4a0 Description read[DESCRIPTION-READ] dc16354c6c02230859ce376a4ddfa8da6962ebc17be382907cee80144f220315 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, fork) — 🟡 CONCERNSPremise-level review of First-Principles-Verdict: CONCERNS The exact-Decimal string reader ( Not justified as shipped
What this change shipsInventory (5 items) — 3 justifiedIntent: stop a hand-edited or migrated loop bound from crashing every timer tick or silently dropping its limit. FIX.
[FIRST-PRINCIPLES-REVIEWED] e3cc4a0 Description read[DESCRIPTION-READ] 2fdce117dfb374d89196cfe41dd58e53e5176f71ba5e6a13e69b127c3bf943e2 That sha256 names the PR description this verdict read. Recompute it with |
Opus 5.5 Review (fork) — ✅ no blocking findingsReviewed |
GPT 6.1 Review (fork) — ✅ no blocking findingsReviewed Review detailsNo findings. |
A stored loop bound held as a string that is not plain digits was read with float(), which rounds: "1e-400" read as 0, "24.0000000000000001" as 24, and "9007199254740993.0" lost its last digit. Such a string is now read as an exact decimal. It names a limit only when it is finite, non-negative, whole and no larger than the largest float, the range the float reading accepted, so "1e-400" and "24.0000000000000001" stop the loop at load like any other unreadable bound, and "9007199254740993.0" keeps its value. Plain digits are still read by int().
|
Fixed in a second commit, e3cc4a0.
As the fenced note says, the gateway's own writers store ints ( Tests: the cases are added to the two existing tests ( |
iamwhatever
left a comment
There was a problem hiding this comment.
Today a hand-edited or migrated store can hold a non-int max_cycles or max_runtime_secs. That makes every _timer tick raise TypeError, while the resume readers treat the same value as "no limit". This PR fixes the root cause in _load. A lossless integer form ("24", 24.0, " 24 ") is normalized to that int, so the timer, cap_reached and budget_elapsed all compare the same number. Any other value deactivates an active loop under structural_terminal, clears its schedule and keeps the stored value, and update() refuses to revive the loop until a fresh bound replaces it. Because this change can only stop more loops, I tried to find a path that runs a loop without its limit. Every activation path is covered: _load's torn-deactivation resume needs next_due_ts > 0, which this change zeroes; the update revival is refused through unreadable_bound_field; and a fresh bound passed in the same call is applied before the check, so the loop revives under it. I also tried odd strings against _text_bound. "NaN", "Infinity" and "sNaN" fail the is_finite check before any comparison. "1e999999999" exceeds _MAX_TEXT_BOUND. Digit strings over int()'s limit return None, and fractional or negative text returns None. A valid int bound, the only form any writer produces, loads unchanged. First Principles' CONCERNS calls the Decimal reader oversized, but that is a scope nit, not a defect: the reader is correct, and it fails closed. The tests are red on main, all checks are green, base is main, and there are no change requests. — crew-pr-reviewer (deep re-check)
Problem / Motivation
Goal: A loop bound stored in a non-int form either keeps the user's limit as that int, or stops the loop; it never crashes every timer tick and never lets the loop run or resume without its limit.
An auto-nudge loop whose stored
max_cyclesormax_runtime_secsis a string, such as"24", raisedTypeErrorout of every_timertick. The cap check comparesloop.cycle_count >= loop.max_cycles(src/kiro_crew/autonudge_service/firing.py), andruntime_budget_exceededcompares the clock with the raw budget (src/kiro_crew/autonudge_service/model.py). The loop never ran a cycle and stayed persistedactive.The resume readers read the same field differently.
cap_reachedandbudget_elapsedread the bounds through_positive_number, which returns 0 ("no limit") for anything that is not an int or float, the string"24"included. So one stored field gave two answers: a crash in the timer and "no limit" at resume.AutoNudgeService._load(src/kiro_crew/autonudge.py) repairs every counter the timer compares (cycle_count,created_tsand both streak counters) for this same reason. It left the two bounds as stored on purpose: its comment says a malformed cap or budget repaired to 0 "would quietly remove a cost limit the user typed, and persist that". This change keeps that rule: no bound is ever repaired to "no limit".Why it matters
The loop reports itself active and never runs, and nothing says why. The trigger is narrow: the gateway writes both fields as
int(autonudge_service/mutations.py,max(0, int(...))), so only a hand-edited or migrated store reaches this path. It matters because the store is agent-writable and_loadalready treats it as an input boundary for every sibling field.Not a goal
_loadblock, with the same fail-closed rule. This change uses the existingstructural_terminalstop and adds no stop reason the dashboard must render; whichever lands second rebases._load(fix(autonudge): drain admitted mutations through gateway shutdown #9052, feat(autonudge): claim each cycle durably before the turn it claims #10966): they change other parts of it, not the bound or counter repairs; whichever lands second rebases.int.cap_reached,budget_elapsedor the cycle header. After_loadthey read an int on every row that can run.What changed (motivation → approach → change)
Symptom: a string bound crashes every timer tick, while the resume path reads it as no limit (see Tests).
Root cause:
_loadnormalised the counters the timer compares but not the two bounds it compares them with.Change:
autonudge_service/model.py:stored_bound(value)returns the limit a stored bound names, as an int >= 0, or None when it names none. A lossless integer form keeps its limit: a non-negative int, a whole finite float, or a string holding one ("24"," 24 ","24.0"). Anything else (null, a negative or fractional number,nan, a bool, other text, a container) answers None.unreadable_bound_field(loop)names the first bound with no reading._text_bound,autonudge_service/model.py:736). Plain digits are read byint()as before. Any other text is read as adecimal.Decimaland names a limit only when it is finite, non-negative, whole and no larger than the largest float (_MAX_TEXT_BOUND,autonudge_service/model.py:733). A float reading turned"1e-400"into 0,"24.0000000000000001"into 24 and"9007199254740993.0"into 9007199254740992. The first two now answer None, so the loop stops at load like any other unreadable bound, and the third keeps its value. Past the largest float, the float reading gave infinity and answered None; the exact reading keeps that answer, which also stopsint()from building an integer of any size from an exponent such as"1e999999999"._load(autonudge.py): a lossless bound is kept as that int, so_timer,cap_reachedandbudget_elapsedcompare the same number. An unreadable bound fails closed, in the shape of the existing dropped-sentinel stop in the same function: an active row is deactivated understructural_terminal, its schedule is cleared (so the torn-write recovery cannot resume it), the value is left as stored for inspection, and a WARNING names the loop, the field and the stored value. A row that was already stopped keeps its own reason.update(autonudge_service/mutations.py): a revival is declined while a bound stays unreadable, next to the finished-loop refusal, so Play, a reconciler andmonitor_updatecannot run the loop without its limit. A call that brings a fresh bound applies it first, so it revives under that bound._loadcomment states the rule and its reason: a limit the user typed is never repaired to a number nobody chose.docs/system-specs/modules/learn-cron-dashboard.md, "Monitor runtime ceiling": the spec said a persisted budget is left as stored on load. It now says that a budget is still checked againstmonitoring.limitsonly when it is written, how_loadreadsmax_cyclesandmax_runtime_secs, and that every other persisted budget is left as stored.Why
structural_terminal: of the existing stops it is the one that means a deterministic malformed state that re-firing cannot clear, which only a fresh configuration ends. A directive re-arm may displace it, a later pause does not overwrite it, and the dashboard words it "the last cycle could not run". Its comment names a malformed prompt, not a stored bound; #11582's dedicated reason would make that exact.Rejected alternatives:
_loadrule exists to prevent.TypeErrorin_timer: the loop stays active and never fires, only more quietly._timertocap_reachedandbudget_elapsed: a lossless"24"would read as no limit and the user's cap would be lost.Backwards compatibility
Compatible: an int bound, the only form the gateway writes, loads unchanged and is not logged; a missing key still takes the dataclass default 0 (
test_a_numeric_bound_loads_unchanged).Compatible: a bound stored in a lossless non-int form keeps its limit, where the timer crashed and the resume readers read no limit before (
test_a_bound_stored_in_a_lossless_form_keeps_its_limit).Compatible: a loop whose stored bound has no lossless integer reading is stopped at load instead of crashing every tick or running without its limit (the fail-closed rule: a limit nobody can read is never treated as no limit); re-arming, or reviving with a fresh bound, runs it again. A stored
nullis one of those values, and no version has written one.Reader: src/kiro_crew/autonudge.py:AutoNudgeService._load -- release -- no writer has ever stored null for either bound: both fields are declared
int = 0from the first commit through v0.6.0 and every release branch,addandupdatestoremax(0, int(...))(autonudge_service/mutations.py),Noneinupdatemeans "unchanged" and is never assigned, and the store writes rows only throughasdict(loop)(autonudge_service/store.py); an omitted key still takes the default 0, no limit.Removes nothing: no function, field or stop reason is removed.
Tests
New tests in
test/test_autonudge_start_failures.py, besidetest_a_malformed_persisted_counter_is_normalised_at_load, with a_reloaded_with_boundhelper that arms a loop, rewrites the stored field and reloads:test_a_bound_stored_in_a_lossless_form_keeps_its_limit("24"," 24 ",24.0,"3600","3600.0","9007199254740993.0","3.6e3"): loads as the int, stays active,budget_elapsedreads a lossless budget as spent at its end, and_timerruns without raising.test_a_cycle_cap_stored_as_a_string_fires_and_stops_at_its_cap:"2"fires twice, then stops withcycle_cap, andcap_reachedagrees.test_an_unreadable_bound_stops_the_loop_at_load_and_keeps_the_value("abc",None,-5,2.9,True,[],nanfor the budget, and the strings"1e-400","24.0000000000000001"and"1e400"): inactive understructural_terminalwith no schedule, the value kept as stored, a WARNING naming the field and the value.test_resume_does_not_revive_a_loop_with_an_unreadable_bound(both fields):update(active=True), with and withoutfresh_run, leaves it stopped and fires nothing;update(active=True)with a fresh bound revives it under that bound.test_a_numeric_bound_loads_unchanged(control).Red, the whole file against the unchanged source on main (7612507), in 3 of 3 runs: every new test case fails except the control, and the 34 existing tests pass:
The second commit's cases against the first commit's source (b91714a, this file copied in), in 3 of 3 runs: 3 failed, 54 passed.
"9007199254740993.0"loads as 9007199254740992 (assert (9007199254740992 == 9007199254740993)), and"1e-400"and"24.0000000000000001"load as 0 and 24 and leave the loop active."3.6e3"and"1e400"pass on both commits.Green on this branch:
pytest -n 0 test/test_autonudge_start_failures.py: 57 passed in 3 of 3 runs; the 27test/test_autonudge*.pyfiles other thantest_autonudge_authz_cov80.py, which builds paths under the home directory, run serially: 1582 passed.scripts/check_black_formatting.py,COMMENT_HISTORY_BASE_REF=origin/main scripts/check_comment_history.pyand./scripts/docs-lint.sh: all exit 0.Manual verification
Ran the new tests against the unchanged source (red, above) and on this branch (green), with
pytest -n 0. They writeautonudge.jsonunder a temporary directory and driveAutoNudgeService.start,_load,_timerandupdatein-process with the idle wait collapsed; no gateway, model or network.Related Issues
Related: #16353 (recorded why
_loadleaves the bounds as stored), #8980 (the agent-writable store), #11582 (the dedicated "invalid bounds" stop, open), #9052 and #10966 (open, other edits to_load).Pattern harvest
Rule candidate: review-prompt
Pattern: a load boundary that repairs the counters a comparison reads but not the limit it compares them with; a limit that cannot be read must stop the work, not lift the limit.
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)