Repository navigation
refactor(renderer): no rebound-settings owner pattern - #27607
Conversation
📝 Walkthrough
Priority: ⬇️ Low Merge Risk: 🟡 Moderate · up to 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 |
|
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
8e937f7e-964f-4456-b76b-899d85c1c958
📒 Files selected for processing (22)
config/focus-setting-read-baseline.txtconfig/scripts/repo-owner-settings-selector-benchmark.mjssrc/renderer/src/components/NewWorkspaceComposerCard.file-drop.test.tsxsrc/renderer/src/components/automations/use-automations-page-setup-state.test.tsxsrc/renderer/src/components/automations/use-automations-page-setup-state.tssrc/renderer/src/hooks/composer-state/async-composer-state.tssrc/renderer/src/hooks/composer-state/async-model.tssrc/renderer/src/hooks/composer-state/attachment-drop-failure.test.tsxsrc/renderer/src/hooks/composer-state/attachment-drop-lifetime.test.tsxsrc/renderer/src/hooks/composer-state/attachment-drop-state.tssrc/renderer/src/hooks/composer-state/composer-attachment-drop-state.tssrc/renderer/src/hooks/composer-state/composer-attachment-target.test.tssrc/renderer/src/hooks/composer-state/composer-attachment-target.tssrc/renderer/src/hooks/composer-state/composer-remote-server-drop.test.tsxsrc/renderer/src/hooks/composer-state/composer-source-model.tssrc/renderer/src/hooks/composer-state/composer-target-state.tssrc/renderer/src/hooks/composer-state/runtime-target-model.tssrc/renderer/src/hooks/composer-state/runtime-target-selection.tssrc/renderer/src/hooks/composer-state/server-ssh-repo-connect.test.tssrc/renderer/src/hooks/composer-state/workspace-identity-state.tssrc/renderer/src/lib/repo-runtime-owner.test.tssrc/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 |
There was a problem hiding this comment.
🎯 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.tsRepository: 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/srcRepository: 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.tsRepository: 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.tsRepository: 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
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.
getSettingsForRepoRuntimeOwneris gone fromlib/repo-runtime-owner.ts, with its per-repo identity cache (256-entry map). It returned{ ...settings, activeRuntimeEnvironmentId: getRuntimeEnvironmentIdForRepo(...) }. Its three remaining callers now callgetRuntimeEnvironmentIdForRepo(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.hooks/composer-state/):selectedRepoSettings(a settings object) becomesselectedRepoRuntimeEnvironmentId: string | nullon the way fromruntime-target-selection.tsthroughworkspace-identity-state.tsand the attachment-drop hooks. It is stillnullwhile settings are unloaded.resolveComposerAttachmentTargetreturnsruntimeEnvironmentIdinstead of a settings object (it already ignored the incoming settings value and overrode it from the destination host).uploadComposerPathstakes that id as its second argument.selectedRepoSettingsRefhad no reader and is removed.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.mjsdeleted. It measured the identity cache insideuseShallowselectors. No selector calls this anymore (all three callers run inuseMemo/useCallback/render), and a string compares by value, so there is nothing left to measure..activeRuntimeEnvironmentIdread instead. Now the one real read is counted where it happens, inruntime-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 nouseShallowcaller 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-selectorwith--hiddenover the whole worktree (src, config, scripts, tests, mobile, packages, including@ts-nocheckfiles) finds nothing.repo-runtime-ownerhas no importer outsidesrc/renderer.build:electron-vitepasses. 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
pnpm tc,pnpm lint(focus-read ratchet OK, 1133),oxlint,pnpm run check:code-quality:changed(0 new findings),build:electron-vite: pass.pnpm testonlib/repo-runtime-owner.test.ts,components/automations/,hooks/composer-state/, and the 18 composer/automations page test files: 1292 tests pass.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 coversuse-automations-page-setup-state.test.tsx. The identity-cache tests are deleted along with the cache.AI Disclosure
Review
P0/P1 only, on head c801524.
Agent skill upstream boundary
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
useCallbackdeps now change only when the owner id changes.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)