Skip to content

Conversation

@drifter089
Copy link
Owner

@drifter089 drifter089 commented Dec 25, 2025

Summary

Fixes an issue where the "Processing" indicator on dashboard charts would disappear immediately after triggering a hard refetch from the drawer, even though the pipeline was still running.

Problem

When hard refetch was triggered, the onSuccess callback invalidated React Query cache, which then refetched data from Prisma Accelerate's stale cache (where refreshStatus was still null), causing the optimistic processing state to be replaced with stale data.

Changes

  • Added immediate Prisma Accelerate cache invalidation in all 4 pipeline mutations (refresh, regenerate, regenerateIngestionOnly, regenerateChartOnly) after setting the processing status in the database
  • This ensures that when the client refetches after mutation success, it gets fresh data showing the processing status

Summary by CodeRabbit

Release Notes

  • Bug Fixes
    • Pipeline processing status updates now display reliably in real-time after background operations.
    • Enhanced data consistency across pipeline operations (refresh, ingestion, and chart updates).
    • Improved client-side visibility of processing state changes.

✏️ Tip: You can customize this high-level summary in your review settings.

@vercel
Copy link

vercel bot commented Dec 25, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
org-os Ready Ready Preview, Comment Dec 25, 2025 2:02pm

@coderabbitai
Copy link

coderabbitai bot commented Dec 25, 2025

📝 Walkthrough

Walkthrough

Cache invalidation steps are added after background pipeline operations (soft-refresh, hard-refresh, ingestion-only, chart-only triggers) to ensure the Prisma cache refreshes with organization and team-based tags. The cache invalidation logic within runBackgroundTask is refactored with a local helper function for reuse in success and error paths.

Changes

Cohort / File(s) Summary
Pipeline Cache Invalidation
src/server/api/routers/pipeline.ts
Adds invalidateCacheByTags calls after background pipeline triggers (soft-refresh, hard-refresh, ingestion-only, chart-only) using organization ID and optional team ID. Refactors cache invalidation logic inside runBackgroundTask with a local invalidateCache helper for consistency across success/error paths.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰 Cache tags flutter, org and team aligned,
Old states vanish, fresh data redesigned,
Helper functions hop through success and strife,
Prisma's memory refreshed to vibrant life!

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and clearly describes the specific bug being fixed: a dashboard chart processing indicator that disappears too quickly during hard refetch operations. It accurately reflects the main issue addressed in the PR.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch zenith

📜 Recent review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 622a322 and b7217bf.

📒 Files selected for processing (1)
  • src/server/api/routers/pipeline.ts
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.{ts,tsx}: Use the tRPC dual API pattern: for server components, directly call tRPC server API (10x faster); for client components, use React hooks with TanStack Query
Use inline type imports with @trivago/prettier-plugin-sort-imports for consistent import ordering

Use TypeScript 5.9 with strict type checking for all frontend and backend code

Files:

  • src/server/api/routers/pipeline.ts
src/server/api/routers/**/*.ts

📄 CodeRabbit inference engine (CLAUDE.md)

src/server/api/routers/**/*.ts: Always verify resource access using authorization helpers (getMetricAndVerifyAccess, getRoleAndVerifyAccess, getTeamAndVerifyAccess) to ensure resources belong to the user's organization in tRPC procedures
Use protectedProcedure or workspaceProcedure for new tRPC procedures instead of public procedures
Invalidate cache tags after mutations using invalidateCacheByTags(ctx.db, [tagName]) to maintain consistency

src/server/api/routers/**/*.ts: In tRPC procedures, never assume authentication; always use helpers like getTeamAndVerifyAccess to verify access before operations
Be careful when modifying team save logic related to EditSession model, which handles locking for concurrent team editing

Files:

  • src/server/api/routers/pipeline.ts
🧠 Learnings (6)
📓 Common learnings
Learnt from: CR
Repo: drifter089/orgOS PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-20T16:32:46.829Z
Learning: Applies to src/server/api/routers/**/*.ts : Invalidate cache tags after mutations using invalidateCacheByTags(ctx.db, [tagName]) to maintain consistency
📚 Learning: 2025-12-20T16:32:46.829Z
Learnt from: CR
Repo: drifter089/orgOS PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-20T16:32:46.829Z
Learning: Applies to src/server/api/routers/**/*.ts : Invalidate cache tags after mutations using invalidateCacheByTags(ctx.db, [tagName]) to maintain consistency

Applied to files:

  • src/server/api/routers/pipeline.ts
📚 Learning: 2025-12-20T22:12:00.576Z
Learnt from: CR
Repo: drifter089/orgOS PR: 0
File: GEMINI.md:0-0
Timestamp: 2025-12-20T22:12:00.576Z
Learning: Applies to src/server/api/routers/**/*.ts : Be careful when modifying team save logic related to `EditSession` model, which handles locking for concurrent team editing

Applied to files:

  • src/server/api/routers/pipeline.ts
📚 Learning: 2025-12-20T16:32:46.829Z
Learnt from: CR
Repo: drifter089/orgOS PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-20T16:32:46.829Z
Learning: Applies to src/app/dashboard/**/*.{ts,tsx} : Three-stage metrics transformation pipeline: Stage 1 (API → DataPoints via DataIngestionTransformer), Stage 2 (DataPoints → ChartConfig via ChartTransformer), Stage 3 (ChartConfig → UI via DashboardMetricChart with Recharts)

Applied to files:

  • src/server/api/routers/pipeline.ts
📚 Learning: 2025-12-20T22:12:00.576Z
Learnt from: CR
Repo: drifter089/orgOS PR: 0
File: GEMINI.md:0-0
Timestamp: 2025-12-20T22:12:00.576Z
Learning: Applies to prisma/schema.prisma : When modifying the Prisma schema, especially for Metric Transformers, ensure AI-generated code generation and execution logic is updated accordingly

Applied to files:

  • src/server/api/routers/pipeline.ts
📚 Learning: 2025-12-20T22:12:00.576Z
Learnt from: CR
Repo: drifter089/orgOS PR: 0
File: GEMINI.md:0-0
Timestamp: 2025-12-20T22:12:00.576Z
Learning: The Metrics Pipeline processes data through 3 stages: DataIngestionTransformer (Raw API → MetricDataPoint), ChartTransformer (MetricDataPoint → Chart Config), and Visualization (Chart Config → Recharts UI)

Applied to files:

  • src/server/api/routers/pipeline.ts
🧬 Code graph analysis (1)
src/server/api/routers/pipeline.ts (1)
src/server/api/utils/cache-strategy.ts (1)
  • invalidateCacheByTags (167-183)
🔇 Additional comments (3)
src/server/api/routers/pipeline.ts (3)

52-56: Good refactoring to extract cache invalidation logic.

The local helper function consolidates the cache invalidation pattern used across success and error paths in runBackgroundTask, improving maintainability.


69-69: Background task cache invalidation correctly ensures final state visibility.

The cache invalidations in success paths (lines 69, 100, 126) and error path (line 138) complement the immediate invalidations in the mutations. This dual approach ensures:

  1. Processing status is visible immediately after mutation (fixed by this PR)
  2. Completion or error status is visible after the background task finishes (existing behavior)

The error path invalidation (line 138) is particularly important for ensuring the frontend can display error states.

Also applies to: 100-100, 126-126, 138-138


161-164: Cache tags are correctly aligned with dashboard query strategy.

The cache invalidation at lines 161-164 uses the exact same tags (dashboard_org_${organizationId} and conditional dashboard_team_${teamId}) that the dashboard queries depend on, ensuring the client refetch will retrieve fresh data. The pattern is consistently applied across all query and mutation operations throughout the codebase.


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 and usage tips.

@drifter089 drifter089 merged commit de29c48 into main Dec 25, 2025
4 checks passed
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.

2 participants