Skip to content

Flows that wait say what they wait for: Hunch runs, define-with-an-agent, resume checks, wizard discard, promotion - #287

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

Mpdreamz merged 1 commit into
mainfrom
fix/explicit-states-flows

Conversation

@Mpdreamz

Copy link
Copy Markdown
Contributor

Part 3 of fix/explicit-states (code-health plan, PR 12), after #283 and #285. Branched from main with both merged.

  • Hunch training: HunchTrainingRun (idle, starting, running(fraction), stopping) replaces training: Double??. The training getter keeps the pane and HunchStatus as they were.
    • Stop never reached the run before. stopTraining cancelled trainTask, but the work runs in a Task.detached that never sees that cancellation. Stop is now passed on with withTaskCancellationHandler.
    • The runtime checks for cancellation before it adopts a head, and puts the head in use back if it was stopped.
    • A run asked to stop records nothing and deletes its new head, even when it finishes anyway.
    • Progress reported late (after a stop, or after the run ended) is ignored.
    • The app asks run.isActive instead of looking at trainTask.
  • Define with an agent: AgentConversation (HeedCore/ACP) holds id, phase (connecting, ready(session), turn(session, buffer), failed), client, root and paths. It replaces five fields each on WizardBrowser and PersonaLibraryBrowser.
    • The goal's-part flow and the persona flow now share one helper, AppModel+AgentConversation.swift, where each had its own copy.
    • Events, replies and failures are applied only while their conversation id is still the slot's. The goal flow used to check neither the client's identity nor the id.
    • A conversation closed while it was connecting gets its client closed: either the close does it, or the client finds itself detached and closes itself.
  • Resume offer: ConversationChecks (unknown, checking(generation, last), present, missing) replaces conversationOnDisk: [String: Bool].
    • A check that reports after a newer one began is ignored, so an older answer can no longer overwrite a newer one.
    • Unknown still means no offer. A recheck keeps the last answer until it reports, as before.
    • ResumeBanner.offer(..., conversation:) takes the check.
    • Expect a one-line conflict with fix/hook-path in receive: .agentSession now calls conversationChecks.forget.
  • Wizard discard:
    • The confirmation passes what it said it would do. GoalOps.discard(goal:expecting:now:) throws discardChanged and changes nothing when the store would now do the other, so a dialog that said Archive never deletes.
    • WizardActivity (idle, thinking(id), discarding) cancels a running plan turn on discard. A turn whose reply arrives after that writes nothing to the goal, both on arrival and after the plan save it awaits.
  • Promotion: PromotionFlow holds the popover's promotion and its handoff ask in one value.
    • There is no ask without a promotion, and none for another session.
    • goalPromotion and promotionHandoff are now accessors on it.
    • HandoffAsk has an id. deliverHandoffAsk used to match on the session only; a delivery now lands only on the ask it was sent for, not on a newer ask for the same session.

Verification

  • mise run fmt is clean. swiftlint is clean on the changed files; the full lint ran clean before two closure-position warnings were fixed.
  • swift test passed the whole suite (2586 tests) on the branch before its last rebase. After rebasing onto main with Loads and tests say where they stand: Load<T> for diffs and threads, TestRun, coalesced GitHub syncs #283 and One stack of dialogs: whether a click may reach a list or a terminal is one question #285 merged, it builds and the targeted suites pass: 90 tests (the new FlowStateTests plus GoalDiscard, ResumeBanner, SessionHandoff, GoalPromotion and Hunch). The full suite was not rerun after that rebase.
  • New tests in Tests/HeedCoreTests/FlowStateTests.swift, plus one in GoalDiscardTests. They cover:
    • a stopped run that finishes does not adopt;
    • late progress is ignored;
    • a reply for a replaced conversation is dropped;
    • an older check reporting first or last is ignored;
    • a delivery for an earlier ask is dropped;
    • a turn ending after discard is dropped;
    • a discard that would now do the other is refused.
  • Mutations, applied and then reverted, each fail the tests: ignore stopping in finish; drop the generation check; drop the ask-id check; thought accepting any turn; drop the id check in AgentConversation.update; drop the expecting check. The generation mutation first survived; the test was strengthened, and it fails now.

Not tested

  • The flows were not driven in a running app: Hunch training with real MLX, ACP define sessions with a real agent, resume checks after a relaunch, the handoff ask to a live agent. Each has its decision logic in HeedCore with tests; the app wiring was reviewed but not exercised.

🤖 Generated with Claude Code

…ent, resume checks, wizard discard, promotion

- Hunch: `HunchTrainingRun` (idle, starting, running, stopping) replaces `training: Double??`. Stop now reaches
  the detached run (withTaskCancellationHandler), the runtime checks for it before adopting, and a run asked to
  stop never adopts its head even when it finishes anyway. Late progress is ignored.
- `AgentConversation` (HeedCore) and one helper for both "define with an agent" flows (a goal's part, a persona)
  replace six loose fields each. Events, replies and failures for a conversation that was closed or replaced are
  dropped by id; a client made after its conversation was closed closes itself.
- Resume offer: `ConversationChecks` (unknown, checking(generation), present, missing) replaces
  `conversationOnDisk: [String: Bool]`; an older check reporting after a newer one began is ignored.
- Wizard discard: the confirmation passes what it said (Archive or Delete); `GoalOps.discard(expecting:)` refuses
  when the store would now do the other. `WizardActivity` cancels a running plan turn on discard, and a turn's
  reply arriving after that writes nothing.
- Promotion: `PromotionFlow` holds the popover's promotion and its handoff ask in one value (no ask without a
  promotion, none for another session); `HandoffAsk` has an id and a delivery lands only on the ask it was sent for.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added the bug Something isn't working label Nov 16, 2026
@Mpdreamz
Mpdreamz merged commit 661d7f4 into main Nov 16, 2026
4 of 5 checks passed
@Mpdreamz
Mpdreamz deleted the fix/explicit-states-flows branch November 16, 2026 20:06
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