Skip to content

perf(server): count active tasks in SQL before create - #107

Open
kvnloo wants to merge 4 commits into
CopilotKit:mainfrom
kvnloo:perf/create-task-cap-sql-count
Open

kvnloo wants to merge 4 commits into
CopilotKit:mainfrom
kvnloo:perf/create-task-cap-sql-count

Conversation

@kvnloo

@kvnloo kvnloo commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

Problem

Every createTask call currently loads the entire durable task table and filters terminal rows in JavaScript to enforce the 100-active-task cap. Terminal tasks are retained, so this check gets more expensive over the lifetime of a workspace.

A downstream PGlite benchmark with 2,000 ~2KB task rows measured roughly:

  • full list()+filter: ~282.7ms / ~3.0MB transferred
  • SQL count: ~54.3ms / ~50B returned

Change

Add Store.countActiveTasks() and push the terminal-status exclusion into SQL. COALESCE preserves the previous behavior where a status-less task counts as active.

createTask still applies the same >=100 cap and the same terminal set.

Regression

The persistence test compares the SQL result to the previous list()+filter semantics across all task statuses, including a status-less record, and verifies owner/kind isolation.

No cap value, task lifecycle, or API behavior changes.

This branch has not been deployed

No deployments
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.

1 participant