Repository navigation
fix(automations): a legacy automation on a twin project refuses instead of running on a guessed host - #31234
Conversation
…ad of running on a guessed host
…pshot, only where it keeps the folder
…ther run captured it first
📝 Walkthrough
Priority: ⬇️ Low Merge Risk: 🟡 Moderate · up to
|
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:
f9afbc8f-149a-44e3-ad6f-c24273b8cd29
📒 Files selected for processing: 7
src/main/automations/run-target-resolution.test.tssrc/main/automations/run-target-resolution.tssrc/main/automations/service.tssrc/main/persistence-legacy-automation-twin-host.test.tssrc/main/persistence/loading-store/automation-persistence.tssrc/main/persistence/scheduling-automations/automation-context-migration.tssrc/main/persistence/scheduling-automations/automation-definition-operations.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 1 remain after this review.
| // Why: a repo id on two hosts names no host, so the load leaves it for dispatch to refuse. | ||
| const reposById = new Map<string, Repo | undefined>() | ||
| for (const repo of state.repos ?? []) { | ||
| reposById.set(repo.id, reposById.has(repo.id) ? undefined : repo) | ||
| } |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
#!/bin/bash
# Find consumers and writers of Automation.sourceContext to see whether a null value is re-derived later.
rg -nP --type=ts -C3 '\bsourceContext\b' src/main/automations src/main/persistence src/shared | rg -v '\.test\.ts' | head -n 120Repository: stablyai/orca
Length of output: 11894
🏁 Script executed:
#!/bin/bash
set -e
printf '%s\n' '--- automation-context-migration.ts ---'
nl -ba src/main/persistence/scheduling-automations/automation-context-migration.ts | sed -n '100,235p'
printf '%s\n' '--- automation-definition-operations.ts ---'
nl -ba src/main/persistence/scheduling-automations/automation-definition-operations.ts | sed -n '1,225p'
printf '%s\n' '--- related selector/run-target references ---'
rg -n -F --type=ts -e 'selectorMoveRequested' -e 'captureLegacyRunTarget' -e 'resolveAutomationRunTarget' -e 'stampLegacyAutomationRunContext' src/main src/shared || test "$?" -eq 1
printf '%s\n' '--- relevant tests ---'
rg -n -F --type=ts -e 'sourceContext' -e 'twin' -e 'duplicate' -e 'ambiguous' src/main/persistence-legacy-automation-twin-host.test.ts src/main/automations src/main/persistence/scheduling-automations || test "$?" -eq 1Repository: stablyai/orca
Length of output: 29207
🏁 Script executed:
#!/bin/bash
set -e
printf '%s\n' '--- run-target-resolution.ts ---'
nl -ba src/main/automations/run-target-resolution.ts | sed -n '1,180p'
printf '%s\n' '--- persistence stamp operation ---'
nl -ba src/main/persistence/loading-store/automation-persistence.ts | sed -n '135,175p'
nl -ba src/main/persistence/scheduling-automations/automation-definition-operations.ts | sed -n '225,290p'
printf '%s\n' '--- source-context definitions ---'
rg -n -F --type=ts -e 'function buildTaskSourceContextFromRepo' -e 'buildTaskSourceContextFromRepo' -e 'type TaskSourceContext' -e 'interface TaskSourceContext' src/shared src/main | head -n 80
printf '%s\n' '--- updateAutomation callers and host selection fields ---'
rg -n -P --type=ts 'updateAutomation\(|projectId:|sourceContext:' src/main src/renderer src/shared | rg -v '\.test\.ts' | head -n 220
printf '%s\n' '--- twin-host test ---'
nl -ba src/main/persistence-legacy-automation-twin-host.test.ts | sed -n '1,210p'Repository: stablyai/orca
Length of output: 44759
🏁 Script executed:
#!/bin/bash
set -e
printf '%s\n' '--- automation files ---'
rg --files src | rg 'automation|Automation' | head -n 160
printf '%s\n' '--- update IPC and renderer references ---'
rg -n -P --type=ts --type=tsx 'updateAutomation|automations:update|automation.*update|projectHostSetupId|hostId' src/main/ipc src/renderer/src | rg -i 'automation|schedule|editor|host|project' | head -n 260
printf '%s\n' '--- task source context implementation ---'
nl -ba src/shared/task-source-context.ts | sed -n '1,145p'
printf '%s\n' '--- automation RPC contract ---'
nl -ba src/shared/rpc-contract/automation-params.ts | sed -n '1,145p'Repository: stablyai/orca
Length of output: 19593
🏁 Script executed:
#!/bin/bash
set -e
printf '%s\n' '--- automation IPC ---'
nl -ba src/main/ipc/automations.ts | sed -n '1,280p'
printf '%s\n' '--- all updateAutomation call sites ---'
rg -n -F -g '*.ts' -g '*.tsx' -- 'updateAutomation' src | head -n 240
printf '%s\n' '--- automation UI files and host terms ---'
rg --files src/renderer | rg -i 'automation|schedule' | head -n 240
rg -n -i -F -g '*.ts' -g '*.tsx' -e 'pick the host' -e 'hostId' -e 'projectHostSetupId' -e 'automation' src/renderer/src | rg -i 'automation|schedule|host' | head -n 260
printf '%s\n' '--- sourceContext consumers in automation paths ---'
rg -n -F -g '*.ts' -g '*.tsx' -- 'sourceContext' src/main/automations src/main/persistence/scheduling-automations src/renderer/src | rg -i 'automation|run|source' | head -n 220Repository: stablyai/orca
Length of output: 42103
🏁 Script executed:
#!/bin/bash
set -e
printf '%s\n' '--- renderer automation save operations ---'
nl -ba src/renderer/src/components/automations/automation-orca-save-operations.ts | sed -n '1,330p'
printf '%s\n' '--- renderer automation host client ---'
nl -ba src/renderer/src/components/automations/automation-host-client.ts | sed -n '1,210p'
printf '%s\n' '--- automation management actions ---'
nl -ba src/renderer/src/components/automations/automation-management-actions.ts | sed -n '1,120p'
printf '%s\n' '--- automation target/editor references ---'
rg -n -F -g '*.ts' -g '*.tsx' -e 'destination' -e 'projectId' -e 'hostId' -e 'runContext' src/renderer/src/components/automations src/renderer/src/hooks | head -n 260Repository: stablyai/orca
Length of output: 41669
🏁 Script executed:
#!/bin/bash
set -e
printf '%s\n' '--- automation run creation and source-context consumers ---'
nl -ba src/main/persistence/scheduling-automations/automation-run-operations.ts | sed -n '60,115p'
rg -n -F -g '*.ts' -g '*.tsx' -e 'run.sourceContext' -e 'automationRun.sourceContext' -e 'sourceContext: run.' -e 'sourceContext: automationRun' src | head -n 180
printf '%s\n' '--- source context migration tests and relevant base diff ---'
git diff --unified=30 3be5039eed0ac7340b55bc92be5a504b1568a668 1017ef06198ed84ceed2ccd732349f7fe529f87a -- src/main/persistence/scheduling-automations/automation-context-migration.ts src/main/persistence/scheduling-automations/automation-run-operations.tsRepository: stablyai/orca
Length of output: 5912
Do not persist sourceContext: null for an ambiguous repository ID.
An ambiguous ID currently backfills both contexts as null. Later loads then skip sourceContext because the property exists. If one twin is removed, captureLegacyRunTarget stamps only runContext, so a subsequent run can still copy sourceContext: null.
Keep sourceContext absent while the repository ID is ambiguous. The next load can then derive it when one repository remains. Do not derive it from an arbitrary twin because TaskSourceContext includes host identity.
🐛 Suggested fix
const contextsByAutomationId = new Map<string, Pick<Automation, 'runContext' | 'sourceContext'>>()
// Why: a repo id on two hosts names no host, so the load leaves it for dispatch to refuse.
const reposById = new Map<string, Repo | undefined>()
+ const ambiguousRepoIds = new Set<string>()
for (const repo of state.repos ?? []) {
- reposById.set(repo.id, reposById.has(repo.id) ? undefined : repo)
+ if (reposById.has(repo.id)) {
+ ambiguousRepoIds.add(repo.id)
+ reposById.set(repo.id, undefined)
+ } else {
+ reposById.set(repo.id, repo)
+ }
}
const automations = (state.automations ?? []).map((automation) => {
+ const legacyRepoId = getAutomationLegacyRepoId(automation)
const contexts = getAutomationContextsForRepo(
- reposById.get(getAutomationLegacyRepoId(automation)),
+ reposById.get(legacyRepoId),
state.projectHostSetups ?? []
)
const next: Automation = { ...automation }
@@
- if (!Object.hasOwn(next, 'sourceContext')) {
+ if (!Object.hasOwn(next, 'sourceContext') && !ambiguousRepoIds.has(legacyRepoId)) {
next.sourceContext = contexts.sourceContext
changed = true
}There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to GitHub limitations.
🟠 Major · Apply remote-host refusal checks to uncaptured legacy targets. · run-target-resolution.ts:154
src/main/automations/run-target-resolution.ts:154
🎯 Functional Correctness | 🟠 Major | ⚡ Quick winApply remote-host refusal checks to uncaptured legacy targets.
When
automation.runContextis absent, this branch returnsresolveLegacyAutomationRunTargetwithout checkingoptions.allowRemoteHostSchedulingorautomation.schedulerOwner. A unique legacy automation on a runtime host can therefore proceed when remote scheduling is disabled or the owner is notremote_host_service.captureLegacyRunTargetdoes not prevent this because it leaves the automation uncaptured before this branch runs. Apply the same refusal used at Lines 157-165 before returning the legacy result.
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
00b3550f-a304-43c9-9ad6-03411dd92bf6
📒 Files selected for processing: 1
src/main/automations/run-target-resolution.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 2 remain after this review.
ELI5
Old automations only remember a project id. If that project is now added on two machines (say this laptop and an SSH server), Orca used to guess which machine to run on. It now refuses with a message telling you to open the automation and pick the host. If only one machine has the project, Orca writes that machine down the first time the automation runs, so a second copy added later can't make it ambiguous.
What Changed
Before:
runContext) looked up its project with a host-blindgetRepo(id). With the same repo id on two hosts it ran on whichever row was listed first. For example, a local automation ran in the SSH copy's folder, or was refused with the unhelpful "This automation has no host to run on."runContextto old records also picked a twin row at random (the last one in a by-id map).After:
runContextto the stored automation once. This goes through a new write-once store operation,stampLegacyAutomationRunContext, and needs no new schema. It only does this when the captured target would run on the same row in the same folder as today. An existing-workspace record whose folder is not the repo root is left as it is. The capture happens before the dispatch snapshot, so the first run still launches instead of being refused as "changed".recordRefusedRun) and prechecks never write.Mechanism:
resolveAutomationRunTarget's legacy branch (src/main/automations/run-target-resolution.ts) now counts rows with the id before doing anything else. The newcaptureLegacyRunTargetis called fromAutomationService.runNowandevaluateAutomation.backfillLegacyAutomationContextsmaps a twin id to no row.Why
runContextis an existing field that older clients and hosts already read, so a captured record works on older peers unchanged.Linked Issue
N/A (internal follow-up).
Visual Proof
N/A: main-process scheduling only. The only visible change is the text of a skipped run.
Testing
src/main/persistence-legacy-automation-twin-host.test.tsruns against a real store (SQLite profile state) and AutomationService:runNow, still dispatches, and keeps the capture after a reload;recordRefusedRunnever captures;The first three fail on main.
src/main/automationsfolder (36 files) passes single-worker.Full static-analysis job run locally.
Not verified live on a real machine: this is a scheduling decision in the main process, with no SSH or terminal I/O involved.
Automated tests added/updated
Review
Codex (gpt-6.1-sol, high) and an independent Opus review.
Agent skill upstream boundary
Notes
getRepos()filter per legacy record per tick.Checklist
N/Avisual proof with reason