Skip to content

refactor(task): reconcile dead-worker state via State method and shared lock helper - #1576

Merged
skevetter merged 1 commit into
mainfrom
refactor/task-store-reconcile-locking
Oct 19, 2026
Merged

skevetter merged 1 commit into
mainfrom
refactor/task-store-reconcile-locking

Conversation

@skevetter

@skevetter skevetter commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary

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.
  • Added TestStateNeedsReconciliation (nil, pending, running, launch pending, succeeded, failed).

CodeRabbit CLI

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.

@skevetter skevetter added the auto-refactor Automated refactor PR label Oct 19, 2026
@netlify

netlify Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for devsydev canceled.

Name Link
🔨 Latest commit e62ffab
🔍 Latest deploy log https://app.netlify.com/projects/devsydev/deploys/6ad5b51b309eb0afc4a40e4e

@coderabbitai

coderabbitai Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

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.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Refactor

Merge Risk: ⚪ Minimal · up to e62ff

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: Passed 3 · Failed 2

Failed Failed checks: 2 warnings

Check name Status Explanation Resolution
Description check Warning 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 Warning 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 Passed checks: 3 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main refactor: consolidating dead-worker reconciliation through a State method and shared lock helper.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed 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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@netlify

netlify Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for images-devsy-sh canceled.

Name Link
🔨 Latest commit e62ffab
🔍 Latest deploy log https://app.netlify.com/projects/images-devsy-sh/deploys/6ad5b51bea8d3283d5d59e9d

@skevetter
skevetter marked this pull request as ready for review October 19, 2026 08:32
@mergify

mergify Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

This pull request does not currently match the merge queue conditions, so it cannot be queued from here. The box comes back if it matches again.

@skevetter
skevetter merged commit 70c4914 into main Oct 19, 2026
111 checks passed
@skevetter
skevetter deleted the refactor/task-store-reconcile-locking branch October 19, 2026 08:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auto-refactor Automated refactor PR size/m

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant