Skip to content

Hook routing and feedback delivery decided in HeedCore: HookRouter and FeedbackDelivery.decide - #290

Merged
Mpdreamz merged 1 commit into
mainfrom
fix/hook-router
Nov 16, 2026
Merged

Mpdreamz merged 1 commit into
mainfrom
fix/hook-router

Conversation

@Mpdreamz

@Mpdreamz Mpdreamz commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Part 1 of fix/hook-router (code-health plan, PR 13): items 1 and 5. Behaviour is unchanged; AppModel keeps the wiring and applies what HeedCore decides.

  • HookRouter (HeedCore/Protocol): route says whose a hook message is (unheard, retired, a reviewer's, a swarm worker's or a run's pane, or the session's agent). review and run say what a reviewer's or run's hook does: did not start, setup failed, usage on the run's record (ignored when unchanged or when no record), or a turn with its state, whether it has worked and whether it ended. takeover names the agent that took the pane over. session turns a state, guess or at-prompt report into the session's next state, or nil when it is not news, with the rate-limit reset in its reason. resets is an autoclosure, so the reset text is only worked out for a rate-limited report, as before.
  • AppModel.receive routes first, then does the same side effects in the same order (heard, last hook, inbox, approvals, the session lookup, audit and origin) before handing reviewer and run panes to the new receiveReview and receiveRun.
  • FeedbackDelivery.decide (HeedCore/GitHub): every gate of deliver in the order the app meets it: nothing queued, the pull-event cause, merged or closed, auto-feed held (stuck when auto-feed ran out of rounds), the author's trust (go, hold, ask), helper, no session, fixture (tutor), in session, a run already working, a swarm handback (worker, wait, pilot). The trust book and the swarm handback route (which looks for worktrees on disk) are closures, read only when the decision gets that far, so nothing reads the book earlier than it used to.
  • AppModel.deliver gathers the facts and switches on the decision; flashes, pilot log lines and side effects are the same.

Items 2 to 4 (helper and pilot run reducers, one trust-resolve function) follow as a second PR off fresh main.

Verified: swift build (app included), swift test --filter "HookRouterTests|FeedbackDeliveryTests" (31 tests), mise run fmt, mise run lint. Mutation checks: dropping || state == .working from a turn's worked flag fails the review and run tests; dropping && auto from stuck fails the auto-feed test. The full suite was not run, per the plan it runs on main at the end.

🤖 Generated with Claude Code

@github-actions github-actions Bot added the bug Something isn't working label Nov 16, 2026
…d FeedbackDelivery.decide

AppModel.receive and AppModel.deliver keep their wiring; what they decide is now pure and tested.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Mpdreamz
Mpdreamz merged commit 1e9fa2c into main Nov 16, 2026
7 checks passed
@Mpdreamz
Mpdreamz deleted the fix/hook-router branch November 16, 2026 21:11
Mpdreamz added a commit that referenced this pull request Nov 16, 2026
…trust check (#292)

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](https://claude.com/claude-code)

Co-authored-by: Claude Opus 5.5 <[email protected]>
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