feat(server): list a user's schedules in one request (GET /me/cron-jobs) - #1
Closed
L42y wants to merge 1 commit into
Closed
feat(server): list a user's schedules in one request (GET /me/cron-jobs)#1L42y wants to merge 1 commit into
L42y wants to merge 1 commit into
Conversation
`GET /chats/:chatId/cron-jobs` answers "what runs from this chat". A client asking the other question — "what do I have scheduled" — had no route for it, so it had to ask every chat it knew about and keep the few answers that were not empty. That is one request per chat to find a handful of jobs, and it gets worse as a workspace grows. `GET /me/cron-jobs` answers it directly: every job the caller owns, across the orgs they belong to, ordered by what runs next. Paused jobs carry no next occurrence, so Postgres sorts them after the scheduled ones, which is also how a reader wants them. Scope: ownership is already the mutation boundary for a job (`requireCronJobAccess` gates on `ownerMemberId`), so listing by owner grants no new reach — it returns exactly the jobs the caller can already read and modify one id at a time. The existing `idx_cron_jobs_owner_created` index covers the join. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Owner
Author
|
Retargeted to upstream: first-tree-ai#2384. This one was opened against the fork by mistake. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds
GET /api/v1/me/cron-jobs— every schedule the caller owns, across the orgs they belong to, ordered by what runs next.Why
GET /chats/:chatId/cron-jobsanswers "what runs from this chat". There was no route for the other question — "what do I have scheduled" — so a client wanting that list had to ask every chat it knew about and keep the few answers that weren't empty. That is one request per chat to find a handful of jobs, and it degrades as a workspace grows: the client I hit this with capped its fan-out at 40 chats and still couldn't state a trustworthy count without paying for all 40.Scope and safety
Ownership is already the mutation boundary for a job —
requireCronJobAccessgates onownerMemberId— so listing by owner grants no new reach. The route returns exactly the jobs the caller can already read and modify one id at a time. Membership is filtered tostatus = 'active', matching the other/me/*cross-org listings (/me/clients,/me/managed-agents).The existing
idx_cron_jobs_owner_createdindex covers the members join; ordering isnext_run_at ASC, which puts paused jobs (next_run_at IS NULL) after the scheduled ones — the order a reader wants anyway, since a job with no next occurrence can't be sorted among ones that have one.Tests
packages/server/src/__tests__/me-cron-jobs-list.test.tscovers:Verified:
tsc --noEmitonpackages/serverpasses, Biome clean.Not verified by me: the integration tests need a live Postgres, and this environment has one running but no credentials I can use — so the new test has not been executed locally. It follows the existing
useTestApp/createTestAgentpatterns and should run in CI; if it fails there, the failure is mine to fix.🤖 Generated with Claude Code