You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
refactor(task): reconcile dead-worker state via State method and shared lock helper - #1576
Collapse the duplicated dead-worker reconciliation logic in pkg/task/store.go into one State method and one lock helper. Behaviour is unchanged.
Why
needsReconciliation and needsStateReconciliation were identical free functions with the same predicate. Replaced with (*State).NeedsReconciliation() in task.go, nil-safe like its siblings.
ReconcileState had nested branches for the cancel/abandon paths. Flattened to early returns; the re-Get under the dead-worker lock is kept, and the same results are returned on every path.
tryWorkerLock and tryLauncherLock differed only in the lock path function. Both now delegate to a shared tryLock(id, lockPath).
Skipped, with reason: a helper for claim-plus-deferred-unlock (ReconcileTask, ReconcileState, CleanupExitedWorkerTree, Abandoned) would need closure-captured results and differing fallbacks, adding complexity without real savings. CleanupExitedWorkerTree vs CleanupCanceledWorkerTree error messages differ, so they were left alone.
The change is small by design.
Validation
mise run cli:format, mise run cli:lint:ci: 0 issues.
golangci-lint run --new-from-rev=origin/main ./pkg/...: 0 issues.
GOOS=windows go vet ./pkg/task/...: clean.
go test -race ./pkg/task/... -count=1: passed twice.
coderabbit review --agent --committed --base-commit <merge-base> --fresh: first two attempts failed with Connection failed: WebSocket closed; third attempt completed with 0 findings across pkg/task/store.go, pkg/task/store_test.go, pkg/task/task.go.
Auto-merge
Eligible by size: 59 changed non-test lines (store.go 53, task.go 6), 2 non-test files, behaviour-preserving, no tests removed or weakened, no //nolint, no go.mod or lint config changes. Draft, not merged.
Next
Maintainer review.
Summary by CodeRabbit
New Features
Task states now provide a check for whether reconciliation is needed. The check accounts for whether a task has a state, whether its status is terminal, and whether launch is still pending. This makes it easier for callers to distinguish tasks that need reconciliation from those that do not.
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Advanced
Run ID: 5e957687-22f5-495c-ae27-3b90661f1c5d
📥 Commits
Reviewing files that changed from the base of the PR and between 2b30bfa and e62ffab.
📒 Files selected for processing: 3
pkg/task/store.go
pkg/task/store_test.go
pkg/task/task.go
Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.
📝 Walkthrough
The change adds State.NeedsReconciliation and uses it in task reconciliation. ReconcileState handles reread failures, completed reconciliation, and cancellation failures in separate branches. Worker and launcher lock acquisition now use a shared helper.
Changes: State reconciliation
Layer / File(s)
Summary
State check and reconciliation flow pkg/task/task.go, pkg/task/store.go, pkg/task/store_test.go
State.NeedsReconciliation returns true for non-nil, non-terminal states that are not mid-launch. Reconciliation callers use this method. ReconcileState separates reread errors, states that need no reconciliation, and cancellation errors. Tests cover the state cases.
Lock acquisition
Layer / File(s)
Summary
Shared lock acquisition pkg/task/store.go
tryWorkerLock and tryLauncherLock delegate to tryLock, which accepts a lock-path function and retains the existing acquisition and error results.
The reconciliation and lock-helper refactor has no identified issue blocking merge after normal checks.
Security architecture risk:⚪ Minimal · up to e62ff
The compared changes preserve reconciliation eligibility, lock separation, and cancellation recovery behavior. No material security risk was introduced or worsened.
Retained concerns
No architecture-level concerns identified.
Security review details
Security Blast Radius
inferred — The changed public method does not expand mutation authority: it exposes an existing eligibility calculation while the mutating reconciliation entrypoints retain their lock and fresh-state checks. The compared changes show no new attacker-controlled input or broader lock scope.
Pre-merge checks: 3 · 2
Failed checks: 2 warnings
Check name
Status
Explanation
Resolution
Description check
The description explains the motivation, implementation scope, behavior-preserving intent, and validation results. However, it omits several required template sections and information, including the i…
Update the description to include the required template sections, or explicitly remove sections that do not apply. State the issue reference or write "none", select "Refactor (no behavior change)", document AI assistance, record applicable …
Docstring Coverage
Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 3 files.
Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed checks: 3 passed
Check name
Status
Explanation
Title check
The title clearly and concisely describes the main refactor: consolidating dead-worker reconciliation through a State method and shared lock helper.
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Full details: Description check
Explanation
The description explains the motivation, implementation scope, behavior-preserving intent, and validation results. However, it omits several required template sections and information, including the issue reference, change-type selection, AI assistance declaration, required testing checklist details, manual verification section, repository checklist, and reviewer notes.
Resolution
Update the description to include the required template sections, or explicitly remove sections that do not apply. State the issue reference or write "none", select "Refactor (no behavior change)", document AI assistance, record applicable unit or integration testing details, list manual verification commands and results, complete the checklist, and add any relevant reviewer notes.
Fix all pre-merge checks with AI
✨ Finishing Touches
✨ Simplify code
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Collapse the duplicated dead-worker reconciliation logic in
pkg/task/store.gointo oneStatemethod and one lock helper. Behaviour is unchanged.Why
needsReconciliationandneedsStateReconciliationwere identical free functions with the same predicate. Replaced with(*State).NeedsReconciliation()intask.go, nil-safe like its siblings.ReconcileStatehad nested branches for the cancel/abandon paths. Flattened to early returns; the re-Getunder the dead-worker lock is kept, and the same results are returned on every path.tryWorkerLockandtryLauncherLockdiffered only in the lock path function. Both now delegate to a sharedtryLock(id, lockPath).ReconcileTask,ReconcileState,CleanupExitedWorkerTree,Abandoned) would need closure-captured results and differing fallbacks, adding complexity without real savings.CleanupExitedWorkerTreevsCleanupCanceledWorkerTreeerror messages differ, so they were left alone.Validation
mise run cli:format,mise run cli:lint:ci: 0 issues.golangci-lint run --new-from-rev=origin/main ./pkg/...: 0 issues.GOOS=windows go vet ./pkg/task/...: clean.go test -race ./pkg/task/... -count=1: passed twice.TestStateNeedsReconciliation(nil, pending, running, launch pending, succeeded, failed).CodeRabbit CLI
coderabbit review --agent --committed --base-commit <merge-base> --fresh: first two attempts failed withConnection failed: WebSocket closed; third attempt completed with 0 findings acrosspkg/task/store.go,pkg/task/store_test.go,pkg/task/task.go.Auto-merge
Eligible by size: 59 changed non-test lines (store.go 53, task.go 6), 2 non-test files, behaviour-preserving, no tests removed or weakened, no
//nolint, no go.mod or lint config changes. Draft, not merged.Next
Summary by CodeRabbit