Repository navigation
refactor(runtime): declare the host-status entry once instead of per consumer - #20262
Conversation
They pass the store map straight through, so nothing they do with it can ever fail on a missing field -- the drift lands in whatever they hand it to. Same declaration, and the parity test now covers them.
6d47f2e to
81e88c6
Compare
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (12)
📝 WalkthroughWalkthroughThe pull request adds the shared ✨ Finishing Touches📝 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 |
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Single declaration for the host-status entry.
RuntimeEnvironmentStatusnow lives insrc/shared/runtime-host-status.ts:26and is re-exported fromruntime-status-types.ts, so the ~76 existing importers keep working. The inline declaration is deleted. - Every forwarding consumer adopts the shared type. The registry alias (
execution-host-registry.ts:52), sidebar options (sidebar-host-options.ts:46), both automation availability readers, and the two automations props (AutomationListLocalRow.tsx:73,AutomationsListPanel.tsx:86) replace their hand-written structural copies. - Compile-time parity guard added.
runtime-host-status-entry-parity.test.tsderives each reader's accepted entry and assertstoEqualTypeOf<RuntimeEnvironmentStatus>().config/tsconfig.tc.web.jsonincludessrc/renderer/src/**/*, sopnpm tcevaluates it — the assertion is a mutation guard, not a runtime no-op in the sense that matters. - Fixtures updated for the now-required
checkedAtinexecution-host-registry.test.ts,sidebar-host-options.test.ts, andpalette-host-badge.test.ts.
Verification run this pass: pnpm run typecheck:web exit 0 (renderer + src/shared/**); focused vitest over the 5 affected files → 57 passed, including the 6 parity tests. I also traced every runtimeStatusByEnvironmentId reader: the remaining narrow copies (workspace-creator-visibility.ts:8, paired-runtime-parking-capabilities.ts:3, terminal-parked-tab-watchers.ts:60, SkillInstallTargetFields.tsx:27) only read .status and never forward the map, so they do not carry the drift failure mode this PR removes. No circular import was introduced (runtime-types.ts does not import runtime-host-status).
The only external caveat is the documented conflict with #20359 (hostContactEpoch), which is a landing-order coordination call, not a code issue.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

What
Declare the client-side runtime host-status entry once, in
src/shared/runtime-host-status.ts, and delete the four hand-written structural copies of it. No runtime behaviour changes — the production diff is entirely type declarations.Why: a reasonable boundary that decayed
The original decision was correct.
src/sharedshould not import a renderer store type, soexecution-host-registry.tsdeclared a local structural shape instead. That is a defensible call and this PR is not second-guessing it.The defect is the drift, not the decision.
git log -L 49,56:src/shared/execution-host-registry.tsdates it:200d8a57384{ status?, appVersion? }1a47b9ee854remoteControl?3b82d8de642snapshot?Both additions arrived as bugfixes, and both fields were added optional. That is the signature of a shadow copy being patched under pressure rather than a contract being designed — an optional field neither breaks a caller nor obliges one to read it, so nothing ever fails.
The tell that makes the drift demonstrable rather than inferred: two further copies are still frozen at the pre-#17710 vintage.
src/renderer/src/components/sidebar/sidebar-host-options.tsdeclared{ status?, appVersion? }— nosnapshot, noremoteControl— and passed that map straight intobuildExecutionHostRegistry.src/renderer/src/components/automations/automation-target-availability.tsdeclared{ status, checkedAt }, twice.Both typecheck against the store today, because everything they are missing is optional. The sidebar signature therefore states that snapshot evidence is unavailable to the registry, while at runtime all five callers pass the real store map and it is present.
addRuntimeHostreadssnapshot.verificationandsnapshot.transportbefore falling back toruntimeHealth, so the declaration is currently lying in the direction that hides the snapshot-aware path — and any future caller that builds a literal matching the declared type silently takes the fallback.How this is proven
The defect is a declaration lying, so there is no runtime assertion that can fail on it. The proof is a compile error:
src/renderer/src/store/slices/runtime-host-status-entry-parity.test.tsasserts, viaexpectTypeOf, that the entry accepted by each reader equals the store's entry. On the parent commit those three assertions fail underpnpm tcand pass afterwards. This mirrors the existing typed-contract tests, e.g.src/main/runtime/rpc/core-typed-method-contract.test.ts, which state the same thing in their header: the assertions fail at typecheck, not at runtime.The test is committed first (
41aac25) so the failure is reproducible on that commit alone.What deleting the copies surfaced
No production call site broke. The only mismatches were nine test fixtures that omit
checkedAt— required by the store entry, never read by these consumers. That is itself the point: the four shapes were structurally compatible everywhere it mattered, which is exactly why three rounds of drift produced no signal. The fixtures now carrycheckedAt, which makes them match what the store actually holds.I deliberately did not narrow the readers to
Pick<RuntimeEnvironmentStatus, …>to avoid the fixture churn. APickis a shadow copy with extra steps: a field added to the canonical type would once again be invisible to the reader, which is the failure this PR removes.Scope
RuntimeEnvironmentStatuskeeps its name and is re-exported fromruntime-status-types.ts, so the ~76 files that reference it are untouched.mainat341b13cf679.Verification
pnpm tc— cleanpnpm teston the four affected files — 41 passedpnpm run check:code-quality:changed— 0 new findings across 9 changed filesFollow-up commit:
refactor(automations): retire the three copies that only forward the mapAdversarial review found the sweep incomplete: three more copies of
{ status: RuntimeStatus | null; checkedAt: number }survive inside the same feature, and they feed the very consumer this PR just consolidated.src/renderer/src/components/automations/automation-source-context.tssrc/renderer/src/components/automations/AutomationListLocalRow.tsxsrc/renderer/src/components/automations/AutomationsListPanel.tsxThese are the purest instance of the failure mode the PR describes. All three only forward the store map to
getRuntimeAutomationAvailability/getRuntimeSourceHostAvailability— they never read a field themselves. So nothing they do with the map can fail on a field they are missing, and the drift lands in whatever they hand it to. They typecheck against the store today for exactly the reason the sidebar copy did: everything they omit is optional.All three now use
RuntimeEnvironmentStatus, and the parity test covers them.AutomationsListPanelPropsis exported so the assertion can name it.Mutation-checked, the same way as the original three: reverting
AutomationsListPanel.tsxto the narrow shape failspnpm tcwithTS2344naming the drifted fields; restoring it returns exit 0. The assertion is not inert.Verification of the follow-up
pnpm tcexit 0, zeroerror TS.pnpm testoversrc/renderer/src/components/automations,src/shared/execution-host-registry.test.ts,sidebar-host-options.test.ts,palette-host-badge.test.tsand the parity test:106 passed (106)/870 passed (870).check:code-quality:changedagainstmainexit 0.Rebased onto current
main(it was ~430 commits behind at341b13cf679); verified to containorigin/mainand to touch only its own files.Ordering note
This PR conflicts textually with #20359, which adds
hostContactEpochto the inlineRuntimeEnvironmentStatusinruntime-status-types.ts— the declaration this PR deletes. Whichever lands second needs a one-line resolution: puthostContactEpochon the shared declaration insrc/shared/runtime-host-status.tsand keepruntime-status-types.tsas the re-export. Landing this one first is the cheaper order.