Skip to content

refactor(runtime): declare the host-status entry once instead of per consumer - #20262

Merged
nwparker merged 3 commits into
mainfrom
astra/shared-host-status-type
Sep 17, 2026
Merged

nwparker merged 3 commits into
mainfrom
astra/shared-host-status-type

Conversation

@nwparker

@nwparker nwparker commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​66 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​66
Prod 8 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​34 $\color{#cf222e}{\Huge{\mathbf{−}}}$​48 $\color{#cf222e}{\Huge{\mathbf{−}}}$​14

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/shared should not import a renderer store type, so execution-host-registry.ts declared 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.ts dates it:

Commit Change
200d8a57384 created the copy as { status?, appVersion? }
1a47b9ee854 fix(remote): distinguish SSH transport from runtime availability (#17710) — added remoteControl?
3b82d8de642 fix(runtime): let connections own host status recovery (#20003) — added snapshot?

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.ts declared { status?, appVersion? } — no snapshot, no remoteControl — and passed that map straight into buildExecutionHostRegistry.
  • src/renderer/src/components/automations/automation-target-availability.ts declared { 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. addRuntimeHost reads snapshot.verification and snapshot.transport before falling back to runtimeHealth, 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.ts asserts, via expectTypeOf, that the entry accepted by each reader equals the store's entry. On the parent commit those three assertions fail under pnpm tc and 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 carry checkedAt, which makes them match what the store actually holds.

I deliberately did not narrow the readers to Pick<RuntimeEnvironmentStatus, …> to avoid the fixture churn. A Pick is 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

  • No behavioural change. Every production hunk is a type import or a parameter annotation.
  • RuntimeEnvironmentStatus keeps its name and is re-exported from runtime-status-types.ts, so the ~76 files that reference it are untouched.
  • Based on main at 341b13cf679.

Verification

  • pnpm tc — clean
  • pnpm test on the four affected files — 41 passed
  • pnpm run check:code-quality:changed — 0 new findings across 9 changed files

Follow-up commit: refactor(automations): retire the three copies that only forward the map

Adversarial 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.ts
  • src/renderer/src/components/automations/AutomationListLocalRow.tsx
  • src/renderer/src/components/automations/AutomationsListPanel.tsx

These 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. AutomationsListPanelProps is exported so the assertion can name it.

Mutation-checked, the same way as the original three: reverting AutomationsListPanel.tsx to the narrow shape fails pnpm tc with TS2344 naming the drifted fields; restoring it returns exit 0. The assertion is not inert.

Verification of the follow-up

pnpm tc exit 0, zero error TS. pnpm test over src/renderer/src/components/automations, src/shared/execution-host-registry.test.ts, sidebar-host-options.test.ts, palette-host-badge.test.ts and the parity test: 106 passed (106) / 870 passed (870). check:code-quality:changed against main exit 0.

Rebased onto current main (it was ~430 commits behind at 341b13cf679); verified to contain origin/main and to touch only its own files.

Ordering note

This PR conflicts textually with #20359, which adds hostContactEpoch to the inline RuntimeEnvironmentStatus in runtime-status-types.ts — the declaration this PR deletes. Whichever lands second needs a one-line resolution: put hostContactEpoch on the shared declaration in src/shared/runtime-host-status.ts and keep runtime-status-types.ts as the re-export. Landing this one first is the cheaper order.

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.
@nwparker
nwparker force-pushed the astra/shared-host-status-type branch from 6d47f2e to 81e88c6 Compare September 17, 2026 06:58
@nwparker
nwparker marked this pull request as ready for review September 17, 2026 07:11
@nwparker
nwparker merged commit 779667c into main Sep 17, 2026
29 checks passed
@nwparker
nwparker deleted the astra/shared-host-status-type branch September 17, 2026 07:11
@coderabbitai

coderabbitai Bot commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: fe5f942c-1660-4210-9bde-34291ff111b9

📥 Commits

Reviewing files that changed from the base of the PR and between 560c42e and 81e88c6.

📒 Files selected for processing (12)
  • src/renderer/src/components/automations/AutomationListLocalRow.tsx
  • src/renderer/src/components/automations/AutomationsListPanel.tsx
  • src/renderer/src/components/automations/automation-source-context.ts
  • src/renderer/src/components/automations/automation-target-availability.ts
  • src/renderer/src/components/cmd-j/palette-host-badge.test.ts
  • src/renderer/src/components/sidebar/sidebar-host-options.test.ts
  • src/renderer/src/components/sidebar/sidebar-host-options.ts
  • src/renderer/src/store/slices/runtime-host-status-entry-parity.test.ts
  • src/renderer/src/store/slices/runtime-status-types.ts
  • src/shared/execution-host-registry.test.ts
  • src/shared/execution-host-registry.ts
  • src/shared/runtime-host-status.ts

📝 Walkthrough

Walkthrough

The pull request adds the shared RuntimeEnvironmentStatus type and removes the local registry wrapper. Runtime status map readers in shared and renderer code now use this type. AutomationsListPanelProps is exported. Type-level parity tests cover six readers. Existing test fixtures now include checkedAt.

✨ 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.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ No new issues found.

Reviewed changes

  • Single declaration for the host-status entry. RuntimeEnvironmentStatus now lives in src/shared/runtime-host-status.ts:26 and is re-exported from runtime-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.ts derives each reader's accepted entry and asserts toEqualTypeOf<RuntimeEnvironmentStatus>(). config/tsconfig.tc.web.json includes src/renderer/src/**/*, so pnpm tc evaluates it — the assertion is a mutation guard, not a runtime no-op in the sense that matters.
  • Fixtures updated for the now-required checkedAt in execution-host-registry.test.ts, sidebar-host-options.test.ts, and palette-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.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

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