Repository navigation
fix(folder-workspaces): keep the broken-folder marker when a host sends a new reason - #15027
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📥 CommitsReviewing files that changed from the base of the PR and between 3d80a01ce3f1b4c86db73ae90b7bcd41203eda2a and 2e04374. 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
Included review availability: Your plan includes up to 10 reviews per rolling hour; 0 remain after this review. 📝 WalkthroughWalkthroughThe change adds a shared type guard for validating string wire discriminants against handled records. Cookie import warning paths now use the shared guard. Folder workspace path-status handling adds fallbacks for unknown or non-string reasons. English localization adds unrecognized status text and expands unavailable status guidance. Tests cover status titles, descriptions, indicators, accessibility labels, styling, and healthy folders. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
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. Comment |
…ds a new reason FolderWorkspacePathStatus is cast, not decoded, off the runtime RPC wire -- runtime-rpc-envelope declares result: z.unknown(), so unwrapRuntimeRpcResult hands back whatever the host sent. Both title and description switch on status.reason with no runtime guard, so a newer host publishing a fifth reason matched nothing and returned undefined. FolderPathStatusIndicator's `!title` check then dropped the whole indicator, and a broken folder workspace rendered as healthy -- worse than the blank toast #15002 fixed, because there the warning was empty and here it is gone. Guard before each switch, the shape #15002 landed. A default: arm is not available: the type-aware config sets allowDefaultCaseForExhaustiveSwitch:false and rejects one with switch-exhaustiveness-check. Extract that guard into isHandledWireDiscriminant instead of hand-writing a third and fourth copy, and move #15002's two bespoke guards onto it. It takes unknown and checks typeof before Object.hasOwn -- hasOwn coerces its key, so a host that widened the field to an array sends ['missing'], which a hasOwn-only guard admits before the switch drops it straight back out. That was the P1 found in review on #15002; one implementation makes it structural instead of tribal. An unrecognized reason gets its own copy rather than reusing 'unavailable'. The unavailable remedy -- "Check the runtime or SSH connection and try again" -- is a false lead here: the host did check and reported the folder unusable, so retrying and inspecting a healthy connection wastes the user's time. Update Orca is the real remedy. Adding a fifth reason still fails typecheck in two places: TS2741 on the Record and TS2366 plus switch-exhaustiveness-check on both switches.
3d80a01 to
2e04374
Compare
Independent review loop — VERDICT: CLEANCovers head Every claim below was re-derived by mutation or differential execution rather than by reading the diff or trusting the existing tests. 1. The helper does not loosen the compile-time guarantee at any call siteThe concern with extracting a generic guard is that inference could degrade All four switches and all three Records still fail. The guarantee is intact everywhere — no call site was traded away. Worth recording why it holds, since it is not the obvious reason: the exhaustiveness enforcement does not depend on the helper's 2. The
|
…ds a new reason (stablyai#15027) FolderWorkspacePathStatus is cast, not decoded, off the runtime RPC wire -- runtime-rpc-envelope declares result: z.unknown(), so unwrapRuntimeRpcResult hands back whatever the host sent. Both title and description switch on status.reason with no runtime guard, so a newer host publishing a fifth reason matched nothing and returned undefined. FolderPathStatusIndicator's `!title` check then dropped the whole indicator, and a broken folder workspace rendered as healthy -- worse than the blank toast stablyai#15002 fixed, because there the warning was empty and here it is gone. Guard before each switch, the shape stablyai#15002 landed. A default: arm is not available: the type-aware config sets allowDefaultCaseForExhaustiveSwitch:false and rejects one with switch-exhaustiveness-check. Extract that guard into isHandledWireDiscriminant instead of hand-writing a third and fourth copy, and move stablyai#15002's two bespoke guards onto it. It takes unknown and checks typeof before Object.hasOwn -- hasOwn coerces its key, so a host that widened the field to an array sends ['missing'], which a hasOwn-only guard admits before the switch drops it straight back out. That was the P1 found in review on stablyai#15002; one implementation makes it structural instead of tribal. An unrecognized reason gets its own copy rather than reusing 'unavailable'. The unavailable remedy -- "Check the runtime or SSH connection and try again" -- is a false lead here: the host did check and reported the folder unusable, so retrying and inspecting a healthy connection wastes the user's time. Update Orca is the real remedy. Adding a fifth reason still fails typecheck in two places: TS2741 on the Record and TS2366 plus switch-exhaustiveness-check on both switches.
…ds a new reason (stablyai#15027) FolderWorkspacePathStatus is cast, not decoded, off the runtime RPC wire -- runtime-rpc-envelope declares result: z.unknown(), so unwrapRuntimeRpcResult hands back whatever the host sent. Both title and description switch on status.reason with no runtime guard, so a newer host publishing a fifth reason matched nothing and returned undefined. FolderPathStatusIndicator's `!title` check then dropped the whole indicator, and a broken folder workspace rendered as healthy -- worse than the blank toast stablyai#15002 fixed, because there the warning was empty and here it is gone. Guard before each switch, the shape stablyai#15002 landed. A default: arm is not available: the type-aware config sets allowDefaultCaseForExhaustiveSwitch:false and rejects one with switch-exhaustiveness-check. Extract that guard into isHandledWireDiscriminant instead of hand-writing a third and fourth copy, and move stablyai#15002's two bespoke guards onto it. It takes unknown and checks typeof before Object.hasOwn -- hasOwn coerces its key, so a host that widened the field to an array sends ['missing'], which a hasOwn-only guard admits before the switch drops it straight back out. That was the P1 found in review on stablyai#15002; one implementation makes it structural instead of tribal. An unrecognized reason gets its own copy rather than reusing 'unavailable'. The unavailable remedy -- "Check the runtime or SSH connection and try again" -- is a false lead here: the host did check and reported the folder unusable, so retrying and inspecting a healthy connection wastes the user's time. Update Orca is the real remedy. Adding a fifth reason still fails typecheck in two places: TS2741 on the Record and TS2366 plus switch-exhaustiveness-check on both switches.
The defect
FolderWorkspacePathStatusreaches the renderer through a cast, not a decode.src/shared/runtime-rpc-envelope.ts:26declaresresult: z.unknown()inside the zod-validated success envelope, sounwrapRuntimeRpcResulthands back whatever the host sent asTResult. Both fetch sites —src/renderer/src/store/slices/repos.ts:1658and:2580— docallRuntimeRpc<{ status: FolderWorkspacePathStatus }>(...). Clients and hosts update independently, so a newer host publishing a fifthreasonreaching an older client is the normal state, not an edge case.getFolderWorkspacePathStatusTitleandgetFolderWorkspacePathStatusDescriptionswitched onstatus.reasonwith no runtime guard. An unrecognized reason matched nothing and the functions returnedundefined.FolderPathStatusIndicator.tsx:20then hitsif (!status || status.exists || !title) return null— the indicator does not render at all, and a broken folder workspace shows as healthy in the sidebar.That is worse than the blank-toast bug #15002 just fixed: there the warning was empty, here it is gone. The red run for the new component test prints
expected '' not to be ''— the marker renders as literally empty markup onmain.Two more consumers of the same two functions were silently degraded by this:
worktree-activation.ts:95(which has??fallbacks, so it degraded rather than vanished) andfolder-workspace-composer-path-status.ts:128(whosetitle && …guard nulled the whole composer error). Fixing the source repairs all three.The fix
One shared guard,
isHandledWireDiscriminantinsrc/shared/handled-wire-discriminant.ts, applied at all four switches — the two here, and the two#15002landed. #15002 had to hand-write its guard twice; this change would have made it four bespoke copies. Extracting it makes the lesson structural instead of tribal.typeoffirst is load-bearing.Object.hasOwncoerces its key, so a guard typed(x: string)accepts['missing'], whosetoString()matches a handled key — and the value then falls straight back out of the switch, reintroducing the exact bug. That was the P1 found in review on #15002 after the author's own verification missed it. There is now one implementation of it that cannot drift.A
default:arm is not available, confirmed empirically here rather than assumed: injecting one into this file producesbecause
config/oxlint-code-quality-type-aware.jsonsetsallowDefaultCaseForExhaustiveSwitch: false. A guard before the switch is the shape that satisfies both the lint rule and the wire.A
readonly Reason[]plusArray.includesis the other obvious shape, and it gets coercion-safety for free (includesuses SameValueZero, so an array is never equal to a string). It was rejected because it gives up the property that matters most here:const X: readonly Reason[] = ['missing', ...]compiles happily while missing a union member, so a fifth reason would land silently. TheRecord<Union, true>form makes a missing member a type error, and the explicittypeofcheck buys back the coercion safety the array form would have given.Adding a fifth reason still fails typecheck in two places. Verified by temporarily widening the union:
Why new copy instead of reusing
unavailableReusing the existing
unavailablestrings would have avoided two new keys, and that is a real cost. It loses on remedy accuracy, which matters more here:unavailable's description is "Orca cannot verify this folder right now. Check the runtime or SSH connection and try again." But the host did verify — it returnedexists: falsewith a definite reason. It is this client that cannot name it. Sending the user to inspect a healthy SSH connection and retry is a false lead that costs them time and does not fix anything.STYLEGUIDE.mdrequires displayed copy to be "concise and specific";Cannot check folderis neither, applied to a folder the host checked.New strings, following the
#15002precedent:unrecognized: Folder is not usableunrecognized: Orca cannot use {{path}}, and this version does not recognize the reason. Update Orca to see the details.The indicator still renders, and
isConfirmedStaleFolderPathStatusreturningfalsekeeps it on the neutraltext-muted-foregroundstyle rather than the destructive one — an imprecise visible warning, which beats a silently missing one.isConfirmedStaleFolderPathStatusandblocksFolderWorkspaceActivationare safe, and here is whyBoth consume the same cast value, but they are not the same class of exposure. The switches lost all output on a miss; these two have a well-defined
falsefallback that is exactly the behavior already chosen deliberately forunavailable.isConfirmedStaleFolderPathStatusreturnsfalsefor an unrecognized reason. That is literally correct by the function's own contract: an unknown reason is by definition not confirmed stale. The only effect is that the indicator renders muted rather than destructive — the correct call when we cannot tell.blocksFolderWorkspaceActivationreturnsfalse, so activation stays permitted. This is deliberate fail-open, matchingunavailableand absent-reason. Flipping it to fail-closed would lock a user out of a working folder workspace the moment a host adds a benign informational reason, and the operation would surface its own error anyway if the folder really is gone. Fail-open on activation plus fail-visible on the warning is the right split; this PR only had to repair the second half.An explicit
reason: nullstays in the unrecognized bucket, deliberatelyreasonis optional, sonullis a shape a differently-implemented host could put on the wire. It is tempting to foldnullin withundefined, but that would reintroduce the bug: TypeScript seesreasonasReason | undefined, socase undefined:does not matchnull, and anulladmitted by the guard would fall straight back out of the switch. Routingnullto the unrecognized copy is the shape that cannot fall through.Sweep for other switches on this wire
In this defect's blast radius (fixed here): the two switches in
folder-workspace-path-status.ts. The other four readers ofFolderWorkspacePathStatus.reason(SectionHeader.tsx:73,folder-row.tsx:67,folder-workspace-composer-path-status.ts:118,124, and the two shared predicates) are equality comparisons with a definedfalsebranch, not switches — same fail-open reasoning as above.Found, out of scope, filed for follow-up:
sshHealthinsrc/shared/execution-host-registry.ts:113is a genuine same-class exposure on a different wire field.SshConnectionStatearrives cast fromcallRuntimeRpc<{ state: SshConnectionState | null }>atruntime-environment-ssh-state.ts:83and:278. Its switch is exhaustive over eightSshConnectionStatusmembers plusundefined, with no guard, and its result is assigned straight into the non-nullablehealth: ExecutionHostHealthat:278. A ninth status from a newer host yieldshealth: undefined, andsetHost'sif (existing.health !== 'disconnected') returnthen prevents any later registration from upgrading it. Not fixed here — different feature, different wire field.runtimeControlHealthat:99reads the same kind of wire value but is benign: itsundefinedis absorbed bycontrolHealth ?? runtimeHealth(...)at:167.Checked and cleared — their discriminants are computed in the local main process or in-renderer, not published by a paired host:
external-automation-display.ts:37,50(ExternalAutomationRunStatus, produced by the local external manager overipcRenderer.invoke),skill-install-result-label.ts:4,skill-freshness-scan-issues.tsx:5,project-skill-runtime.ts:66, andlocal-base-ref-refresh-toast.ts:9.Tests
Each new wire test was proven red against
main's version of the source file only, with the test files untouched:Green on this branch, together with #15002's unchanged tests — which is the proof that moving its two guards onto the shared helper kept behavior identical:
The
['missing']cases are the P1 from #15002, now covered at both call sites and at the indicator.src/shared/handled-wire-discriminant.test.tspins the shared primitive's own contract, including the case none of the call-site tests reach:Object.hasOwn, notin, so'toString'/'constructor'/'__proto__'are not handled members.The
typeofcheck was mutation-tested rather than assumed. Replacing the helper body withObject.hasOwn(handled, value as string)fails six tests across all four call sites plus the helper's own:Gates
A follow-up worth noting for the composer: with the fix,
folder-workspace-composer-path-status.ts:128now produces a non-nullpathStatusProjectErrorfor an unrecognized reason where it previously producednull. That surfaces asinvalidstyling plus a message on the project field (NewWorkspaceComposerCard.tsx:704,707) and does not newly block creation —createDisabledis driven bypathStatusBlocksCreate, which this PR does not touch. Verified by reading both consumers.The first typecheck run caught a real error in the new
.tsxtest (TS6133: 'React' is declared but its value is never read), which is worth noting:src/**/*.test.tsxis typechecked, unliketests/.