Skip to content

fix(cloudstore): invalidate dashboard cache after every InsertMutationBatch commit#354

Open
danielgap wants to merge 2 commits into
Gentleman-Programming:mainfrom
danielgap:fix/251-dashboard-cache-insert-mutation-batch
Open

fix(cloudstore): invalidate dashboard cache after every InsertMutationBatch commit#354
danielgap wants to merge 2 commits into
Gentleman-Programming:mainfrom
danielgap:fix/251-dashboard-cache-insert-mutation-batch

Conversation

@danielgap
Copy link
Copy Markdown

🔗 Linked Issue

Closes #251


🏷️ PR Type

  • type:bug — Bug fix

📝 Summary

  • InsertMutationBatch now unconditionally invalidates the dashboard read model cache after every successful commit, aligning its behavior with WriteChunk.
  • Before this fix, only batches that produced materialized chunks (session/observation/prompt entities) triggered cache invalidation. Batches containing only non-materializable entities (e.g. relation) left the cache stale, causing 404s on the dashboard until a manual restart.

📂 Changes

File Change
internal/cloud/cloudstore/cloudstore.go Moved invalidateDashboardReadModel() outside the if len(chunks) > 0 conditional so it always runs after commit
internal/cloud/cloudstore/cloudstore_test.go Added TestInsertMutationBatchInvalidatesDashboardReadModel regression test using a relation-only batch (zero chunks)

🧪 Test Plan

  • Unit tests pass locally: go test ./internal/cloud/cloudstore/ — all pass (47 tests, 0 failures)
  • E2E tests pass locally: go test -tags e2e ./internal/server/... — skipped (no local Postgres)
  • Manually verified that InsertMutationBatch with a relation-only batch triggers cache invalidation

🤖 Automated Checks

These run automatically and all must pass before merge:

Check What it verifies Status
Check Issue Reference PR body contains Closes #N / Fixes #N / Resolves #N
Check Issue Has status:approved Linked issue has status:approved label
Check PR Has type:* Label PR has exactly one type:* label
Unit Tests go test ./... passes
E2E Tests go test -tags e2e ./internal/server/... passes

✅ Contributor Checklist

  • I linked an approved issue above (Closes #251)
  • I added exactly one type:* label to this PR (type:bug)
  • I ran unit tests locally: go test ./internal/cloud/cloudstore/
  • I ran e2e tests locally: no local Postgres available
  • Docs updated (if behavior changed) — no docs change needed, internal cache behavior
  • Commits follow conventional commits format
  • No Co-Authored-By trailers in commits

💬 Notes for Reviewers

The root cause is that InsertMutationBatch guarded the cache invalidation behind if len(chunks) > 0, but WriteChunk (the other write path) invalidates unconditionally. This meant that mutations arriving via autosync that contained only non-materializable entities (like relation) never invalidated the cache, making the dashboard stale until a server restart. The fix is a one-line change that matches the proven pattern from WriteChunk.

Copilot AI review requested due to automatic review settings May 11, 2026 14:28
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes dashboard staleness in the cloudstore write path by ensuring InsertMutationBatch invalidates the dashboard read-model cache after every successful commit (including batches that produce no materialized chunks, e.g., relation-only batches), and adds a regression test to prevent reintroducing the bug.

Changes:

  • Make InsertMutationBatch always call invalidateDashboardReadModel() after a successful transaction commit.
  • Add a regression test proving cache invalidation happens even when the mutation batch yields zero materialized chunks.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
internal/cloud/cloudstore/cloudstore.go Unconditionally invalidate the dashboard read-model cache after committing InsertMutationBatch.
internal/cloud/cloudstore/cloudstore_test.go Add regression coverage for cache invalidation on a relation-only mutation batch (zero chunks).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

db, err := sql.Open("cloudstore-partial-fail-driver", "dsn")
if err != nil {
t.Fatalf("open: %v", err)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(cloudstore): InsertMutationBatch does not invalidate dashboard read model cache

2 participants