Skip to content

feat(server): list a user's schedules in one request (GET /me/cron-jobs) - #1

Closed
L42y wants to merge 1 commit into
mainfrom
feat/me-cron-jobs
Closed

feat(server): list a user's schedules in one request (GET /me/cron-jobs)#1
L42y wants to merge 1 commit into
mainfrom
feat/me-cron-jobs

Conversation

@L42y

@L42y L42y commented Sep 3, 2026

Copy link
Copy Markdown
Owner

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-jobs answers "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 — requireCronJobAccess gates on ownerMemberId — 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 to status = 'active', matching the other /me/* cross-org listings (/me/clients, /me/managed-agents).

The existing idx_cron_jobs_owner_created index covers the members join; ordering is next_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.ts covers:

  • returns the caller's jobs across multiple chats, and not another user's;
  • ordering by next run, with a paused job last;
  • 401 without a signed-in user.

Verified: tsc --noEmit on packages/server passes, 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 / createTestAgent patterns and should run in CI; if it fails there, the failure is mine to fix.

🤖 Generated with Claude Code

`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>
@L42y

L42y commented Sep 3, 2026

Copy link
Copy Markdown
Owner Author

Retargeted to upstream: first-tree-ai#2384. This one was opened against the fork by mistake.

@L42y L42y closed this Sep 3, 2026
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