Repository navigation
feat(mobile): coordinator switch in the thread menu and on New agent - #607
Conversation
NoahHendrickson
left a comment
There was a problem hiding this comment.
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 oncovers. - The task goes back to
restoredNewTaskDraftKey(messageId). That screen gets a new thread id fromuseState(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
NoahHendrickson
left a comment
There was a problem hiding this comment.
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-805asserts exactly this behaviour. - Nits: archived threads aren't refused the way web's
useTellThreadrefuses them; tag failures are logged asstart-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)
Thread transfer impact
This comment will update automatically after the next completed run. |
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>
febbe2d to
77f9b29
Compare
…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
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 sharedcoordinatorSwitchOf) and disabled without operate scope. It runs web's steps: set or clear thecoordinatortag, 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'suseSetCoordinator.tsinto client-runtimefork-coordinator-threadsso both clients share it. Its tests moved with it. Web behaves the same:coordinatorMenuItemsnow builds oncoordinatorSwitchOfand 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 taskcoordinator: true. Outbox delivery then sends what web's first send does:fork/no3yCoordinatorDelivery.tsno3yFirstSendbuilds the steps from the sharedcoordinatorFirstSendTurns.thread.tag.set coordinator.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
sendQueuedCreationgets one fenced loop over those steps.When a step is rejected:
pending-thread-creationno3yCreationMessageId), 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.Checked on an iOS simulator (fresh post-sync dev client, isolated backend, Replay provider), after the review fixes too:
Follow-ups, not in this PR:
start-turn.customafter fix(fork): design lint holds new UI to a Figma kit component and a story #602/feat(mobile): sprint and coordinator Threads sheet #604, so they are not from 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