Repository navigation
fix(orcad): free a lock whose PID another user now owns, and explain a possibly reused PID - #29548
Conversation
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 16 minutes. View limit details
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Priority: ⬇️ Low Merge Risk: 🔵 Low · 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:
adce3168-c5b0-4838-8a59-94f905b9b657
📒 Files selected for processing: 6
src/main/orcad/orcad-instance-lock.test.tssrc/main/orcad/orcad-instance-lock.tssrc/main/orcad/orcad-managed-stop-completion.tssrc/main/orcad/orcad-managed-stop-identity.test.tssrc/main/orcad/orcad-process-start-time.test.tssrc/main/orcad/orcad-process-start-time.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.
| if ((readers.platform ?? process.platform) !== 'linux') { | ||
| return 'differs' | ||
| } | ||
| return ownerProvesAnotherProcess(pid, recorded, readers) ? 'differs' : 'unproven' |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
grep -n 'unknown\|matches\|differs\|unproven\|ownerProvesAnotherProcess' src/main/orcad/orcad-process-start-time.ts
sed -n '120,160p' src/main/orcad/orcad-process-start-time.tsRepository: stablyai/orca
Length of output: 1907
🏁 Script executed:
set -eu
printf '%s\n' '--- identity helper and exported function ---'
nl -ba src/main/orcad/orcad-process-start-time.ts | sed -n '1,165p'
printf '%s\n' '--- direct consumers and related tests ---'
rg -n -F --glob '*.ts' -e 'compareOrcadProcessIdentity' -e "'differs'" -e "'unproven'" -e "'unknown'" src test tests 2>/dev/null || true
printf '%s\n' '--- lock/stop files mentioning identity verdicts ---'
rg -n -F --glob '*.ts' -e 'OrcadProcessIdentityVerdict' -e 'compareOrcadProcessIdentity' -e 'ownerProvesAnotherProcess' src 2>/dev/null || trueRepository: stablyai/orca
Length of output: 45665
🏁 Script executed:
set -eu
printf '%s\n' '--- lock consumer ---'
nl -ba src/main/orcad/orcad-instance-lock.ts | sed -n '1,190p'
printf '%s\n' '--- managed-stop consumer ---'
nl -ba src/main/orcad/orcad-managed-stop-completion.ts | sed -n '1,125p'
printf '%s\n' '--- identity tests ---'
nl -ba src/main/orcad/orcad-process-start-time.test.ts | sed -n '45,180p'Repository: stablyai/orca
Length of output: 20999
🏁 Script executed:
set -eu
nl -ba src/main/orcad/orcad-instance-lock.ts | sed -n '183,310p'Repository: stablyai/orca
Length of output: 6481
Use owner evidence when a Linux record has no start time.
When either start time is null, compareOrcadProcessIdentity returns unknown before ownerProvesAnotherProcess runs. Lock acquisition then refuses the live lock, and managed stop does not report the PID as exited. A different eligible UID therefore remains unproven while the replacement process is alive.
This is not permanent after the replacement process exits. Keep the matches path unchanged. A start time within tolerance is already accepted as a match; adding the owner check there would conflict with that result.
Suggested fix
const actual = (readers.startedAtMs ?? readOrcadProcessStartedAtMs)(pid)
if (actual === null || recorded.startedAtMs === null) {
+ if ((readers.platform ?? process.platform) === 'linux') {
+ return ownerProvesAnotherProcess(pid, recorded, readers) ? 'differs' : 'unknown'
+ }
return 'unknown'
}23dd218 to
de4422c
Compare
…, and explain a possibly reused PID Records written before #28125 carry no start ticks or boot id, so on Linux a wall-clock mismatch is unproven and a reused PID kept the lock held forever. A PID owned by another non-root uid cannot be the holder (orcad never changes uid), so that now proves reuse in both lock reclaim and managed stop. When the verdict stays unproven, the error names the live process and the orcad.lock path that is safe to remove once no orcad is running.
…D error for any boot-less record
…e platform hook also drives data-root privacy
de4422c to
8684266
Compare
ELI5
orcad (Orca's background server) keeps a lock file so two copies never share one data folder. The lock remembers the process ID (PID) of the orcad holding it. If that orcad crashes and the machine restarts, another program can end up with the same PID. Lock files written by older orcads don't record enough for Orca to tell the two apart on Linux, so Orca kept treating that unrelated program as orcad. orcad would not start, and the user wasn't told why. Now, if the PID belongs to a different user account, Orca knows it can't be orcad and takes the lock back. When Orca still can't tell, the error names the program it found and the exact file that is safe to delete.
What Changed
Before: on a Linux host (SSH or local headless), an older orcad dies uncleanly (out of memory, SIGKILL, power loss) and leaves
orcad.lockbehind. After a reboot, an unrelated long-running process gets the same PID. When Orca is updated:orcad_instance_lock_held, naming that unrelated process as "Another orcad".orcad.lockby hand.unverifiableinstead ofexitedfor the same instance.Before #28125, the mismatch let the new orcad take the lock.
After:
Proof by owner. A process's uid is the user account it runs as. orcad never changes its uid, so on that "unproven" path a PID now owned by a different uid than the lock's identity can't be the lock's holder. That uid is read from
/proc/<pid>. Root and the kernel's overflow uid don't count, because the kernel can show a real holder as either of those. When the proof holds, the verdict becomesdiffers:exited.Managed stop takes the identity from the lock only while that lock still names the instance.
A useful error. When the verdict stays unproven and the record has no boot id,
orcad_instance_lock_held(same code) now says:/proc/<pid>/comm);orcad.lockpath to delete once the user is sure orcad isn't running.Records written since #28125 carry kernel start ticks and a boot id. They never reach this path, so nothing changes for them. macOS and Windows are unaffected: they return before the new check.
Why
The regression comes from #28125. It was right to stop trusting Linux wall-clock start times, because they're derived from
/proc/statbtime, which drifts. But for records written before it, nothing could prove a mismatch anymore.Alternatives I rejected:
acquiredAt(or its recorded start time) with the current boot time. The kernel recomputes btime from the current clock. On VMs and WSL2 it moves forward, which is the drift fix(orcad): identify instances by kernel start ticks, not drifting wall-clock start time #28125 measured: 47 s in 10 minutes. A lock taken shortly after boot would then look "older than this boot", and a live orcad would lose its lock or be reported as exited. That's the exact false exit fix(orcad): identify instances by kernel start ticks, not drifting wall-clock start time #28125 fixed.The uid check is narrower: a root-owned or same-user process that reuses the PID still needs the manual delete. But it never gives a false
differs, and for the rest the error now tells the user exactly what to do.Linked Issue
None. Regression from #28125, found in post-merge review.
Visual Proof
N/A: this is lock and process-identity logic on the execution host, with no UI change.
Testing
orcad-process-start-time.test.tschecks the verdict for a Linux wall-clock mismatch on a record without ticks:differs;unproven;/proc, the owner uid and command-name readers are checked against this process.orcad-instance-lock.test.ts: the old test "keeps an older Linux record whose wall-clock start time disagrees" now runs on every OS and states its intent: drift alone proves nothing, so the lock stays held. It covers:orcad-managed-stop-identity.test.ts: for an older lock, another uid givesexitedwith a receipt, and root or the same uid givesunverifiable. A lock that no longer names the instance gives no owner proof (unverifiable).Ran
pnpm tc, the orcad lock/stop/start-time suites,desktop-profile-instance-lock.test.ts, oxlint, andcheck:code-quality:changed, all on macOS. The real/proctests run on Linux CI.An adversarial review agent found no blocking issue. I applied its findings: the overflow uid, the error wording, and the extra tests.
I manually tested these changes locally
Automated tests added/updated, or explained why not below
AI Disclosure
Review
Agent skill upstream boundary
Notes
/proc/<pid>/commis restricted to printable characters before it reaches the message.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)