Skip to content

refactor(renderer): no rebound-settings owner pattern - #27607

Merged
OrcaWin merged 2 commits into
mainfrom
OrcaWin/p399-D2
Oct 11, 2026
Merged

OrcaWin merged 2 commits into
mainfrom
OrcaWin/p399-D2

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Oct 11, 2026 •

Copy link
Copy Markdown
Collaborator

ELI5

When the new-workspace composer and the Automations page needed to know "which paired server owns this project?", they built a whole copy of the app settings with one field swapped, then read that one field back out. This PR asks the same question directly and gets back just the answer (a server id, or nothing for this computer). Same answers, less machinery.

What Changed

Renderer only. Phase 3.99 PR D2. No user-visible change.

  • getSettingsForRepoRuntimeOwner is gone from lib/repo-runtime-owner.ts, with its per-repo identity cache (256-entry map). It returned { ...settings, activeRuntimeEnvironmentId: getRuntimeEnvironmentIdForRepo(...) }. Its three remaining callers now call getRuntimeEnvironmentIdForRepo (the resolver it wrapped) themselves. That resolver is unchanged, so its fallback to the focused server for unstamped, missing or duplicate rows is unchanged too. Narrowing that fallback is a separate, later decision.
  • Composer (hooks/composer-state/): selectedRepoSettings (a settings object) becomes selectedRepoRuntimeEnvironmentId: string | null on the way from runtime-target-selection.ts through workspace-identity-state.ts and the attachment-drop hooks. It is still null while settings are unloaded. resolveComposerAttachmentTarget returns runtimeEnvironmentId instead of a settings object (it already ignored the incoming settings value and overrode it from the destination host). uploadComposerPaths takes that id as its second argument. selectedRepoSettingsRef had no reader and is removed.
  • Automations (use-automations-page-setup-state.ts): the hook cache keys are still ${env ?? 'local'}:${repoId}. The settings copy built only to derive the key is gone. A new test pins the key strings for runtime, local, unstamped, missing and duplicate rows.
  • config/scripts/repo-owner-settings-selector-benchmark.mjs deleted. It measured the identity cache inside useShallow selectors. No selector calls this anymore (all three callers run in useMemo/useCallback/render), and a string compares by value, so there is nothing left to measure.
  • Focus-read baseline goes from 7 to 1 for these files (−6). The ratchet could not see the focus read inside the old helper, because the helper returned an object literal. So it counted each downstream .activeRuntimeEnvironmentId read instead. Now the one real read is counted where it happens, in runtime-target-selection.ts (a new 1-line baseline entry).

Net: +141 / −445 (−304). Production src/: +32 / −111 (−79). Benchmark: −207. Tests: +106 / −120 (−14). Baseline: −3.

Why

A settings object with one field rebound looks like settings, so the next reader may trust its other fields or pass it somewhere that reads them. A scalar says what it is. I kept the same resolver rather than switching to the strict owner-only one (getExplicitRuntimeOwnerEnvironmentId): the strict one would stop unstamped repos from following the focused server, which is a behaviour change. The design says the identity cache should stay. I dropped it anyway, because current main has no useShallow caller left (earlier Phase 3.99 PRs removed them), and a string needs no identity cache.

Dead-code proof: rg getSettingsForRepoRuntimeOwner|ownerRoutedSettings|selectedRepoSettings|repo-owner-settings-selector with --hidden over the whole worktree (src, config, scripts, tests, mobile, packages, including @ts-nocheck files) finds nothing. repo-runtime-owner has no importer outside src/renderer. build:electron-vite passes. CLI and orcad do not import the renderer.

Linked Issue

N/A (maintainer refactor, Phase 3.99 cleanup).

Visual Proof

N/A. No UI or behaviour change; the same owner id reaches the same consumers.

Testing

  • Automated tests added/updated, or explained why not below
  • pnpm tc, pnpm lint (focus-read ratchet OK, 1133), oxlint, pnpm run check:code-quality:changed (0 new findings), build:electron-vite: pass.
  • pnpm test on lib/repo-runtime-owner.test.ts, components/automations/, hooks/composer-state/, and the 18 composer/automations page test files: 1292 tests pass.
  • New owner matrix (repo-runtime-owner.test.ts) covers local, direct SSH, nested runtime-over-SSH, unstamped, missing, and duplicate rows with local, matching, other and deleted focus. A new cache-key test covers use-automations-page-setup-state.test.tsx. The identity-cache tests are deleted along with the cache.
  • SSH: a direct SSH repo still resolves to no runtime (local IPC, fenced by its connection id). A server-owned repo still resolves to its server. Folder projects use the attachment target's host as before.

AI Disclosure

Review

P0/P1 only, on head c801524.

  • Self review: NO P0/P1. Old and new were compared per call site for unloaded settings, no selected repo, unstamped, runtime-stamped, SSH and duplicate rows.
  • Codex (GPT-6.1 Sol, high, read-only): NO P0/P1. It confirmed the resolver is unchanged, the composer keeps its unloaded-settings guard, the attachment target and upload defaults are unchanged, and the automation cache keys are byte-identical. It found no remaining references. The read-only renderer typecheck passed.

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Security, cross-platform, SSH, mobile and wire: no change. This is renderer-internal and nothing crosses a process or wire boundary. Performance: one string per render replaces a cached object, and useCallback deps now change only when the owner id changes.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

@coderabbitai

coderabbitai Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

📝 Walkthrough
📝 Walkthrough

Walkthrough

The repo-specific settings cache and its benchmark are removed. Automation setup and hook cache keys now use repository runtime environment IDs. Composer target selection, workspace identity, and attachment uploads pass runtime environment IDs instead of selected repository settings. Tests and focus-read baseline entries are updated.



Priority: ⬇️ Low

Merge Risk: 🟡 Moderate · up to c8015

Files attached to a repository that follows the focused remote runtime may stay as local paths instead of being imported to that runtime, so the remote agent cannot access them. Fix this before merging.

Pre-merge checks | Passed 4 | Failed 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 8.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 12 functions across 18 files. (1 skipped: … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
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.
Title check Passed The title clearly and concisely describes the renderer refactor that removes the rebound-settings owner pattern.
Description check Passed The description is complete and aligned with the template. It explains the change, motivation, testing, compatibility considerations, review results, and the absence of visual changes. The maintainer-…

Full details: Docstring Coverage

Explanation

Docstring coverage is 8.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 12 functions across 18 files. (1 skipped: 1 unsupported.)


  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR



  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@coderabbitai coderabbitai 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.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 8e937f7e-964f-4456-b76b-899d85c1c958
📥 Commits

Reviewing files that changed from the base of the PR and between aa1eca1 and c801524.

📒 Files selected for processing (22)
  • config/focus-setting-read-baseline.txt
  • config/scripts/repo-owner-settings-selector-benchmark.mjs
  • src/renderer/src/components/NewWorkspaceComposerCard.file-drop.test.tsx
  • src/renderer/src/components/automations/use-automations-page-setup-state.test.tsx
  • src/renderer/src/components/automations/use-automations-page-setup-state.ts
  • src/renderer/src/hooks/composer-state/async-composer-state.ts
  • src/renderer/src/hooks/composer-state/async-model.ts
  • src/renderer/src/hooks/composer-state/attachment-drop-failure.test.tsx
  • src/renderer/src/hooks/composer-state/attachment-drop-lifetime.test.tsx
  • src/renderer/src/hooks/composer-state/attachment-drop-state.ts
  • src/renderer/src/hooks/composer-state/composer-attachment-drop-state.ts
  • src/renderer/src/hooks/composer-state/composer-attachment-target.test.ts
  • src/renderer/src/hooks/composer-state/composer-attachment-target.ts
  • src/renderer/src/hooks/composer-state/composer-remote-server-drop.test.tsx
  • src/renderer/src/hooks/composer-state/composer-source-model.ts
  • src/renderer/src/hooks/composer-state/composer-target-state.ts
  • src/renderer/src/hooks/composer-state/runtime-target-model.ts
  • src/renderer/src/hooks/composer-state/runtime-target-selection.ts
  • src/renderer/src/hooks/composer-state/server-ssh-repo-connect.test.ts
  • src/renderer/src/hooks/composer-state/workspace-identity-state.ts
  • src/renderer/src/lib/repo-runtime-owner.test.ts
  • src/renderer/src/lib/repo-runtime-owner.ts
💤 Files with no reviewable changes (3)
  • config/scripts/repo-owner-settings-selector-benchmark.mjs
  • src/renderer/src/lib/repo-runtime-owner.ts
  • src/renderer/src/hooks/composer-state/async-model.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 4 remain after this review.

...input.selectedRepoSettings,
activeRuntimeEnvironmentId: host?.kind === 'runtime' ? host.environmentId : null
}
runtimeEnvironmentId: host?.kind === 'runtime' ? host.environmentId : null

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.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

#!/bin/bash
# Confirm the execution host selected for a repo without either host stamp.
ast-grep outline src/shared/execution-host.ts --match getRepoExecutionHostId --view expanded
rg -n -C 10 'function getRepoExecutionHostId' src/shared/execution-host.ts

Repository: stablyai/orca

Length of output: 1057


🏁 Script executed:

set -eu
printf '%s\n' '--- execution-host helpers ---'
sed -n '1,230p' src/shared/execution-host.ts
printf '%s\n' '--- attachment target ---'
sed -n '1,180p' src/renderer/src/hooks/composer-state/composer-attachment-target.ts
printf '%s\n' '--- target resolver references ---'
rg -n -F --glob '*.{ts,tsx}' -- 'resolveComposerAttachmentTarget' src/renderer/src
printf '%s\n' '--- uploadComposerPaths references and implementation ---'
rg -n -C 12 --glob '*.{ts,tsx}' -- 'uploadComposerPaths' src/renderer/src

Repository: stablyai/orca

Length of output: 37976


🏁 Script executed:

set -eu
printf '%s\n' '--- complete upload implementation ---'
sed -n '120,210p' src/renderer/src/hooks/composer-state/attachment-drop-state.ts
printf '%s\n' '--- attachment target callers ---'
sed -n '1,120p' src/renderer/src/hooks/composer-state/composer-card-props.ts
sed -n '1,90p' src/renderer/src/hooks/composer-state/composer-attachment-drop-state.ts
printf '%s\n' '--- composer model host fields and target wiring ---'
rg -n -C 8 --glob '*.{ts,tsx}' -- 'selectedRepoExecutionHostId|selectedRepoRuntimeEnvironmentId|selectedRepoSettings' src/renderer/src/hooks/composer-state src/renderer/src
printf '%s\n' '--- relevant target tests ---'
sed -n '1,130p' src/renderer/src/hooks/composer-state/composer-attachment-target.test.ts

Repository: stablyai/orca

Length of output: 41976


🏁 Script executed:

set -eu
printf '%s\n' '--- target-state contract ---'
rg -n -C 12 --glob '*.ts' -- 'runtimeTargetSelection' src/renderer/src/hooks/composer-state
printf '%s\n' '--- runtime selection return ---'
sed -n '205,325p' src/renderer/src/hooks/composer-state/runtime-target-selection.ts
printf '%s\n' '--- composer target state contract ---'
sed -n '1,180p' src/renderer/src/hooks/composer-state/composer-target-state-contract.ts
printf '%s\n' '--- all resolver call blocks ---'
sed -n '1,30p' src/renderer/src/hooks/composer-state/composer-card-props.ts
sed -n '1,35p' src/renderer/src/hooks/composer-state/composer-attachment-drop-state.ts

Repository: stablyai/orca

Length of output: 42111


Preserve the focused runtime for unstamped repository attachments.

An unstamped repository can resolve to local while getRuntimeEnvironmentIdForRepo resolves its selected focused runtime. The attachment resolver currently drops that runtime ID. uploadComposerPaths then skips the remote import and keeps the original local attachment path.

Pass selectedRepoRuntimeEnvironmentId for repository targets. Keep project-group routing based on the group host.

🐛 Suggested fix
 type TargetInput = Pick<
   ComposerModel,
-  'selectedProjectGroup' | 'selectedRepoPath' | 'selectedRepoExecutionHostId' | 'connectionId'
+  | 'selectedProjectGroup'
+  | 'selectedRepoPath'
+  | 'selectedRepoExecutionHostId'
+  | 'selectedRepoRuntimeEnvironmentId'
+  | 'connectionId'
 > & { selectedRepo: Pick<Repo, 'id'> | undefined }
 
 export function resolveComposerAttachmentTarget(input: TargetInput) {
   const group = input.selectedProjectGroup
   const hostId = group ? getRepoExecutionHostId(group) : input.selectedRepoExecutionHostId
   const host = parseExecutionHostId(hostId)
@@
-    runtimeEnvironmentId: host?.kind === 'runtime' ? host.environmentId : null
+    runtimeEnvironmentId: group
+      ? host?.kind === 'runtime'
+        ? host.environmentId
+        : null
+      : (input.selectedRepoRuntimeEnvironmentId ??
+        (host?.kind === 'runtime' ? host.environmentId : null))
   }
 }
     selectedRepo: target.runtimeTargetSelection.selectedRepo,
     selectedRepoExecutionHostId: target.runtimeTargetSelection.selectedRepoExecutionHostId,
+    selectedRepoRuntimeEnvironmentId:
+      target.runtimeTargetSelection.selectedRepoRuntimeEnvironmentId,
     connectionId: target.workspaceIdentityState.connectionId

@OrcaWin
OrcaWin merged commit c9730df into main Oct 11, 2026
29 checks passed
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