Skip to content

Helper and pilot runs end once: HelperRun.apply, PilotRun.State, one trust check - #292

Merged
Mpdreamz merged 1 commit into
mainfrom
fix/run-states
Nov 16, 2026
Merged

Mpdreamz merged 1 commit into
mainfrom
fix/run-states

Conversation

@Mpdreamz

Copy link
Copy Markdown
Contributor

Part 2 of fix/hook-router (code-health plan, PR 13): items 2 to 4. Independent of #290; whichever lands second takes a small rebase in AppModel.deliver (the trust-resolve block and the one-run-per-PR check).

  • HelperRun.apply(_ event:, at:) -> [Effect]? (HeedCore/Helpers/HelperLifecycle.swift). Every phase change in AppModel+Helpers now goes through this one function, about 15 sites: ready, turn started, turn ended (read by why it was cancelled: pause, steer, stop), stopped, could not start, turn failed, agent exited, close-out, closed, part ended. It returns what the app does next (finishTurn, steer, recordFailure), or nil when the event no longer applies, in which case nothing changes. The app keeps the side maps (turns, cancelling, clients) as it did. HelpersModel.CancelReason is now HelperRun.Cancel, kept under its old name as an alias.
  • The fix. A turn's end, a failure or a stop needs a live helper. A close-out needs one waiting for it. Closing out needs one that is not closed already. So a late turnEnded after gO (take over) no longer turns the helper back to stopped and runs finishTurn, which could auto-push. A finishTurn whose git read finishes after the close-out no longer overwrites endedAt and the close-out. runTurn does not start a turn on a helper that failed or was closed out. A failed helper can still be closed out (thrown away), as before.
  • Two small behaviour changes: taking over a finished helper keeps its first endedAt rather than setting it to the takeover time. Closing out an already closed helper does not relabel it.
  • PilotRun.State: running, ending, ended(Outcome, at:). Before, endedAt and outcome could be set separately. endedAt and outcome are now read-only views of the state. end(_:at:) counts only the first end. endRun marks the run ending as it removes the live entry, and the one-run-per-PR check in deliver treats an ending run as busy, so the next round waits until the end has been read (endRun already delivers what waited). Storage keeps its old format (endedAt and outcome), plus ending while a run ends. A stored end with no outcome reads as interrupted.
  • PullTrustBook.resolveOnGitHub(_:viewer:trustedAuthors:caller:) replaces the five resolve { GitHub.pullAuthorship … } blocks in AppModel, +Helpers and +Reviewers. The callers' names in the call log are unchanged.

Verified: swift build (app included) and swift build --build-tests. Targeted tests passed (154 tests in 25 suites): the new HelperLifecycleTests and PilotRunStateTests, plus Runs, RepoSetup, Helper, HelperApproval, AwaySummary, RunIsolation and Domain. mise run fmt and lint (swiftformat --lint, swiftlint) are clean. Mutation checks: dropping the live guard on a turn's end fails the late-takeover test, and dropping the first-end guard in PilotRun.end fails the ending test. The full suite was not run; per the plan it runs on main at the end. Not checked in the running app.

🤖 Generated with Claude Code

@github-actions github-actions Bot added the bug Something isn't working label Nov 16, 2026
…trust check

A helper's phase changes go through HelperRun.apply, which ignores what no longer applies, so a late turn end or
close-out cannot reopen a helper you closed out or move its end. A pilot run is running, ending or ended; the next
round waits while one ends, and only its first end counts. PullTrustBook.resolveOnGitHub is the one way the app
asks who a PR is from.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Mpdreamz
Mpdreamz merged commit 9d728f4 into main Nov 16, 2026
2 checks passed
@Mpdreamz
Mpdreamz deleted the fix/run-states branch November 16, 2026 21:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant