Skip to content

feat(mobile): coordinator switch in the thread menu and on New agent - #607

Merged
NoahHendrickson merged 8 commits into
customfrom
t3/ios-coordinator-switch
Nov 29, 2026
Merged

NoahHendrickson merged 8 commits into
customfrom
t3/ios-coordinator-switch

Conversation

@NoahHendrickson

@NoahHendrickson NoahHendrickson commented Nov 29, 2026 •

Copy link
Copy Markdown
Owner

iOS sprints spec step 7. On the phone you couldn't turn a thread into a coordinator or start one. Web has both ways in.

Thread ⋯ menu. It now has "Make coordinator" / "Stop coordinating" (fork/no3yCoordinator.ts), shown only where the thread can coordinate (the new shared coordinatorSwitchOf) and disabled without operate scope. It runs web's steps: set or clear the coordinator tag, then queue the start or stop message behind whatever the thread is doing. If the message fails, or the thread is archived, the tag goes back. That step function, switchCoordinator, moved from web's useSetCoordinator.ts into client-runtime fork-coordinator-threads so both clients share it. Its tests moved with it. Web behaves the same: coordinatorMenuItems now builds on coordinatorSwitchOf and keeps the same labels.

New agent Coordinator pill. It sits after the worktree, branch and machine pills (iOS kit 33:473: No3yCheckboxMark, workflow-square-10, label). The switch is held per draft for the session, in an atom, as on web. A send with it on marks the queued outbox task coordinator: true. Outbox delivery then sends what web's first send does: fork/no3yCoordinatorDelivery.ts no3yFirstSend builds the steps from the shared coordinatorFirstSendTurns.

  1. The rules turn creates the thread. It goes 1 ms earlier, with no title seed.
  2. thread.tag.set coordinator.
  3. The owner's task, queued behind the rules.

Each step has its own command id, so a retry after a failed step has the server replay the steps it already took. The upstream sendQueuedCreation gets one fenced loop over those steps.

When a step is rejected:

  • Before the rules created the thread: the task goes back to a new draft with the switch on.
  • After: it goes to that thread's composer with the reason. A new draft would make a second thread.
  • "Preparing" state: a coordinator creation stops showing "preparing" once its rules message arrives (pending-thread-creation no3yCreationMessageId), because a task handed back to the thread never reaches the server.

Tests.

  • threadOutboxDelivery.permissions.test.ts "coordinator first send": the full rules → tag → task sequence; a transport failure on the tag, then a retry with the same command ids; a rejection before the thread exists going to a new draft; a rejection after going to the thread.
  • pending-thread-creation.test.ts: the creation settles on the rules message.
  • The fork guard pins the mobile wiring.
  • The full mobile suite passes (386 files).

Checked on an iOS simulator (fresh post-sync dev client, isolated backend, Replay provider), after the review fixes too:

  • The pill send made a thread titled from the task, with the rules first and the task queued behind them.
  • The thread showed under Coordinators on home, with feat(mobile): sprint and coordinator Threads sheet #604's coordinator glyph and Threads button in its header.
  • "Stop coordinating" queued the stop message, and "Make coordinator" queued the rules again.

Follow-ups, not in this PR:

Reviewed with sol-loop: 3 rounds with gpt-6.1-sol on high. Sol verdict: approved


🤖 Signed: Claude Opus 5.5 (claude-opus-5-5) via Claude Code (T3 Code)
Reviewed by: GPT-6.1 Sol (gpt-6.1-sol, high) via Codex, 3 review rounds; its round-2 finding (the thread kept showing "preparing" after a hand-back) is fixed here

🤖 Generated with Claude Code

@github-actions github-actions Bot added size:L vouch:trusted Author is trusted by repo permissions or the VOUCHED list. labels Nov 29, 2026

@NoahHendrickson NoahHendrickson left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code-quality review: febbe2d686

Not approving. The behaviour lines up with web. Moving switchCoordinator into client-runtime with its own test is the right call. The structure falls short in a few places, though. The largest problem is that the coordinator's first send is written inline inside upstream's busiest delivery generator. It also uses a second ordering model that differs from the shared one web uses. Findings, most serious first:

1. A 40-line orchestration block inside upstream sendQueuedCreation (structural, blocker)

threadOutboxDelivery.ts goes from 1645 to 1698 lines. The new fenced block sits in the middle of the generator. It builds the rules and tag commands by hand, then runs a loop that copies the failure handling the task send does right below it: the hasAccess check, then reportCommandFailure, then retry or restore. That handling now appears three times in this one function. .fork/AGENTS.md says an inline edit to an upstream file is the last resort and its hunk must stay small. Every upstream sync will have to re-merge this block.

Fix: move the plan into a fork module, for example apps/mobile/fork/no3yCoordinatorDelivery.ts. It would export no3yFirstSend(queuedMessage, launch): { prelude: ReadonlyArray<StartTurnCommand | SetTagCommand>; send: StartTurnCommand }, where a normal task returns { prelude: [], send: launch }. The upstream fence then shrinks to one destructuring line plus a short loop that sends each prelude command through the same settle path as the task. No let send reassignment and no second copy of the failure handling.

2. Two ordering models for one concept, and an orphan thread on restore (plausible correctness issue)

Web runs rules → tag → task through the shared sendCoordinatorFirstTurn. That helper tracks rulesSent and retries on the same thread. Mobile writes the same sequence again and relies on the server replaying a resent command with the same command id. sendCoordinatorFirstTurn's own doc says it is shared with iOS, yet it now has a single caller. The two models give different results on restore:

  • The rules turn succeeds, so the thread now exists.
  • Then the tag gets a restore verdict. This is the case your test hands a rejected task back to its draft with the switch still on covers.
  • The task goes back to restoredNewTaskDraftKey(messageId). That screen gets a new thread id from useState(makeTurnCommandMetadata).
  • The next send creates a second thread with the rules again. The first thread is left untagged, holding the rules and its "Coordinating." reply.

Fix: pick one model. Either reshape sendCoordinatorFirstTurn into steps that both clients can drive, Effect and Promise alike. Or, if replay by command id is the better model, move web to it and delete rulesSentThreads and rulesDone. Today the shared helper and the mobile copy can drift apart without anyone noticing.

3. A hand-made key for menuLabelAtom, and a builder called with a fake argument

The family key is made with JSON.stringify and read back with JSON.parse(key) as [string, string]. The canonical scopedThreadKey / parseScopedThreadKey already exist, and no3yBotDigestAnswers.ts next door uses them. The label also comes from calling coordinatorMenuItems(shell.source, true)[0]?.label, which passes a made-up canOperate: true just to pull out a string. The item is then rebuilt by hand with the real disabled. Use the canonical key, and either select a typed "start" | "stop" | null state or feed the real canOperate into the shared builder. Then there is a single source for the item's shape.

4. A new state store written from scratch instead of using an Atom

no3yCoordinatorDraft.ts writes its own store: a module-level Set, a listener set and useSyncExternalStore. Mobile already uses Effect Atoms in appAtomRegistry, and this PR uses them in no3yCoordinator.ts. An Atom.make<ReadonlySet<string>> read with useAtomValue and written with appAtomRegistry.set would delete subscribe, listeners and read. It would also put the switch in the registry the outbox tests already reset between cases. The module state here persists across tests.

5. DraftPill becomes a two-mode component through checked?: boolean

checked === undefined now chooses the role, the accessibility state, the left padding, a leading checkbox and the icon's filled. That is five branches for one optional prop, in a file that was already over 1k lines (1008 → 1053). A separate DraftSwitchPill, or a leading slot plus explicit accessibility props, would keep the plain pill plain. A small CheckboxMark component would also move the checkbox out of the file. Separately: with the !showWorkspace && !showMachine early return gone, a null draftKey and no other pills now renders an empty row.

6. Optional threadId the only caller always passes

no3yUsage.threadId? and useNo3yThreadBar's threadId? are optional, but ThreadRouteScreen always passes them. The optionality is why input?.threadId !== undefined and part of the thread | undefined handling exist. Make it required. It is also a coordinator setting riding on a prop named no3yUsage, which is a hint that the grouping is wrong.


🤖 Reviewed by Claude Opus 5.5 (claude-opus-5-5) via Claude Code

Comment thread apps/mobile/fork/no3yCoordinator.ts Resolved
Comment thread apps/mobile/fork/No3yNewAgent.tsx Resolved
Comment thread apps/mobile/fork/No3yScreenHeader.tsx Resolved

@NoahHendrickson NoahHendrickson left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review of febbe2d686e3115c9f053ff6c404d6dd2f604c20 (/code-review high, findings checked against the source).

1 important, 4 nits. Details are in the inline comments.

  • Important: if a coordinator step is rejected after the rules turn has already created the thread, the task goes back to a new draft. The thread that got the rules stays behind on the server, and resending the draft makes a second thread. The new test at threadOutboxDelivery.permissions.test.ts:795-805 asserts exactly this behaviour.
  • Nits: archived threads aren't refused the way web's useTellThread refuses them; tag failures are logged as start-turn; two upstream lines were changed outside the fork fence; the test leaves the module-global coordinator draft switched on for later tests.

Not raised again: the PR body already lists the restart-between-rules-and-task recovery gap as a follow-up. A double tap on the menu item before the tag event arrives can also switch the thread twice, but web's useCoordinatorMenuPick behaves the same way, so this is parity rather than a regression.


🤖 Signed: Claude Opus 5.5 (claude-opus-5-5) via Claude Code (T3 Code)

Comment thread apps/mobile/fork/no3yCoordinator.ts Resolved
@github-actions

github-actions Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

Thread transfer impact

⚠️ The latest CI run did not produce a thread transfer result for 4a6f302.

This comment will update automatically after the next completed run.

xxxxxxxxxxxxx and others added 3 commits November 29, 2026 15:27
The thread ⋯ menu offers "Make coordinator" / "Stop coordinating", running
web's switch steps (now shared as client-runtime switchCoordinator): tag,
then queue the rules, putting the tag back if they fail.

New agent gets a Coordinator pill. A switched-on send marks the queued task,
and outbox delivery sends it as web does: the rules create the thread, the
thread is tagged, then the task queues behind them, each step under its own
command id so a retry is replayed by the server.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… thread

Review follow-up. Once the rules turn has created the thread, a rejected tag
or task hands the task to that thread's composer with the reason, instead of
a new draft whose send would make a second thread. The rules/tag/task steps
move to fork/no3yCoordinatorDelivery, so the upstream hunk is one fenced loop.

Also: the menu reads a typed start/stop state (shared coordinatorSwitchOf)
under the canonical scoped key, archived threads are refused as on web, the
draft switch is an atom, the pill's checkbox is a leading slot, and the
thread bar's threadId is required.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@NoahHendrickson
NoahHendrickson force-pushed the t3/ios-coordinator-switch branch from febbe2d to 77f9b29 Compare November 29, 2026 20:30
xxxxxxxxxxxxx and others added 5 commits November 29, 2026 15:37
…rive

Sol review: a task handed back to the thread never reaches the server, so the
open thread kept waiting for it and showed "preparing" and a phantom queued
task. A coordinator creation now settles on its rules message, the thread's
first.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The watch entry landed in the media-attachment entry by mistake.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…switch

# Conflicts:
#	.fork/customizations.yaml
@NoahHendrickson
NoahHendrickson merged commit de4874b into custom Nov 29, 2026
32 checks passed
@NoahHendrickson
NoahHendrickson deleted the t3/ios-coordinator-switch branch November 29, 2026 22:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L vouch:trusted Author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants