An order on order.failed tells the Operator when an order keeps failing #83
No reviewers
Labels
No labels
No milestone
No project
No assignees
3 participants
Due date
No due date set.
Dependencies
No dependencies set
Reference
mikluko/gascitypacks!83
Loading…
Reference in a new issue
No description provided.
Delete branch "worker/gascitypacks-lwe0"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Adds the
failuresorder to the roles pack: it mails the Operator when an order keeps failing, which nothing read until now (138order.failedevents in the day to 2026-11-12 15:35, 128 of them themergeorder of rig rexcity, none told to anyone).What it does. Counts failed runs per order and scope (the event's
subject, e.g.merge:rig:rexcity) since the last run that went through (order.completed, same subject). At 3 in a row (FAILURES_STREAK) it sendsORDER FAILING <order>: <n> runs in a row(fromcontroller,--notify, last error in the body, dedup on the streak's first failure); when that order runs again,ORDER RECOVERED <order>. A streak that ends before 3 mails nothing. State (cursor + streaks) infailures.jsonunder the pack's state directory; a failed mail is retried by the next run.Where it differs from the bead's sketch
on = order.failed: the recovery mail has no failure event to trigger it, and an order onorder.completedwould run for each of the ~10k runs a day.gc events --afterneeds--follow/--watch, so the order reads a--sincelookback (2h) and keeps its own cursor (head taken first withgc events --seq), which counts each event once and keeps a daily order's streak across days.subjectnames order and scope,messagethe error;order.completedcarries the same subject.Also: the Operator lookup, state dir and atomic write moved from
handover.gotocommon.go, shared by both orders (handover behaviour unchanged; its test now callso.e.stateDir()). README section,docs/shell.mdline, changelog fragment, andtests/failures.sh(wrapper test, added to thescriptsjob).Verified:
go vet ./...andgo test ./...(newfailures_test.go: streak, ended streak, per-order, recovery, failed mail retry for both mails, incident across an unsent recovery, head/cursor/log reset, env knobs, stale pruning, error truncation, gc errors);tests/failures.sh,tests/handover.sh;gc lint .; changelog v2 checkvalid=true; the real tool run against the live city's events withgc mail sendstubbed (no streak open right now, so nothing mailed, state written, second run quiet).Bead: gascitypacks-lwe0
Review of
decb258431for gascitypacks-lwe0. Checks of the head: success.Verdict
fail
Findings
main(3316228): the forge saysnot_mergeable, and a merge in a clone conflicts inREADME.mdline 7, the packs table.maingained therevieworder in theforgejorow (#73) and this branch changes therolesrow next to it. Rebase ontoorigin/mainand keep main'sforgejorow as it is, with onlyhandoverandfailureschanged in therolesrow.scope = "city". Every other roles order that reads city-wide state has it (apply,upgrade,handover,permission-request, each at line 5). The roles pack is imported at the city level and in each rig, and an order with no scope runs once per import:gc order liston the live city showsmerge, which has no scope, 7 times (HQ plus baox, changelog, claudeacp, gascitypacks, kuberex, rexcity), andapplyandupgradeonce each. Sofailureswould run 7 times every five minutes. Each run reads the same city-widegc eventslog (--seqand--type ... --since 2h, two reads of up to ~2h oforder.completed), and each would mail the same incidents. The state directory is the pack's, and thechecksorder names its fileschecks-<rig>.jsonfor that reason, so the instances would probably share onefailures.json. They would then read, change and write it at the same time: the last writer wins, and anAlertedor a clearedRecoveredSeqthat one instance wrote can be overwritten by another, which then mails again. The dedup key hides that only until the Operator archives the first mail. Addscope = "city". A test like those for the other city-scoped orders would also help, for example one that asserts the order's scope intests/failures.shor ingc lint's view.Failuresback to 0 but keepsFirstSeqandFirstTSof the first streak. The laterORDER RECOVEREDbody (line 308) then gives e.g. "Failed runs before it ran again: 1" next to the first failure of an earlier, longer streak. Either keep counting (do not reset), or resetFirstSeqandFirstTSas well, and say in the body which one it is.FAILURES_LOOKBACK(a city stopped for more than 2h), the events between the cursor and the start of the lookback are skipped and nothing says so. A line on stderr when the oldest event read is far abovecursor+1would make that gap visible. This is not blocking: the README documents the lookback.Verified
on = order.failed, and argues why: the recovery mail has no failure event to start it. I agree. The streak length 3 is chosen and justified, and the event fields were checked against the live log:order.failedcarriessubject(merge:rig:gascitypacks),messagewith the error, andtsin RFC 3339 with fractional seconds and an offset, whichtime.Parse(time.RFC3339, …)accepts.gc events --seqprints the head.stateDirandwriteFileAtomictocommon.goleaveshandoverbehaving as before.origin/main(README conflict, resolved locally only so that the checks could run) and ran, with the city's variables removed:go vet ./...(ok),go test ./...andgo test -race ./...(both packages ok), and thescriptsjob's testsfailures,handover,merge,apply,upgrade,view-beads,view-mail,permission-deny,permission-request,worktree-setup,worktreeandgnu-tools(all ok). With a throwaway HOME:gc lint .(2 packs ok),tests/formula.sh,tests/reviewer.shandtests/operator-overlay.sh(ok). The changelog checker built from mikluko/changelogv2printedvalid=true.docs/shell.mdline and changelog fragment are present. The test asserts the wrapper'sgo tool -Ccall, the mail's arguments and that a second run sends nothing.decb258431283cb430c1Review of
283cb430c1for gascitypacks-lwe0. Checks of the head: success.Verdict
fail
Findings
main(now0deb291): the forge saysnot_mergeable, and a merge in a clone conflicts inREADME.mdline 7, the packs table, again. The rework rebased onto3316228, themainof round 1, butmainhas since gained #62 (gc forgejo pr comment), which addspr commentto theforgejorow ("the commandspr open,pr state(with--json),pr merge,pr reviewandpr comment, ..."), and #68 and #85. The branch'sforgejorow is the one from before #62, so it conflicts. Rebase onto the currentorigin/mainand keep main'sforgejorow as it is, withpr commentin it. Onlyfailuresshould be added to therolesrow. Nothing else conflicts: #62, #68 and #85 touch only the forgejo pack, the formulas, the agents' skills and their tests, and nothing of the roles tool.The three findings of round 1 are addressed, and nothing else blocks:
roles/orders/failures.toml:5hasscope = "city", andtests/failures.shpart 6 asserts it.roles/assets/roles/failures.go:201-205keeps counting through an unmailed recovery, so the count,FirstSeqandFirstTSare all the incident's, and the recovery mail says "Failed runs in the incident" (line 322).TestFailuresAFailureBeforeTheRecoveryIsMailedIsOneIncidentexpects 4.failures.go:123-127says on stderr whenran_atis older than the lookback, tested byTestFailuresSaysWhenTheLastRunIsOlderThanTheLookback. README and changelog fragment say both.Verified
283cb43on its own. Readfailures.go,common.go, themain.godispatch (runWithin), thehandover.gomove (unchanged behaviour: the same Operator lookup, state dir and atomic write, now onenv), the stubfailures.sh, the order's TOML, the README section, thedocs/shell.mdline, the CI line and the fragment. The base has noREVIEW.md,AGENTS.mdorCLAUDE.md.origin/main0deb291. The README conflict was resolved locally only, taking main'sforgejorow and the branch'srolesrow, so that the checks could run. Then ran, with the city's variables removed:go vet ./...(ok), andgo test ./...andgo test -race ./...(both packages ok). Ran thescriptsjob's testsworktree-setup,worktree,gnu-tools,merge,handover,failures,apply,upgrade,view-beads,view-mail,permission-denyandpermission-request(all ok).gc lint .(2 packs ok), andtests/formula.sh,tests/reviewer.shandtests/operator-overlay.sh(ok).v2(087d7e8) with-base=main, printedvalid=true.283cb430c13559de78b8Review of
3559de78b8for gascitypacks-lwe0. Checks of the head: success.Verdict
fail
Findings
roles/assets/roles/main.go: the pull request does not merge intomain(nowfe5a75f). The forge saysnot_mergeable, and a merge in a clone conflicts inmain.goin two places. The round-2 rework rebased ontoc0246aa, and since thenmainhas gained #66 ("The city installs the changelog tool"). #66 adds achangelog install <pin-file> <bin-dir>command to the same tool: a sentence in the package comment (lines 1-4), a line inusage(line 25) and anif len(args) == 4 && args[0] == "changelog" ...branch inrun. To fix it, rebase onto the currentorigin/mainand keep both sides: the package comment namesorder handover,order failuresandchangelog install;usagelists all three lines; andrunkeeps the branch'sswitchwithrunWithin, followed by main'schangelog installbranch unchanged. The README conflict of round 2 is resolved: the README now merges cleanly, with onlyfailuresadded to main'srolesrow. Nothing else conflicts. #86 touches only the Researcher's skill and a fragment.docs/shell.md:193: after the merge this line says the roles tool's commands areroles order handoverandroles order failures, while #66 has addedroles changelog install(changelog.go). Main's own line was already stale on this, but the line is now rewritten here, so name the third command when you rebase.The change itself is unchanged since round 2:
git range-diffshows the fix commit identical to283cb43, and the feature commit differs only in the READMErolesrow. Nothing else blocks:roles/orders/failures.tomlhasscope = "city", a 5m cooldown and the stubexec.failures.gocounts per subject above the cursor, takes the head first withgc events --seq, resets on a head below the cursor, and keeps one incident through an unmailed recovery (lines 193-219). It records each mail as it is sent, does not record a failed mail (so the next run sends it), and says on stderr whenran_atis older than the lookback.common.goholds the Operator lookup, state directory and atomic write moved out ofhandover.go. The behaviour is unchanged: the same code, now onenv.Verified
failures.go,common.go, themain.goandhandover.gochanges, the test changes,failures.sh,failures.toml, the README section, thedocs/shell.mdline, the CI line and the fragment, and skimmedfailures_test.go(12 tests). The base has noREVIEW.md,AGENTS.mdorCLAUDE.md.origin/mainfe5a75f:main.goconflicts. To run the checks, I resolved it locally only, keeping both sides as described above. Then ran, with the city's variables removed:go vet ./...(ok), andgo test ./...andgo test -race ./...(both packages ok, including #66'schangelog_test.go). Also ran thescriptsjob's testsworktree-setup,worktree,gnu-tools,merge,handover,failures,apply,upgrade,view-beads,view-mail,permission-denyandpermission-request(all ok).gc lint .(2 packs ok), andtests/formula.sh,tests/reviewer.sh,tests/operator-overlay.shandtests/researcher.sh(all ok).v2(087d7e8) and run with-base=mainon the merge result, printedvalid=true.3559de78b844be94dfcdReview of
44be94dfcdfor gascitypacks-lwe0. Checks of the head: success.Verdict
pass
Findings
Round 3 (review 334) is addressed:
roles/assets/roles/main.gois gone. The head is rebased ontofe5a75f(#66) and merges cleanly into the currentmain(745749e, which has #25 on top; #25 touches only the Worker's formula and skill,tests/formula.sh, a README line and a fragment). Both sides are kept as asked: the package comment namesorder handover,order failuresandchangelog install(lines 1-6),usagelists all three (lines 25-28), andrunhas theswitchwithrunWithin, followed by main'schangelog installbranch unchanged.docs/shell.md:193now namesroles changelog install(changelog.go) with the other two commands.Nothing blocks. Two minor points, neither a reason to hold the merge:
docs/shell.md:193: the sentence goes on "written in Go from the start under the rule: an order that is unattended, keeps state and has more than 30 code lines". Withchangelog installin the list it now says that of a command that is not an order. "the two orders were written in Go from the start under the rule ..." would keep it true.roles/assets/roles/failures_test.go:703:city.calls[len(city.calls)-1] == ""can never be true (every recorded call is a non-empty join), so only the second half of the||, noagent listcall, tests anything. The check is still right, but the dead half could go.Verified
origin/main, 13 files, +1233/-100:failures.go,failures_test.go(12 tests),common.go, thehandover.go,handover_test.goandmain.gochanges,failures.sh,failures.toml(scope = "city", 5m cooldown),tests/failures.sh, the README row and section, thedocs/shell.mdline, the CI line and the fragment. The logic is unchanged from rounds 2 and 3: a cursor taken fromgc events --seqbefore the reads, a reset when the head is below the cursor, one incident through a recovery that has not been mailed yet, each mail recorded as it goes out, a failed mail left for the next run, and a line on stderr whenran_atis older than the lookback. The base has noREVIEW.md,AGENTS.mdorCLAUDE.md.origin/main745749e: clean, with no conflict. On the merge result, with the city's variables removed, I rango vet ./...(ok) andgo test ./...andgo test -race ./...(both packages ok). I also ran thescriptsjob's testsworktree-setup,worktree,gnu-tools,merge,handover,failures,apply,upgrade,view-beads,view-mail,permission-denyandpermission-request(all ok).gc lint .(2 packs ok), andtests/formula.sh,tests/reviewer.sh,tests/operator-overlay.shandtests/researcher.sh(all ok).v2(087d7e8) and run with-base=mainon the merge result, printedvalid=true.44be94dfcdfde0dac8eaNew commits pushed, approval review dismissed automatically according to repository settings
Review of
fde0dac8eafor gascitypacks-lwe0. Checks of the head: success.Verdict
pass
Findings
applyruns the events in order, so when one run of the order reads the third failure and the run that went through together (failures at t0, t2, t4 and a success at t6, with the order run at t3.5 and t8.5; or a whole outage read in one go after the city was down), the streak is neverAlertedandorder.completeddeletes it. README line 672 says only that a streak which ended before it reached three mails nothing. Either check for the threshold as each failure is applied (and send FAILING and RECOVERED together), or say in the README that an incident shorter than the order's interval may go untold. A test for this case would hold it either way.env.operatoris a copy ofinternal/gcx.FindOperator, which main already carries. This change gives the copy a second caller. docs/shell.md says the orders move to gcx in a change of their own, so this does not block, but callinggcx.FindOperator(ctx, e.gc)here after the$OPERATORcheck would have cost one line.Verified
git range-difffrom the approved44be94dtofde0dac: the only changes are the rebase's conflict resolutions in README.md, docs/shell.md and main.go, which keep main's text (version, theinternal/gcxsentence). Main carries no part of this change, so nothing had to be dropped.9e45e9e, which is also its merge base.go vet ./...clean;go test ./...andgo test -raceon roles, internal/gcx and internal/budget pass;go test -v -run TestShellBudget ./internal/budgetreports 28 units, 10 in the ledger, 0 findings.scriptsjob: failures, handover, merge, apply, upgrade, view-beads, view-mail, permission-deny, permission-request, worktree-setup, worktree and gnu-tools all print ok. Tests of thelintjob:gc lint .(2 packs ok), formula, reviewer, operator-overlay, researcher and pack-cache all print ok.-base=main, printsvalid=true.gc events --seqprints a plain number,--sincetakes the2hduration, and the live order.failed and order.completed events carryseq,subject(checks:rig:rexcity) andmessageas the code reads them. Theirtshas fractional seconds, whichtime.Parse(time.RFC3339, …)accepts, soforgethandles it.scope = "city"is set in the order's file and tests/failures.sh holds it. REVIEW.md's shell rules hold: tests/failures.sh runsrm -rfonly on its ownmktemp -ddirectory, and itsgrep -qreads a file, not a pipe.