Skip to content

fix(mobile): keep retired names on an RPC error and route the host's created name (STA-4479, STA-4480) - #14926

Open
brennanb2025 wants to merge 1 commit into
mainfrom
brennanb2025/fix-4479-4480
Open

brennanb2025 wants to merge 1 commit into
mainfrom
brennanb2025/fix-4479-4480

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Aug 16, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​70 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​69
Prod 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​15 $\color{#cf222e}{\Huge{\mathbf{−}}}$​5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​10

Fixes STA-4479 (P2) and STA-4480 (P2). Both regressions from #14350, both on mobile's
generated-name suggestion surface. Neither can leak history — the host still refuses reuse — so this
branches from main rather than the host-side stack (#14917 → #14919 → #14924); it shares no files
with it.

STA-4479 — an RPC error blanked the retired-name cache

RpcClient.sendRequest resolves with { ok: false, error } for a host-side failure; it only
rejects on transport failures. The hook read response.result unconditionally, so an error envelope
produced undefined → readRetiredNameRegistryForRepo returned an empty registry (not null) →
retiredNamesAfterRefresh stored it and overwrote the previous good answer. The .catch never saw
it.

Empty means "nothing is retired", which is the one direction retired-name-cache.ts exists to
prevent — its own doc says mobile "blanked the list on any error, which un-retires names". The
transport-level fix landed then; the envelope-level one did not.

Now the envelope decides: response.ok ? read(response.result) : null, and null already means
"hold the previous answer" in the shared cache rules.

Test-harness correction, called out because it changes existing tests: the hook's test client
resolved bare { result } objects with no ok field, which the transport never delivers. That fake
is exactly what let this bug hide. The harness now emits real RpcSuccess/RpcFailure envelopes.

STA-4480 — mobile routed the name it proposed, not the one the host created

createWorktreeWithNameRetry returned { worktreeId, name: candidateName }. The host advances past
a retired cwd on its own, so the created workspace can carry a later candidate than the one sent —
and onCreated(result.worktreeId, result.name) then titles the new workspace wrongly until the
live-name hook corrects it.

It now prefers result.worktree.displayName, falling back to the proposal when a host answers
without one. No wire change: displayName is an existing required field on Worktree; the fallback
covers a malformed or unexpected envelope rather than a version skew.

Tests

RED against unfixed production code (git checkout origin/main -- <both files>, tests kept — note
the 17 pre-existing tests still pass against the corrected harness, so only the two new assertions
fail):

FAIL worktree-create-retry.test.ts > routes to the name the host actually created, not the one this client proposed
  -   "name": "nautilus-4",
  +   "name": "nautilus",
FAIL use-retired-worktree-names.test.tsx > keeps previously loaded names when the host answers with an error
  -   "exhaustedTiers": 2,  "names": [ "nautilus" ],
  +   "exhaustedTiers": 0,  "names": [],

GREEN: full mobile suite, 3524 passed / 3 skipped across 448 files. tsc -p mobile/tsconfig.json
exit 0, oxlint exit 0.

Not covered

Mobile emulator QA was not run for this change; both defects are asserted at the unit level only.

🤖 Generated with Claude Code

@coderabbitai

coderabbitai Bot commented Aug 16, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: f35a5a88-fcf7-4a1c-b0af-0050b8054106

📥 Commits

Reviewing files that changed from the base of the PR and between 516a269 and 7c18a26.

📒 Files selected for processing (4)
  • mobile/src/tasks/worktree-create-retry.test.ts
  • mobile/src/tasks/worktree-create-retry.ts
  • mobile/src/worktree/use-retired-worktree-names.test.tsx
  • mobile/src/worktree/use-retired-worktree-names.ts

Included review availability: Your plan includes up to 10 reviews per rolling hour; 5 remain after this review.


📝 Walkthrough

Walkthrough

Worktree creation now returns the host-provided non-empty displayName, with fallback to the proposed name. Tests cover both cases. The retired-name hook now checks the RPC response envelope and preserves existing names and tier state when the host returns an error envelope. Tests cover successful envelopes, resolved errors, and state preservation.

Merge Risk: ⚪ Minimal · up to 7c18a

The change preserves retired-name suggestions across RPC errors and uses the host-created name for new workspaces; no actionable merge-blocking risk remains after the reported checks pass.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes both primary mobile fixes and identifies their related issues.
Description check ✅ Passed The description clearly explains both regressions, fixes, linked issues, tests, and the mobile QA limitation, but omits the required Visual Proof entry and checklist sections.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Review — verdict: CLEAN, approve. No blocking findings at 7c18a26.

Two things a reviewer should not miss before re-litigating this PR:

1. The "conditional displayName" objection is disproved — don't re-raise it. The obvious worry about the STA-4480 half is that it routes on a field the host may not send, so the || candidateName fallback silently restores the old (wrong) behavior. It cannot. displayName is a required field on Worktree and mergeWorktree (src/main/ipc/worktree-metadata-merge.ts:38) populates it unconditionally: meta?.displayName || branchShort || defaultDisplayName || basename(path). Both arms carry the advanced name — createManagedWorktree reassigns effectiveRequestedName inside the suffix loop (src/main/runtime/orca-runtime.ts:22696) and shouldSetDisplayName only returns false when the requested name already equals the branch short name, in which case branchShort is that same advanced name. The worktree.create RPC handler (src/main/runtime/rpc/methods/worktree.ts:93) returns createManagedWorktree's result unprojected, and dedupeWorktreeCreate replays the identical promise. So the fallback branch is unreachable from any real host; it is defensive only, and the fix is load-bearing on every real path.

2. NEW — the same defect class is still live on the web client, unfixed and unfiled. Out of scope for this PR (correctly mobile-only), but adjacent: src/renderer/src/web/web-preload-api.ts:1807 wraps listRetiredNames in try { … } catch { return EMPTY_RETIRED_NAME_REGISTRY }. callRuntimeResult throws on an ok: false envelope (:3513), so a host-side failure is converted into an empty registry that looks like a successful load. The desktop hook's .catch(() => settle(null)) never fires, retiredNamesAfterRefresh stores the empty answer, and every name un-retires — precisely the outcome retired-name-cache.ts exists to prevent, and precisely what STA-4479 fixes for mobile. Worth a follow-up ticket.

What was reviewed, and how

Read the full diff against the PR head, then traced both halves end-to-end through host code: the RPC envelope union (mobile/src/transport/types.ts:23-38), retired-name-cache.ts's null-vs-empty contract, mergeWorktree, createManagedWorktree's suffix/retirement loop, the worktree.create handler and its dedupe, and every caller of createWorktreeWithNameRetry down to the render surface. Diff is 4 files, +85/−6, mobile-only; no wire change (displayName is an existing required field, not a new one).

Base: the earlier audit recorded "current main tip". That is now stale — main has moved 57 commits since. Restated accurately: the base 516a2693 is a clean ancestor of main with no orphaned or superseded commits (unlike sibling #14924, which needed a restack), and GitHub still reports MERGEABLE / CLEAN.

Prior-art conformance — A

  • null means "hold the previous answer", empty means "nothing is retired". The fix routes an error envelope to null, which is the documented contract in retired-name-cache.ts rather than a new rule invented at the call site.
  • RPC result is unknown on the wire. The new read casts, then guards (typeof createdName === 'string' && createdName) instead of trusting the cast — the pattern this codebase already uses for cast-then-branch wire payloads. The hook goes further and drops its old (response as { result?: unknown }) cast entirely, letting the RpcSuccess | RpcFailure discriminant narrow. That cast is what hid the bug; removing it is the durable part of the fix.
  • No paired desktop change is needed: the desktop hook goes over IPC, which rejects on failure, so its .catch already covers this. (The web path does not — see finding 2.)

Non-vacuity evidence

  • Load-bearing harness correction. The hook's test client used to resolve bare { result } objects with no ok field — a shape the transport never delivers, and the reason a resolved error envelope could hide. Post-fix, response.ok on that fake is undefined → every one of the 17 pre-existing tests would settle null. They pass only because the harness now emits real RpcSuccess/RpcFailure envelopes. The harness change is not cosmetic; it is what makes the whole file non-vacuous.
  • RED derivation (reasoned from the diff, not re-run by me — see gaps). Pre-fix, the hook read .result unconditionally, so an ok: false envelope yields undefined → empty registry → the keeps previously loaded names… assertion fails on both names and exhaustedTiers. Pre-fix, worktree-create-retry returned candidateName unconditionally, so routes to the name the host actually created fails nautilus vs nautilus-4. Both are genuine regression tests.
  • One of the four new tests is a guard, not a regression test. falls back to the proposed name when the host answers without one passes against unfixed code too (old code always returned the proposal). That is fine — but it pins the defensive branch, it does not prove the fix.
  • CI is green at exactly this head. 46/46 checks pass on 7c18a26 (e2e skipped — no changed e2e specs, expected for a mobile-only diff). The root PR suite does not cover mobile/** (config/vitest.config.ts includes src/** only); mobile is covered by the separate Mobile Checks run, whose Typecheck / Test / Lint / Check-formatting steps all succeeded on this same SHA.

Explicitly NOT covered

  • This PR never received the independent same-model review-until-clean loop. The wave that would have run it was never dispatched. This comment is a single audit pass, not a converged loop — so treat "no findings" as "one careful reader found none", not as "the loop ran dry".
  • Both halves have a rendered surface, and there are no screenshots and no emulator QA. STA-4480 seeds the session screen's route name param (mobile/app/h/[hostId]/index.tsx:1405 → useLiveWorktreeName), so the header title shows the wrong name until the live-name hook corrects it. STA-4479 feeds getSuggestedCreatureName(…, retiredWorktreeNames) in the create sheet (mobile/src/components/NewWorktreeModal.tsx:629), so a blanked cache re-suggests a spent name in the exact window the form is asking for one. Both defects are asserted at the unit level only; there is no visual evidence that either surface renders correctly on a device.
  • I did not re-run the tests locally — this worktree has no node_modules. The green claim above rests on the Mobile Checks CI run at this SHA, which is authoritative; the RED claim rests on reading the diff, which is deterministic here but is reasoned, not re-executed.
  • Unchanged and intentional: an ok: true answer from a host predating worktree.listRetiredNames still yields an empty registry. That is the documented degrade-to-pre-retirement direction, not a gap this PR introduces.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant