fix(issue): clearLock leaves dead workers row at status='active' (crash-recovery.js:168)#6201
Conversation
…sh-recovery.js:168)
📝 WalkthroughWalkthroughThis PR adds a new database helper function ChangesStale Worker PID-Based Cleanup
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint skipped: no ESLint configuration detected in root package.json. To enable, add 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. Comment |
🔴 PR Risk Report — CRITICAL
Affected Systems
File Breakdown
|
There was a problem hiding this comment.
Actionable comments posted: 3
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/resources/extensions/gsd/crash-recovery.ts (1)
226-226:⚠️ Potential issue | 🔴 Critical | ⚡ Quick winRead legacy lock metadata before deleting the file.
Line 226 deletes the legacy lock first, then Line 238 reads it. That makes
lock?.pidunreachable, somarkWorkerStoppingByPidnever runs.💡 Proposed fix
export function clearLock(basePath: string): void { - clearLegacyLockFile(basePath); + const legacyLock = readLegacyLock(basePath); + clearLegacyLockFile(basePath); @@ - const lock = readLegacyLock(basePath); - if (lock?.pid) markWorkerStoppingByPid(projectRoot, lock.pid); + if (legacyLock?.pid) markWorkerStoppingByPid(projectRoot, legacyLock.pid);Also applies to: 238-239
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/resources/extensions/gsd/crash-recovery.ts` at line 226, The code deletes the legacy lock file via clearLegacyLockFile(basePath) before reading its metadata, which prevents accessing lock?.pid and stops markWorkerStoppingByPid from running; fix by first reading the legacy lock into a local variable (the code that currently accesses lock?.pid), call markWorkerStoppingByPid(lock.pid) if present, and only then call clearLegacyLockFile(basePath) so the lock metadata is available when markWorkerStoppingByPid is invoked.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/resources/extensions/gsd/db/auto-workers.ts`:
- Around line 173-181: The UPDATE that marks a worker as 'stopping' should also
write the stopped_at timestamp; modify the SQL in
src/resources/extensions/gsd/db/auto-workers.ts so the statement sets stopped_at
= CURRENT_TIMESTAMP (or the DB's equivalent) along with status = 'stopping',
keeping the same WHERE conditions that use :pid and :project_root and the
existing run call that passes pid and projectRootRealpath; ensure the column
name stopped_at is included in the SET clause next to status so downstream
diagnostics/cleanup see the stop time.
In `@src/resources/extensions/gsd/session-lock.ts`:
- Around line 288-290: The cleanup path can incorrectly mark the current process
as stopping because isPidAlive(pid) returns false for pid === process.pid;
update the guards around existingPreflight usage (the checks that call
isPidAlive and then markWorkerStoppingByPid) to explicitly skip cleanup when
existingPreflight.pid === process.pid (or equals process.pid), e.g. add a
condition that verifies existingPreflight.pid !== process.pid before calling
markWorkerStoppingByPid(normalizeRealPath(basePath), existingPreflight.pid);
ensure the same change is applied to the other occurrences of this pattern (the
checks around lines referencing existingPreflight, isPidAlive,
markWorkerStoppingByPid).
In `@src/resources/extensions/gsd/tests/session-lock-regression.test.ts`:
- Line 110: The test uses a non-deterministic "deadPid" value (const deadPid =
99999) which may be a real PID on some systems; replace that literal with a
guaranteed-invalid PID such as Number.MAX_SAFE_INTEGER (or another very large
constant) to ensure deterministically-dead behavior. Update the const deadPid
declaration in the session-lock-regression.test (the const deadPid variable) to
use Number.MAX_SAFE_INTEGER (or a helper like getDeterministicDeadPid() that
returns a very large/invalid PID) so the test cannot accidentally target a live
process.
---
Outside diff comments:
In `@src/resources/extensions/gsd/crash-recovery.ts`:
- Line 226: The code deletes the legacy lock file via
clearLegacyLockFile(basePath) before reading its metadata, which prevents
accessing lock?.pid and stops markWorkerStoppingByPid from running; fix by first
reading the legacy lock into a local variable (the code that currently accesses
lock?.pid), call markWorkerStoppingByPid(lock.pid) if present, and only then
call clearLegacyLockFile(basePath) so the lock metadata is available when
markWorkerStoppingByPid is invoked.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: ed2ef72a-ef5b-41f8-a6ed-be2ab7db5716
📒 Files selected for processing (6)
src/resources/extensions/gsd/auto.tssrc/resources/extensions/gsd/crash-recovery.tssrc/resources/extensions/gsd/db/auto-workers.tssrc/resources/extensions/gsd/session-lock.tssrc/resources/extensions/gsd/tests/auto-workers.test.tssrc/resources/extensions/gsd/tests/session-lock-regression.test.ts
|
🤖 Dispatched Agent prompt (click to expand) |
|
🤖 Dispatched Agent prompt (click to expand) |
Summary
active→stopping) in clear-lock/session-lock/remote-check paths and verified with focused GSD DB/lock tests (22/22 passing).Verification
Related Issue
Repo
gsd-build/gsd-2Branch
issue/5667-clearlock-leaves-dead-workers-row-at-sta-1778906171Summary by CodeRabbit
Release Notes
Bug Fixes
Tests