feat: scheduled actions agent execution#268
Merged
Merged
Conversation
… clarify docstring
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Copilot created this pull request from a session on behalf of
crazygo
May 27, 2026 09:23
View session
Contributor
There was a problem hiding this comment.
Pull request overview
Adds recurring "scheduled actions" that are stored per user, exposed as agent tools, and executed by a Vercel Cron-driven endpoint that runs the local agent loop and writes the results back into chat history.
Changes:
- New
scheduled_actions/scheduled_action_runstables (migrations 021/022) with idempotent claim viaUNIQUE(scheduled_action_id, scheduled_fire_at), plus a full CRUD + cron-helper service. - Seven new internal agent tools (
scheduled_action.{create,list,get,update,pause,resume,delete}) wired intolocalAgentLoopServicewith unit tests. - New
GET /api/cron/scheduled-actionsendpoint guarded byCRON_SECRET(timing-safe compare); registered without JWT middleware and scheduled every minute invercel.json.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| apps/node_backend/src/db/migrations/021_create_scheduled_actions.sql | Creates scheduled_actions table + indices + updated_at trigger. |
| apps/node_backend/src/db/migrations/022_create_scheduled_action_runs.sql | Creates scheduled_action_runs table with idempotency UNIQUE and trigger. |
| apps/node_backend/src/services/scheduledActionService.ts | CRUD + cron helpers (queryDueActions, claimScheduledActionRun, advanceNextRunAt, markRun*). |
| apps/node_backend/src/services/localAgentLoopService.ts | Registers 7 scheduled_action.* internal tools and their agent-facing tool definitions. |
| apps/node_backend/src/services/localAgentLoopService.test.ts | Mocks scheduledActionService and tests the dispatcher branches. |
| apps/node_backend/src/routes/cron.ts | New cron handler: claims a run, advances next_run_at, runs agent loop, writes assistant message, marks run completed/failed. |
| apps/node_backend/src/app.ts | Mounts /api/cron (no JWT middleware). |
| vercel.json | Registers the per-minute Vercel Cron entry. |
| docs/code_maps/{feature_map,logic_map}.yaml | Adds scheduled_actions feature entry and risks/keywords. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+99
to
+101
| // Advance next_run_at immediately so the next cron tick won't re-claim. | ||
| await advanceNextRunAt(action.id, new Date(action.nextRunAt), action.intervalSeconds); | ||
| await markRunStarted(run.id); |
Comment on lines
+262
to
+268
| const result = await pool.query<ScheduledActionRow>( | ||
| `UPDATE scheduled_actions | ||
| SET ${setClauses.join(', ')} | ||
| WHERE user_id = $1 AND id = $2 AND status <> 'deleted' | ||
| RETURNING ${ACTION_SELECT_COLS}`, | ||
| values, | ||
| ); |
Comment on lines
+154
to
+157
| export function clampIntervalSeconds(value: number): number { | ||
| const n = Math.max(MIN_INTERVAL_SECONDS, Math.trunc(value)); | ||
| return Number.isFinite(n) ? n : MIN_INTERVAL_SECONDS; | ||
| } |
Comment on lines
+90
to
+92
| for (const action of dueActions) { | ||
| // Attempt to claim a run for this fire time. | ||
| const run = await claimScheduledActionRun(action, fireTime); |
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.
Adds recurring agent tasks that fire automatically via Vercel Cron. Users create scheduled actions through the agent loop; the cron endpoint picks up due actions, runs the agent loop per action, and writes results into chat history.
DB
scheduled_actions— storesinterval_seconds,next_run_at,status(active/paused/deleted)scheduled_action_runs—UNIQUE(scheduled_action_id, scheduled_fire_at)enables idempotent claiming across concurrent cron invocationsService (
scheduledActionService.ts)Full CRUD + cron helpers:
queryDueActions,claimScheduledActionRun(INSERT … ON CONFLICT DO NOTHING),advanceNextRunAt,markRun{Started,Completed,Failed}Agent tools (
localAgentLoopService.ts)7 new internal tools:
scheduled_action.{create,list,get,update,pause,resume,delete}Cron endpoint (
routes/cron.ts)GET /api/cron/scheduled-actions— processes up to 5 due actions per tick:next_run_atimmediately (prevents re-claim on same tick)Auth:
Authorization: ****** verified withcrypto.timingSafeEqual` (no length pre-check timing leak).Infrastructure
app.ts:/api/cronregistered without JWT middlewarevercel.json:"crons": [{"path": "/api/cron/scheduled-actions", "schedule": "* * * * *"}]Notes
updateScheduledActionpreservesnext_run_atwhen onlyintervalSecondschanges — interval takes effect on the next advance, not immediatelyCRON_SECRETmust be set in Vercel project settings to activate