Skip to content

fix(task-history): route invalidate() and invalidateAll() through withLock#912

Open
morgan-coded wants to merge 1 commit into
Zoo-Code-Org:mainfrom
morgan-coded:task-history-locked-invalidation
Open

fix(task-history): route invalidate() and invalidateAll() through withLock#912
morgan-coded wants to merge 1 commit into
Zoo-Code-Org:mainfrom
morgan-coded:task-history-locked-invalidation

Conversation

@morgan-coded

@morgan-coded morgan-coded commented Jul 17, 2026

Copy link
Copy Markdown

Locks invalidate() and invalidateAll() behind TaskHistoryStore's existing withLock queue so cache invalidation cannot interleave with an in-flight mutation. Each method keeps its existing cache behavior.

Related GitHub Issue

Fixes #698

Description

Per your note, I routed invalidate() rather than removing it: the census found no non-test callers, but TaskHistoryStore is exported from the task-persistence barrel, so deleting its public method could break consumers.

Method Definitions Non-test callers Test references Export surface Decision
invalidate() 1 0 3 call sites Public method on the barrel-exported TaskHistoryStore Route through withLock
invalidateAll() 1 1 6 mock/assertion references Public method on the barrel-exported TaskHistoryStore Route through withLock

Test Procedure

The regression blocks writeTaskFile with a manually controlled promise after the lock is acquired, calls invalidateAll(), then releases the write. It asserts that onWrite sees both cached tasks before the queued invalidation clears the final cache, so no timer or scheduling delay controls the result.

  • pnpm --filter zoo-code exec vitest run core/task-persistence/__tests__/TaskHistoryStore.spec.ts
  • pnpm test
  • pnpm lint
  • pnpm check-types

Pre-Submission Checklist

  • Issue Linked: This PR is linked to an approved GitHub Issue.
  • Scope: The changes are focused on the linked issue.
  • Self-Review: I performed a self-review of the cache and test changes.
  • Testing: A deterministic concurrency regression covers the change.
  • Documentation Impact: No user-facing documentation changes are required.
  • Contribution Guidelines: I read and agree to the Contributor Guidelines.

Additional Notes

Non-goals: no other cache methods, lock implementation, callers, or APIs are changed.

Summary by CodeRabbit

  • Bug Fixes

    • Improved task history cache invalidation to prevent conflicts with ongoing updates.
    • Cache clearing now waits for active writes to finish, ensuring consistent task history data.
  • Tests

    • Added coverage for cache clearing during an in-progress task history update.

Copilot AI review requested due to automatic review settings July 17, 2026 06:33

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 58eaf5ae-1d59-453f-9666-94cddbc3f5bb

📥 Commits

Reviewing files that changed from the base of the PR and between 367013f and dd158bb.

📒 Files selected for processing (2)
  • src/core/task-persistence/TaskHistoryStore.ts
  • src/core/task-persistence/__tests__/TaskHistoryStore.spec.ts

📝 Walkthrough

Walkthrough

Task history invalidation now runs through the write lock. invalidateAll() returns a promise, and a concurrency test verifies it waits for an ongoing upsert before clearing the cache.

Changes

Task history cache consistency

Layer / File(s) Summary
Lock invalidation and validate concurrency
src/core/task-persistence/TaskHistoryStore.ts, src/core/task-persistence/__tests__/TaskHistoryStore.spec.ts
invalidate() and invalidateAll() serialize cache changes with withLock; tests verify invalidateAll() waits for an in-flight write and leaves the cache empty afterward.

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

Possibly related PRs

Suggested labels: awaiting-review

Suggested reviewers: hannesrudolph

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: routing invalidate methods through the existing lock.
Description check ✅ Passed The PR description includes the issue link, implementation details, testing steps, checklist, and extra context; only optional sections are omitted.
Linked Issues check ✅ Passed The changes satisfy #698 by wrapping invalidate() and invalidateAll() in withLock and adding a concurrency regression test.
Out of Scope Changes check ✅ Passed The code changes stay focused on TaskHistoryStore locking and its regression test, with no clear unrelated additions.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@codecov

codecov Bot commented Jul 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@github-actions github-actions Bot added the awaiting-review PR changes are ready and waiting for maintainer re-review label Jul 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting-review PR changes are ready and waiting for maintainer re-review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(task-history): invalidate() and invalidateAll() bypass withLock, corrupting cache under concurrent writes

2 participants