Skip to content

Scheduler: a backend service for scheduled and on-demand agent runs (ADR-017) - #658

Merged
Deodat-Lawson merged 31 commits into
mainfrom
claude/backend-agentic-workflows-23972d
Nov 29, 2026
Merged

Deodat-Lawson merged 31 commits into
mainfrom
claude/backend-agentic-workflows-23972d

Conversation

@Deodat-Lawson

@Deodat-Lawson Deodat-Lawson commented Nov 29, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • Adds @launchstack/scheduler, the service from the design doc "LaunchStack Scheduler and Job Execution" (ADR-017). A subapp registers a workflow (its model, prompts and skills) and creates jobs on a one-time, interval or cron schedule with a time zone. Each due slot becomes exactly one run. The run reaches Inngest through a dispatch outbox that retries with the same event id. The agent can delegate to child tasks that run in parallel, and the outcome is recorded, including what was missing when a job allows partial results. Missed slots follow the job's policy: run late, catch up once, or skip.
  • Wires it into the app: four new tables in the product migration set (one additive migration), the Inngest function schedulerRun, a scheduler loop in the worker (taking slots and sending runs, with a reconciler on a loop of its own), Prometheus metrics, an operator CLI (apps/web/scripts/scheduler.ts), settings in .env.example and both compose files, and a CI step for the package's integration tests.
  • No subapp uses it yet, as asked. getScheduler() gives subapps the job and run API only, not the admin or executor parts.

Related

  • Design: docs/architecture/ADR-017-scheduler-and-job-execution.md
  • Operating it: docs/runbooks/scheduler.md
  • API and examples: packages/scheduler/README.md

Checklist

  • pnpm check passes (lint + typecheck): 0 lint errors, 26 warnings, none in files this branch touches; typecheck clean. Run at 902d0a2b3, this branch before its rebase onto 587ce7176. CI checks the head.
  • pnpm --filter @launchstack/web test passes: 786 suites pass. The one failure is mindmap-embedding-quality, which calls OpenAI and fails locally with the placeholder key; it is not touched here. Run at 1b52a59fe.
  • Changeset added: @launchstack/scheduler minor, @launchstack/llm patch (the agent model port now passes the caller's abort signal to the request).
  • New env vars documented: SCHEDULER_ENABLED, SCHEDULER_TICK_MS and SCHEDULER_RECONCILE_INTERVAL_MS are in .env.example and apps/worker/src/env.ts. The worker is their only reader; nothing in the web app reads them.
  • UI changes exercised in a browser: no screens change. The only visible text is a new AI-usage category label, "Scheduled jobs" (English and Simplified Chinese), not checked in a browser.
  • Docs updated: package README, ADR-017, a runbook, and the package lists in REPOSITORY.md, CONTRIBUTING.md and packages/README.md.

Testing

At 902d0a2b3 (the same changes before the rebase; the rebase added only main's three commits and re-chained the migration snapshot):

  • Package tests, unit plus real Postgres: 1,425 passed, 8 skipped (the skipped ones are the larger lifecycle-sweep sizes, opt-in through SCHEDULER_SWEEP). Worker: 71 passed.
  • Schema parity: a database built from the committed migrations matches one built from the TypeScript schema.

At 1b52a59fe, two commits earlier:

  • Full lifecycle sweep (SCHEDULER_SWEEP=full): 24,960 sequences that place what a subapp or operator can do (pause, resume, save the schedule or the input, archive, run now, cancel) on every stage of a run, then let five days of passes go by. In every one, no slot had two runs and nothing was left alive: no run, child task or dispatch, and no job without its next slot.
  • End-to-end harness (apps/web/scripts/run-scheduler-e2e.ts: real Postgres, a real Inngest dev server in Docker and the real worker process): 17 of 19 scenarios passed. The two failures were set-up errors in the harness's two newest scenarios (a run time-out below the allowed minimum, and a backdated deadline the reconciler correctly ignored). 902d0a2b3 fixes the harness, and both scenarios pass when run on their own.
  • With a real model (--real-model), the harness passed all 15 scenarios it had on 24 November at 539518fbe. They included the reference workflow: plan, delegate to child agents working in parallel, write the result through the real worker. That run predates the review fixes, and the agent's code has changed since.

At the head (f837884d5), so far: the migration gates CI runs (journal checks, drizzle-kit check, both drift probes, DDL-only), the no-push ban and the schema-boundary check all pass. A full rerun of every gate, the sweep, Node 20 and the end-to-end harness is in progress, and this section will be updated with its results.

Notes for reviewers

  • Where to start: the package README, then ADR-017, then packages/scheduler/src/service.ts, tick.ts, runs.ts, reconcile.ts and executor.ts.
  • The service goes by the database server's clock, not the host's (clock.ts), so a worker host with a wrong clock cannot take a slot early or skip one.
  • A row another session holds never stops the loops. The tick, the dispatcher and the reconciler skip rows they cannot lock (SKIP LOCKED), and any other lock wait in the reconciler is capped at 250 ms. A row held for a minute or more is named in the log and counted in pdr_scheduler_held_rows; the runbook shows how to find the session holding it.
  • The migration only adds tables: apps/web/drizzle/20261129093142_scheduler_job_execution.sql. Its snapshot was regenerated after main's distribution_place_pools migration (Prospects: the free place search fills a pool of every place instead of keeping the first 40 #654); the SQL is byte-identical to before.
  • Known limits, written down in ADR-017's consequences and the package README:
    • SCHEDULER_ENABLED=false stops all three scheduler loops, not only the creation of new runs: nothing is sent, re-sent, expired or timed out while they are off.
    • A deploy stops the step under way. Inngest runs it again, which repeats that phase's model calls; nothing is recorded twice.
    • A job with no creator is checked against nobody's AI allowance, and there is no spend limit per workspace.
    • Saving a different schedule drops a due slot of the old one.
  • Outside the package, the branch touches only wiring: the worker loop, the web app's Inngest function, metrics, CLI, schema and e2e harness, Dockerfiles that copy the new package's manifest, ESLint boundary rules, the usage label, and the packages/llm abort-signal fix.

🤖 Generated with Claude Code


Note

High Risk
Adds durable scheduling, transactional dispatch, and Inngest-orchestrated agent runs touching Postgres, background loops, and model calls; misconfiguration or boundary bypass could affect every workspace's scheduled work.

Overview
Introduces @launchstack/scheduler: subapps register workflows (model, prompts, skills) and create jobs on one-time, interval, or cron schedules. Each due slot becomes one run, queued through a dispatch outbox to Inngest (idempotent event ids), with a run state machine that can delegate parallel child tasks and honor missed-slot policies and partial results.

Worker gains separate tick, drain, and reconcile loops (SCHEDULER_ENABLED, SCHEDULER_TICK_MS, SCHEDULER_RECONCILE_INTERVAL_MS), backlog Prometheus gauges, and readyz scheduler status. Web exposes a narrow getScheduler() API (jobs/runs only), Inngest parent/child functions (scheduler-run, scheduler-child-task), metrics, operator CLI (scripts/scheduler.ts), and enforcement that only allowed modules reach the full runtime.

Adds a Postgres migration (jobs, runs, dispatches, child_tasks), CI integration tests for @launchstack/scheduler, wiring across Dockerfiles/workspace, AI usage feature scheduledJobs, and docs/runbook updates.

Separately, @launchstack/llm now passes the caller's signal through createLangchainAgentPort to in-flight model requests so agent stop aborts retries instead of waiting them out.

Reviewed by Cursor Bugbot for commit f837884. Bugbot is set up for automated code reviews on this repo. Configure here.

Deodat-Lawson and others added 30 commits November 29, 2026 18:18
The service of ADR-017. A subapp registers a workflow (a model, prompts and
skills) and creates jobs on a one-time, interval or cron schedule. The
package turns each due slot into exactly one run, records its dispatch in
the same transaction, and drives the run: claim, plan, child tasks that run
in parallel, finish.

- schedule/: five-field cron in IANA time zones, intervals, and what to do
  with a slot found late. No dependency.
- tick, dispatch, reconcile: the three passes of the worker's loop.
- executor: what the worker does with a run, one replay-safe step at a time.
- workflow, skills, agent: what a subapp registers, and how each phase is
  prompted.
- builtin: scheduler/smoke (no model, for checking a deploy) and
  scheduler/brief (a complete agentic workflow to copy from).

The package is registered in the workspace: lint boundaries (it may import
runtime, store and llm only), the lockfile, the two apps that will import
it, and the Dockerfiles' manifest layers.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
scheduler_jobs (a schedule and what to run), scheduler_runs (one row per
slot, unique on job and scheduled instant), scheduler_child_tasks (what a
run delegated, unique on run and child key) and scheduler_dispatches (the
outbox of runs on their way to Inngest). Additive: nothing existing is
altered.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The worker now finds due jobs every SCHEDULER_TICK_MS, hands their runs to
Inngest, and rescues runs nothing is driving. Two functions execute them:
scheduler-run (claim, plan, one step.invoke per child, finish) and
scheduler-child-task (one child, which records its own outcome).

- getScheduler() is what subapp code imports; workflows are registered in
  apps/web/src/server/scheduler/workflows.ts (none yet).
- Model calls happen inside the workspace's model scope and are counted
  under the workflow's usage feature, or a new one, "Scheduled jobs".
- /readyz reports the loop, /metrics gains pdr_scheduler_*, and
  SCHEDULER_ENABLED=false turns the loop off.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
scripts/scheduler.ts inspects and repairs jobs, runs and dispatches, and has
a smoke command that proves the whole path through a running worker without
a model. Changes need --actor and write an audit line.

scripts/run-scheduler-e2e.ts proves the service through the real parts: a
throwaway database, an Inngest dev server in Docker and the real worker
process. It covers parallel children, a recurring job, two workers, Inngest
stopped and started, partial results, timeouts, a cancel, the worker killed
mid-run, the CLI, and (with --real-model) an agentic run against a real
model.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The package's suite needs a migrated database for its integration tests, so
it runs in the step that already has one.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The scenario created three waves of ten jobs and read how many runs the
second worker's loop had created with `grep -c`, which exits 1 on a count of
zero. When the first worker happened to take every job, the scenario failed
on that exit code, and had not shown any contention anyway.

It now adds waves of twenty jobs, due a random part of a second ahead, until
both workers' loops have created runs (at least three waves, at most
twelve), and checks from the two logs that between them they created
exactly one run per job.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The loop looks for due jobs and for due dispatches on every pass; the ADR
counted only the first.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A one-time job is marked complete by its run's terminal outcome. That update
only matched an active job, so a job paused while its run was under way
stayed paused for good, and resuming it left an active job that could never
fire. It also matched a job that had been given a new instant meanwhile and
closed it before the new slot came round.

The job is now completed when it is disarmed (its slot was taken) and active
or paused, and left alone when it is armed again.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The parent waited for each child for "the child's own limit plus five
seconds", counted from the moment it invoked the child. A child's limit is
counted from when the child starts, and children of one workspace run six at
a time, so a child that started late, behind others, could be given up on
while it was still inside both its own limit and the run's deadline. With
several runs at once, or a plan with more than six tasks, that is the normal
case.

The parent now waits until the run's deadline, which is what the design
says the deadline is: when the parent stops waiting. A child still stops at
its own limit and records that itself, and the parent goes on as soon as the
last child has answered.

The end-to-end harness gains a scenario for it: eight children, six at a
time, each working 6.5 s under a 7 s limit.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…overs the cancellation check

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…here backs off

Review found a one-time job could be left active or paused with no next
slot for ever, by four ordinary routes: a run started by hand for the
job's own instant, a schedule saved away and back, a pause with the same
schedule saved again, and a same-schedule save followed by a cancel before
the next tick. And a full batch of due jobs that could not be processed
made the loop spin.

- The completion rule is now one rule with two halves: the job's slot has
  been taken, and the run in that slot has ended. Whichever happens second
  completes the job: the end of the run (any trigger, the job active or
  paused), or the tick when it finds the slot already holds a finished run.
- finishRun and cancelRun take the job row's lock before the run row's, as
  the tick does, so the two halves can neither deadlock nor miss each other.
- Saving the schedule a job already has changes nothing: not its next slot,
  and not whether a one-time job is armed.
- A job whose tick transaction fails, or whose row is held by something
  else, sits out a wait in that process (5 s doubling to 5 min; a short one
  for a held row) and is left out of the scan meanwhile, so the jobs behind
  it are reached. The tick reports how many jobs it advanced.
- tick() and reconcile() can create without sending ({ drain: false }), for
  a host that sends on a cadence of its own.
- Every slot gets a least grace (minMisfireGraceMs, 15 s; a host sets it
  from its tick interval with minMisfireGraceForTick), so a skip policy
  with a grace shorter than the loop's rhythm no longer skips every slot.
- The job limit counts jobs that can still fire (active or paused), not
  completed and archived ones.
- The clock tool refuses zone abbreviations, as schedules do.
- schedulerClient() is the face a subapp is handed: jobs and runs only.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
… is under way

Three defects of one kind (a job left in a state nothing would ever move
it out of) were each found by a different pair of ordinary operations. This
suite stops picking cases: it places pause, resume, three kinds of schedule
save, an input save, archive, two kinds of run-now and cancel on the five
stages of a run in every way, carries every run to its end, lets five days
of scheduler and reconciler passes go by, and checks what is left against
a short list of rules.

Every test run plays 640 sequences in about twenty seconds.
SCHEDULER_SWEEP=pairs adds every two of all ten operations on a one-time
and an hourly job (3,000 more); SCHEDULER_SWEEP=full adds the same without
passes between stages, the skip policy, and every three of six operations
(about 24,000 more).

Reverting either half of the completion rule makes it fail with the rule
that half upholds.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…ps; subapps get jobs and runs only

- Two loops instead of one. Creating runs (and the reconciler) touches only
  Postgres; sending them waits on Inngest. A slow or unreachable Inngest
  now stalls the sending loop and nothing else, so slots are still taken on
  time. /readyz reports both.
- A pass is followed at once by the next only while it is getting
  somewhere. A full batch it could do nothing with waits out the interval,
  so a fault can no longer become a spin.
- The backlog gauges are refreshed on a timer of their own, on every worker
  whether or not it runs the loops: they have to keep reporting when a loop
  is the thing that stopped.
- The worker tells the scheduler its tick interval, which sets the least
  grace a slot gets.
- getScheduler() hands a subapp jobs and runs. The passes, the executor and
  the operator's reads across workspaces moved to ~/server/scheduler/runtime,
  which only the worker and the scheduler's Inngest functions import; a
  test fails if anything else in the web app does.
- A child step gets two retries, like the parent's: one deploy in the
  middle of a step no longer uses up a child's only retry.
- The publisher's event names and payloads are pinned by a test.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
… through Inngest, and the kill switch

- inngest-hang: with the Inngest server frozen (connections accepted,
  nothing answered) a send hangs for its fifteen seconds while four more
  slots come due and are each taken within a second; every run executes
  once when the server answers again.
- cancel-inngest: a cancel through the service sends scheduler/run.cancelled,
  and Inngest itself lists the parent function as Cancelled. The existing
  cancel scenario (database only) now shows the contrast.
- kill-switch: a worker started with SCHEDULER_ENABLED=false takes no slot
  and sends nothing, still reports the backlog in /metrics, and still
  executes a run handed to Inngest; with the switch back on, what waited
  runs.
- observability checks the sending loop's fields in /readyz.

Inngest is asked about a function by its own run id (the run's claim
token): the dev server's list of runs per event reports a function that is
still waiting as Completed.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…etion rule; pass the reconcile interval through Compose

Corrections from review:

- SCHEDULER_ENABLED=false switches a worker's loops off altogether (no
  slots, no sends, no rescues), not only the creation of runs.
- An idle scheduler makes two queries per interval, not one.
- A retried step repeats its agent phase, model calls included; what is
  never repeated is a record.
- The backlog gauges keep reporting with the loop off or stuck.
- SCHEDULER_RECONCILE_INTERVAL_MS is in .env.example and passed by both
  Compose files, as the runbook already said.
- The runbook lists every end-to-end scenario by the name --only takes, and
  explains an abandoned dispatch.
- The brick adds no dependency to the repository (it uses drizzle-orm and
  zod); it was wrong to say it depends on nothing outside the monorepo.

And the behaviour added with the fixes: the one-time completion rule, the
least grace a slot gets, what saving a schedule does to a due slot, who
may import the whole scheduler, that a job with no creator is checked
against nobody's AI allowance.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…he request

An agent told to stop only stopped once the request in flight had run its
whole course, the transport's retries included: the port took the signal
and did not pass it on.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Time. Every decision about time is made on the database's clock, read now
and then and carried forward on a monotonic timer, so a host whose clock is
wrong can no longer take slots early, skip them or time out runs in flight.

Taking slots. A pass walks the due jobs once, in slot order, from where the
last page ended. Jobs it cannot deal with (failing, backing off, or with a
row something else holds, the workspace's included) no longer keep it from
the jobs behind them. A job's failure count is kept across passes; a fault
of the database as a whole is not counted against a job. A slot that came
due while the loop was already at work is waiting its turn, not missed. A
skipped stretch and the first slot after it are dealt with in one visit, and
a job with further slots due is come back to at once, so a loop slower than
a job's interval no longer falls behind for good.

Reconciling. The pass never waits on a row, a run it cannot end does not
stop the others, and what it did is counted even when something failed. It
closes children that will never report.

Runs. Cancelling takes no lock on another workspace's rows, stops children
the parent had already stopped waiting for (after the run has ended, too),
and no longer waits on a silent Inngest. A child that never started is
closed when the parent stops waiting; one whose function gave up is recorded
failed. Run-now works for a completed one-time job and checks its input and
its instant. A run past its expiry is not sent.

Phases. A first phase that is code no longer lets a run start for a person
at their AI allowance. Output Postgres cannot store is cleaned instead of
failing the write three times; a null result is a result; a phase that ends
on a ceiling records what it spent; a phase is capped under Inngest's limit
for one step; a child agent is shown only its own task, and what children
hand in cannot leave its block in the last phase's prompt. An unclassified
fault is logged under the run's trace id.

Jobs. Saving an interval job with the start it already has changes nothing;
ensure returns an existing job at the job limit; the limit holds under
concurrent creates; a job whose schedule cannot be read can still be listed,
paused, archived and given a new schedule.

The migration is regenerated: the due-jobs index gains the id, the
per-workspace run index is on the id the listing orders by, and children
that have not reported get a partial index.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
… claim where the work starts

The worker runs three loops. A reconciler pass that hangs or fails holds up
neither slot-taking nor sending, and /readyz reports its age and what it
could not do. Ages are measured on a monotonic timer. The kill switch
refuses a value that is neither a yes nor a no, the tick interval may not
exceed the shortest interval a job may have, and the root .env is read
before the worker's own settings.

The Inngest functions claim a run, and a child, in the step that does the
work: a time limit counts from the claim, and must not run down while the
work waits for an execution slot. Steps are told when they are on their
last attempt, the last step is told which children handed nothing back, and
a failure handler that cannot record the failure lets Inngest run it again.

The operator's smoke check uses the scheduler's clock and archives its job.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…es, re-running a one-time job

README, ADR-017, the runbook and .env.example brought in line with the
service as it now is: whose clock decides, how a pass walks the due jobs and
what it does with ones it cannot take, the reconciler's own loop and its
health fields, the child states, run-now for a completed one-time job, what
a long stop loses, where a failed phase is logged, what a child agent is
shown, the kill switch's values and the tick's bounds. The README's three
steps compile as written.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…fter its run ended, and a held row

The harness takes its instants from the scheduler's clock, checks the
reconciler's fields in /readyz, and gains three scenarios: a one-time job
whose run failed and is run again by hand; a child still working after its
run ended, stopped by cancelling that run; and a job row held by another
session while the reconciler has to end one of its runs, with slots still
taken on time. Unit tests for judging lateness from when the loop began
working.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Six agents re-ran every finding of the review against the fixes and wrote
permanent tests for them. They confirmed the fixes and found what those had
left or broken. This closes it; their tests are added here, and the fifteen
they had to mark as expected failures now pass as ordinary tests.

The tick
- A round takes one slot from each job. A job several slots behind was met
  again in the same walk, so a page-full of such jobs had their whole
  backlog taken in front of another workspace's slot that had only just
  come due, and past five minutes of that the slot was skipped as missed.
- A pass stops after three jobs in a row fail for a reason of the
  database's, instead of failing and logging every due job on every pass.
- More faults are known to be the database's and not a job's: a schema
  that is not the one the code expects (a deploy in progress), a missing
  grant, a pooler that lost a prepared statement. A code on the outer
  error that means nothing here no longer hides the database's underneath.
- The same due slot found held by another session for a minute is logged
  and counted. It used to leave no trace at all.

The clock
- A reading is pinned to the moment its answer arrived, not the middle of
  the round trip, so the service's clock is never ahead of the database's
  (it was, by half the time a reading queued for a connection).
- When the host's clock and the timer disagree about how long ago the last
  reading was (the host was suspended), the next entry reads again.

The reconciler
- It no longer waits for a child row or an unsent dispatch row another
  session holds while it has the run's row and the job's: those are taken
  at once or the run is left, and anything else waits a quarter second.
- Each walk over runs carries on from where the last pass ran out of its
  budget, so a thousand runs it cannot end no longer hide those behind.
- A run past its expiry gets no more dispatches even when the pass could
  not end it yet. Re-dispatch is one short transaction per run, taking the
  workspace's row first, so one run costs no other its turn.
- A run found held pass after pass is named.

Runs and jobs
- A child recorded as given up that is still working stops: a phase stops
  once its row no longer owes an outcome. "Gave up" is believed only more
  than five seconds before the run's deadline, since which side of the
  deadline the parent woke on is read off a clock.
- An input has to be an object as JSON: a Date or a URL was stored as a
  string. A key named __proto__ is kept (it was silently dropped), and a
  value nested thousands deep is cleaned without running out of stack.
- Ids that are not whole numbers, a workspace that is not a positive
  bigint and a reason that is not text are refused by name instead of
  reaching the database. A null reason is no reason again.
- Two overlapping ensure calls with one place left: the second is handed
  the job the first created instead of the limit error.
- createdBy is cleaned like every other stored text.

Phases
- Whatever a step throws is logged once under the run's id and thrown on
  in words: also a database that is away at the step's first read, and a
  write that fails while recording how a phase ended. The logged stack no
  longer carries the failed statement's parameters.
- A run names the model its own phases called when the first phase ends on
  a ceiling, and when its only agent phase is the last.
- A first phase stopped at the longest one step may work is recorded as
  phase_time_limit, not deadline_exceeded.
- A child agent is told to work from its task, not from the job input it
  is no longer shown.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…orker takes every log level

- /readyz gains heldJobs and heldRuns, and lastError says when a pass
  stopped because the database was refusing every job. A new gauge,
  pdr_scheduler_held_rows{kind}, carries the same.
- A worker started from a checkout refused to start when the shared .env
  set LOG_LEVEL to trace or fatal, two of the six values .env.example
  lists: the .env is read before the worker's settings since the last
  round. The worker now takes all six and maps the two its logger lacks.
- The test that keeps feature code away from the whole scheduler catches
  every spelling of the module's path, a scheduler built on the spot, and
  the runtime taken from its slot (81 new cases).
- The scheduler's metrics have a test of their own.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
… documents had wrong

Twenty-eight sentences the verification found false or inexact, corrected,
and what this round changed: the runbook's new section "A row is held",
the phase_time_limit error, when a silent child is closed, what counts as
a missed slot, what the clock guarantees, and what a step logs.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…unts properly

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Seven agents tested and reviewed the second round before a usage limit
stopped them; their probes and the tests they left (nine expected to fail)
showed what it had got wrong. Their tests are kept, and pass.

The tick
- A round that ends having taken a slot from jobs that are due again asks
  to be followed at once. It used to report nothing more to do when its
  last pass met only jobs it had already taken from: with the loop looking
  once a minute, a backlog of every-minute jobs never caught up.
- A pass no longer stops when jobs fail for a reason of the database's.
  One workspace's jobs refused by a row-level policy (42501) stopped every
  pass before another workspace's job could be reached, for as long as it
  lasted. Instead a job the database refused waits the shortest back-off
  (5 s, never longer, nothing counted), so a pass that comes straight back
  does not retry it, and a pass logs three failures and one line for the
  rest. databaseFault replaces gaveUpOnDatabase: set when every job a pass
  tried was refused by the database.
- A held job stays reported through the passes of a round that does not
  reach it; it used to flicker between 0 and 1 on /readyz.

The reconciler
- A run whose last phase began after its deadline (its step waited its
  turn) gets its finish allowance from that start: the start of the last
  phase touches the run, and the time-out needs both the deadline and the
  last write to be past the allowance. It used to time out a run under a
  last phase at work.
- A run to re-send whose own row is held is counted and named, like one
  whose workspace's row is held.
- Held runs are remembered until their walk has gone all the way round
  without meeting them, so more than a thousand held are still named; a
  sighting from before the clock was put back counts afresh.
- Two workers ending runs of one job at the same moment no longer report
  each other: a run found behind its job's row is only counted when no run
  of that job was ended in the same pass.

Errors and values
- describeError gives the database's reason for a failed statement that is
  the cause of a workflow's own error, names a connection refused on every
  address (AggregateError with no message), keeps the message of a plain
  object thrown, and never throws itself.
- The cause handed to Inngest with a step's error no longer carries a failed
  statement (Inngest keeps it and its logger prints it): it is the reason in
  words with the database's code.
- A child's failure recorded by the parent is put into words like the
  child's own: no statement or parameters on its row, in missing, or in the
  last phase's prompt.
- A stored value may be nested 4,000 levels deep; deeper is refused by name.
  Between about 6,580 and 6,590 levels the driver used to run out of stack.
- A workspace id past the largest bigint is refused by name; the calls that
  change a job check its id before opening a transaction.

The clock
- A reading the host's clock says cannot be carried forward (the host was
  suspended, or its clock set) is not used when a new one fails: ready()
  fails and says why. A reading that gets no answer is waited for 5 s at
  most. "Carrying on from its last reading" is logged once per half minute.
- A worker that cannot read the clock before a step logs it under the run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…he end-to-end held-row scenario checks what the worker reports

- /readyz lastError now says "the database refused every job this pass
  tried", from the tick's new databaseFault.
- The held-row scenario holds a due job's row and an overdue run's for over
  a minute and checks that /readyz (heldJobs, heldRuns), the held-rows
  metric and the log name both, that nothing is reported as failed, and that
  both are dealt with and the reports clear once the rows are let go. The
  cancel scenarios look for the reworded "stopped a child" log line.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ows found

- A job the database refused waits 5 s, never longer; a pass never stops
  for what jobs fail with, and logs three failures and one line for the rest.
- A run whose last phase began late gets its allowance from that start.
- "A row is held" finds any transaction open for over a minute, busy or
  idle; two workers meeting on one job's rows are not counted; a table a
  migration has locked whole is waited for.
- Stored keys keep their names but not always their order (jsonb); a value
  may be nested 4,000 levels deep; an archived job gives up its key.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… service allows and set up what they mean

- cancel-after-end asked for an 8-second run timeout, under the 10-second
  least a run may have, and stopped at the job's creation.
- held-row made a run look overdue by moving its deadline back only. Since a
  run's finish allowance counts from its last write when that is later, the
  reconciler rightly left it alone, and the scenario waited for a report that
  could not come. It now backdates the last write too, as for a worker that
  died at the deadline.
- The tick's header said a job the database refused is tried on the pass but
  one; it is tried after the shortest wait. The runbook gives the measured
  length of the full end-to-end run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Main gained 20261124154747_distribution_place_pools (#654) after this
branch's last rebase. The scheduler's journal entry is now idx 59, and its
snapshot was regenerated with drizzle-kit rather than hand-patched: prevId
is main's latest snapshot and the body now includes the place-pools table.
The SQL is unchanged (the regenerated file was byte-identical), so its
checksum and name stay as they were.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
packages/llm is publishable and the branch changes it (b4b214f), so it
gets a patch changeset of its own beside the scheduler's.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Nov 29, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
pdr-ai-v2 Ignored Ignored Nov 29, 2026 11:25pm UTC

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-29T23:27:25.302941Z f837884 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f837884d57

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

title: title.slice(0, 300),
instructions: instructions.slice(0, 20_000),
input,
skills: task.skills && task.skills.length > 0 ? task.skills : null,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve an explicitly empty child skill selection

When a planner returns skills: [] for a child, this normalization changes it to null. In agent.ts, both toolsForSkills and composeSystemPrompt interpret null as allowing every workflow skill, whereas an empty array selects none. Consequently, a child explicitly assigned no skills receives all their instructions and tools instead. Preserve the empty array and use null only when the selection was omitted.

Useful? React with 👍 / 👎.

Comment on lines +1130 to +1132
if (args.onlyIfStatus && !args.onlyIfStatus.includes(run.status)) {
return { finished: false, reason: "state_changed", run } as const;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Recheck timeout eligibility after locking the run

If a delayed finish step starts after timeOutOverdueRuns selects an overdue run but before finishRun locks it, settleChildren refreshes updatedAt to grant synthesis its finish allowance. This guard checks only status, which remains waiting_for_children, so the reconciler still marks the run timed out and the synthesis result cannot be recorded. Revalidate the deadline and updatedAt cutoff under the run lock before committing the timeout, so a finish phase that has just started receives its intended allowance.

Useful? React with 👍 / 👎.

@Deodat-Lawson
Deodat-Lawson merged commit 48a00a6 into main Nov 29, 2026
20 checks passed

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit f837884. Configure here.

late: false,
});
}
return { settled: true, run: outcome.run, children: outcome.children };

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Late children counted finished twice

Low Severity

settleChildren emits child.finished for children still at work after the parent stops waiting, then recordChildOutcome emits child.finished again when that child actually completes as late. pdr_scheduler_child_tasks_finished_total therefore counts those children twice, once as timed_out and once as their real status.

Additional Locations (2)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit f837884. Configure here.

Deodat-Lawson added a commit that referenced this pull request Nov 29, 2026
The scheduler (#658) merged with its migration at journal slot 59, where
this branch's migration had just been placed. This time the migration
keeps its name: 20261129231658_distribution_fit_verdicts is later than
the scheduler's 20261129093142, so it moves to slot 60.

drizzle-kit regenerated it on main's journal and the SQL came out
byte-identical. The result was put back under the existing file name,
snapshot id and journal time, as the recipe for a second merge does; the
snapshot's contents and its link to the scheduler's snapshot are
drizzle-kit's own.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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