Skip to content

perf(server): scope refreshIdeas status queries - #109

Merged
jerelvelarde merged 7 commits into
CopilotKit:mainfrom
kvnloo:perf/refresh-ideas-scoped-status
Oct 6, 2026
Merged

jerelvelarde merged 7 commits into
CopilotKit:mainfrom
kvnloo:perf/refresh-ideas-scoped-status

Conversation

@kvnloo

@kvnloo kvnloo commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Problem

refreshIdeas() performs three full-table reads and then filters by status in JavaScript:

  • all tasks → status === "succeeded"
  • all ideas → status === "new"
  • all goals → status === "active"

Terminal task history is retained, so the task scan grows without bound and runs on both maintenance refreshes and on-demand idea refreshes.

A downstream PGlite benchmark measured the largest hotspot (2,000 ~2KB tasks) at roughly:

  • full task list + filter: ~423.6ms / ~3.0MB
  • status-scoped query: ~17.7ms

Change

Add Store.listByStatus() with the same updated_at DESC,id ordering as list(), then use it for those three status predicates only.

All remaining filters and side effects stay unchanged:

  • messageId checks;
  • obsolete idea CAS;
  • empty-milestone goal check;
  • mail/sent dedupe;
  • final full ideas return.

Regression

Persistence coverage compares the scoped query directly with the previous list().filter(item.status === value) semantics and verifies owner/kind isolation.

No idea ranking, task lifecycle, or goal behavior changes.

Verification

Reconciled against current main while retaining the existing section-snapshot persistence regression and this PR's status-query regression, as requested by @jerelvelarde.

Fresh CI: all seven jobs passed.

Integration limits

Only the three existing status predicates are pushed into SQL. Idea ranking, dedupe, CAS side effects, goal behavior, and the final ideas response are unchanged.

@jerelvelarde jerelvelarde left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The three status-scoped reads preserve existing filters and side effects while avoiding unrelated rows; all three persistence tests pass. No new security blocker found. Please resolve tests/persistence.test.ts against current main, keeping this status/isolation regression and the section-snapshot regression, then rerun CI, including the currently failing browser-container check. Production patches merge cleanly. Add actual verification results and integration limits to the description.

kvnloo commented Oct 6, 2026

Copy link
Copy Markdown
Contributor Author

@jerelvelarde thanks — reconciled this onto current main without dropping the existing persistence coverage, and kept the status-scoped regression. Fresh CI is 7/7 green; the description now records verification and integration limits. Ready for re-review when convenient.

kvnloo commented Oct 6, 2026

Copy link
Copy Markdown
Contributor Author

Thanks — reconciled against current main while retaining the status-query regression and existing persistence coverage. Fresh CI on 9025d0f is green across all seven jobs; verification and integration limits are now in the description.

@jerelvelarde jerelvelarde left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Value: scopes refreshIdeas database reads to the statuses actually consumed, avoiding unnecessary application-side scans. Template fit: preserves final ideas results, task filtering, active-goal behavior, deduplication, and compare-and-swap acceptance protection. Integrated current main by retaining both independent Store methods and persistence test additions from #108; no behavior rewrite. Security: owner/kind/status remain parameterized and isolated; no introduced security blocker found. Verification on this integrated head: 37 persistence/workflow/agent API tests, changed-file Biome, and diff checks pass. Merge remains gated on fresh required CI for this head and combined verification.

@jerelvelarde jerelvelarde left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Combined verification on the exact integrated tree passes: 483 tests (zero failures/skips), two real Chromium tests, root/mobile/worker typechecks, server build, and full Biome. Fresh CI passed six jobs; browser-container failed on the initial PDF download listing with WORKER_FAILURE. Independently reproduced a pre-existing race in unchanged worker code: readDownloadFailures enumerates a pending journal which successful capture deletes before readFile, producing ENOENT and the same HTTP 500 mapping. The precise CI cause remains an inference because the worker masks that exception. One bounded failed-job retry is justified by this reproduction; merge remains held until required checks pass. A durable worker follow-up would tolerate only ENOENT for an enumerated journal that disappears, while preserving other errors.

@jerelvelarde
jerelvelarde merged commit 1ac68f3 into CopilotKit:main Oct 6, 2026
13 of 14 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