Skip to content

feat(platform): let project agents page the queue and read run state - #3963

Merged
yannickmonney merged 7 commits into
mainfrom
feat/task-read-tools-pagination
Sep 30, 2026
Merged

yannickmonney merged 7 commits into
mainfrom
feat/task-read-tools-pagination

Conversation

@yannickmonney

@yannickmonney yannickmonney commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Why

A recurring fleet manager has to reconcile every task in its project and tell whether a run has actually finished before it resumes routine work. Neither read tool let it:

  • task_find read the first 200 rows of status, rank and stopped. It answered totalFound: 200 with "Showing the first 50 of 200", a capped count presented as a total. A column with more than 200 cards could not be listed, whatever the filter.
  • task_get answered the newest 50 comments with no ids and no way to read older ones, listed subtasks and blockers without ids, and said nothing about the task's runs, a pending review or a question waiting on a person.

This PR extends the two existing read tools and nothing else. It adds no new tool, no question, steer or approval API, and no migration.

What changes

task_find: pages to the end of a queue

  • Keyset pages of at most 50 (default 20; a fraction below one reads one row), answering isDone and, while more follow, a signed continueCursor. The last page has no cursor to pass back.
  • The cursor is bound to its listing: the order, the effective scope (the run's project, its automation's bound set, or the organization) and every filter. A cursor passed with other arguments, from another project's run or another organization, or one that is malformed, cut short or edited answers invalid_args. It is never read as a first page. The page size may change between pages.
  • totalFound appears only when one page holds every matching task, the one case where the count is a total.
  • Two total orders, both ending on the task id, so tasks tied on rank or on their creation millisecond still page exactly once:
    • board (the default, and the old order): (status, rank, id), which groups tasks by status name (alphabetically) and keeps each column's rank order. A task that moves while you page can be skipped or listed twice.
    • created: (created_at, id). A task keeps its place, so a pass lists each task at most once, as it stands when its page is read.
  • Scopes are unchanged: a project-bound run is still fixed to its project, a multi-bound automation run to its bound set, and a member's confined run still reads its project.

task_get: ids, continuation and run state

  • Subtasks and blockers carry their taskId (and number). They are read inside the task's own project only, even for a dependency row put in by hand, and subtasksTruncated / blockedByTruncated say when a list was cut.
  • Each comment carries its commentId (the messageId task_comment answered) and ISO dates, like the tool's other dates. commentCursor pages older comments through the feed the app and REST read (readTaskCommentPage, split out of listTaskComments), past the newest 50.
  • agentRuns: the task's project-agent runs, newest-created first on seq (which never ties on a same-millisecond clock), paged with runCursor (runLimit ≤ 20, default 5). Each has runId, agentId, status, live (queued or running), trigger, dates, failureCode and a 500-character feedback excerpt. There is no transcript, error text, result or workspace handle (exec, session, model).
  • workflowRun: the task's automation run in its own project, the live one or else the latest, with waitingFor. ask carries its askId but not the question text; approval carries its approvalId.
  • pendingReview: the review only a person decides.
  • The run half is read by the readers the task sheet uses (findLive/findLatestAutomationRunForTask, getPendingAskForRun + runWaitingFor, getPendingReviewForTask), plus one seq-ordered projection beside the run card (listTaskAgentRunSummaries), through a new sandbox-lane handler (getTaskWorkStateForAgent). A failed run read fails the call. It never answers a task that looks idle.

One cursor codec. The HMAC codec the REST lists sign their cursors with moves from rest/shared.ts to core/lib/signed_cursor.ts, unchanged, and rest/shared.ts re-exports it. The reused bridge cannot import rest/ or a domain. Outstanding REST cursors keep verifying, and the tools' lists (agent:…) and the REST lists keep apart by name.

The routine-question protocol (docs, EN/DE/FR). Delegate a task to an agent gains Let a manager agent keep the queue moving. It covers passes in created order, a checkpoint comment that carries the cursor to the next run, and a fresh pass after the end or after a refused cursor. A failed read is not an empty queue. It explains what running, finished and person-bound work look like in Read a task, and the protocol itself:

  1. The worker posts its question as a comment (key, evidence, question), names the comment and run ids, and finishes. Its @mention of the manager starts nothing.
  2. The manager answers only while the task still waits on that question: the asking run R is the task's newest run and has finished, nothing is live, and the task waits in review of that run (pendingReview.runId). It keeps R and the review's pendingReview.approvalId from that read. If a person has moved the task on (accepted, cancelled, or asked for changes), the manager reports the question instead.
  3. It posts its answer A as a durable comment naming the question's comment id. It then resumes the agent with Start other agents on tasks, using feat(platform): let a schedule or another agent start a project agent #3942's guarded restart: task_start_agent({taskId, resumeFrom: {runId: R, approvalId}, feedback}). The feedback opens with the question key Q, R and A, since a later task_get shows only the first 500 characters. Under the task's row lock, the start checks that this is still the task's open question before it withdraws the review (never approving it) and resumes the agent.
  4. On stale_question, the question was overtaken between the read and the start (a person decided, a newer run or review exists, or the assignee changed) and nothing changed. The manager re-reads the task and drops the superseded question. It never retries, and never without resumeFrom.
  5. A lost start response is reconciled by reading the task again: a newer run whose feedback opens with that Q/R/A marker means the start went through. The same start sent again answers stale_question and changes nothing.

A standing task's question (a task a schedule starts with moveToInProgress: false) waits for no review. The manager only posts its answer there, and the run at the schedule's next occurrence reads it. Neither the manager nor anyone else starts the task early to deliver it.

Accepting a result, answering an automation's question and deciding an approval stay with people. Live steering and agent approval are out of scope.

Dependency on #3942

This branch starts from current main and shares no commit with #3942. The read tools do not depend on it. Only the protocol's restart step ships in #3942: task_start_agent with its guarded resumeFrom: {runId, approvalId} precondition and stale_question answer (as of #3942 at f47cc9a07), and its label Start other agents on tasks. Merging this before #3942 would leave the new docs section naming a tool that is not there yet, so merge #3942 first. The docs section does not link to #3942's Work an automation or another agent starts yet, because that anchor is not on main.

This PR does not touch #3942's delegated admission, retry budget, import-cursor store or migrations 0139/0140. It avoids its hunks in the files both PRs change (workspace_domain_tools.ts, workspace-write-shim.ts, agent-runs.ts, handler_names.ts, integration-check.ts, the tool descriptions, reference/automation.md). The docs section sits before Handle waiting and failed runs, away from #3942's new section.

How it was verified (local, synthetic data)

  • Real Postgres lane checkAgentTaskReadTools (PG 16 + pgvector; driven over POST /api/tools/execute with native session tokens for project agents' live runs): 21/21 on the head. The only other failure in the run is the known BM25 boot check (no pg_search on the scratch cluster).
    • 260 same-bucket tasks tied on rank and creation millisecond, paged 50 at a time in the database's own (status, rank, id) and (created_at, id) order, each exactly once. Walking twice gives the same order.
    • Cursors: another filter, order, includeArchived, another project's run and a foreign projectId are refused, and so are garbage, truncated, edited, bare-position, number and object cursors. The unchanged cursor still resumes after page one.
    • Concurrent changes:
      • created order: a moved task is listed once in its new state, an archived one not at all, and a new one at the end;
      • board order: a task moved past the cursor is listed again, and one moved behind it is skipped.
    • Comments past the newest 50: a worker's question is found on the second page by the id task_comment answered. A comment cursor pages only its own task.
    • Runs:
      • live, terminal (settledAt, failureCode) and a 500-character feedback excerpt, with no hidden fields;
      • seven runs whose clocks run backwards against their creation order page newest-created first to the end;
      • an automation run waiting on a native question (askId, not the question) and on an approval. Another project's automation run naming the task is not its run.
    • Visibility: subtask and blocker ids, with a hand-inserted cross-project dependency never shown. A foreign task reads exactly as a missing one. A member's confined run reads its project and nothing beyond it, and a neighbour project's run lists only its own tasks.
    • Protocol read half and receipts:
      • the worker's question starts nothing;
      • the manager's answer @mentions the task's own idle agent, the case where a person's mention would start a rework run, and starts no run and no job;
      • the answer reads back as the manager's own comment. done is refused (AGENTS_CANNOT_COMPLETE), ask_human is unavailable to it, and the review stays pending with the card in review;
      • the manager's run 1 saves a checkpoint comment with its cursor, and 55 comments follow. Once run 1 has ended (its token answers run_ended), run 2 finds the checkpoint on the second comment page by author and id and resumes the pass. The two legs list every task exactly once, and after the end a fresh pass starts at the oldest task.
  • Before/after: with main's source swapped in (the lane kept), 18 of the lane's first 20 checks fail. The two that still pass are the worker's inert question and the repeated walk, where main ignores the cursor and returns the same first page twice.
  • Mutation check: eight guard mutations are each caught by the lane: the id tie-break, filter binding, scope binding, a refused cursor restarting the listing, the blocker project guard, runs ordered by clock, an ignored comment cursor, and the agent-author mention guard.
  • No regression: the same 12-lane selection (checkTasks, checkTaskDiscussionPaging, checkRestMachineJourney, checkAutomationRunToolLane, checkTaskAgentRuns, checkOneLiveRunPerTask, checkSandboxSpawner, checkCollabMentions, checkTaskCommentBurst, checkTaskCommentCrossTaskBurst, checkTaskBoardSearch, checkAgentTaskReadTools) on the branch and on main. Nothing fails only on the branch, and 19 checks fail only on main. Four fail on both for environmental reasons: no S3 (document_create), no pg_search, and a filtered run's missing product seed.
  • Docs aligned with feat(platform): let a schedule or another agent start a project agent #3942's guarded restart (a8759c908):
  • Merged with feat(platform): let a schedule or another agent start a project agent #3942 (local only, never pushed), earlier head: a scratch merge of b459b7ce3 with feat(platform): let a schedule or another agent start a project agent #3942 at 942c16648, before feat(platform): let a schedule or another agent start a project agent #3942 added resumeFrom.
  • Unit tests: 110 files and 2,298 tests pass: every test file that directly imports a changed module, plus the source-scanning guards (the REST error-code registry, task errors, handler names, tests/guards, the OpenAPI spec). The new suites are:
    • workspace_tools_bridge.task_reads.test.ts (19): pages, binding, refusals, fractional limits, failed reads, run and comment views;
    • service.agent-list.test.ts: the keyset SQL;
    • agent-work-state.test.ts: the composition;
    • additions to agent-runs.test.ts and chat/shim.test.ts.
  • Static checks:
    • tsc scoped to every changed file and their import graphs is clean;
    • oxlint --type-aware on every changed file is clean, and oxfmt --check passes;
    • the docs suite passes 200/200 across 36 files, and lint:manual passes;
    • check-guide adds no finding for the new register row.
  • Independent review: a read-only adversarial review found one medium issue and three lows, all fixed in 2ba3f9d71 and b459b7ce3:
    • medium: the documented restart could undo a person's decision (see protocol step 2);
    • a fractional limit or runLimit read an empty page as the end;
    • lost-response ids could fall outside the 500-character excerpt;
    • the inert-mention check could not fail for the reason it named.
      CI's first run caught the REST error-code registry guard on an internal TASK_CURSOR_INVALID, which is removed.

Left open

Closes #3955

The HMAC cursor codec every REST list pages with lived in rest/shared.ts,
which the reused workspace-tool bridge cannot import: core code reaches the
0.5 domains only through the ctx shim, never rest/ or the domains. It now
lives in core/lib/signed_cursor.ts, byte for byte, with the same key
derivation, so every outstanding REST cursor still verifies, and
rest/shared.ts re-exports mintCursorFor, verifyCursorFor and
resetCursorKeyForTests for the doors and their tests.

A list name is the scope a cursor redeems in, so the agent tools' lists
(named agent:…) and the REST lists keep apart by name alone.
A manager agent that reconciles a project could not see all of it.
task_find read the first 200 rows of status and rank and stopped, and
answered totalFound: 200 with "Showing the first 50 of 200", a capped count
presented as a total. A column past 200 cards could not be listed at all.
task_get answered the newest 50 comments with no ids and no way to read
older ones, subtasks and blockers without ids, and nothing about the task's
runs, so an agent could not tell running work from finished or person-bound
work.

task_find now answers keyset pages of at most 50 with isDone and a signed
continueCursor. The cursor is bound to its listing: the order, the
effective scope (the run's project, its automation's bound set, or the
organization) and every filter. One passed with other arguments, from
another project's run or another organization, or malformed, cut short or
edited, answers invalid_args and is never read as a first page. totalFound
appears only when one page holds every matching task. Two orders end on the
task id, so tasks tied on rank or on their creation millisecond still page
exactly once: board (status, rank, id), the default and the old order; and
created (created_at, id), where a task keeps its place, so a pass lists each
task at most once while the board moves. The project-bound and member-run
scopes are unchanged.

task_get now names subtasks and blockers by taskId (read inside the task's
own project only, and saying when a list was cut) and each comment by its
commentId, the messageId task_comment answered, with ISO dates like the
tool's other dates. commentCursor pages older comments through the feed the
app and REST read (readTaskCommentPage, split from listTaskComments), past
the newest 50. It lists the task's project-agent runs newest-created first
on seq, paged with runCursor: runId, agentId, status, live, trigger, dates,
failureCode and a 500-character feedback excerpt, never the transcript,
error text, result or workspace handles. It adds the task's automation run
(the live one, else the latest, in the task's own project) with what it
waits on (ask with its askId, approval with its approvalId), and the pending
review. The run half comes from the readers the task sheet uses, through a
new sandbox-lane handler (getTaskWorkStateForAgent). A failed run read fails
the call instead of answering an idle task.

A real-Postgres lane (checkAgentTaskReadTools) drives both tools over
POST /api/tools/execute with native tokens for project agents' live runs.
It pages 260 tasks tied on rank and creation time in the database's own
order in both orders, refuses cursors from other filters, orders, scopes and
malformed ones, and shows what moves between pages do in each order. It
pages a discussion past its newest 50 and a run history against skewed
clocks, reads live, finished, asking and approval-bound work, and checks
that another project's task reads as a missing one. It also runs the read
half of the routine-question protocol: a worker's question starts nothing,
the manager's answer reads back as its own comment, and done stays refused
while the review stays pending. A pass checkpoint saved in a comment is
found by a later run past the newest 50 comments, and the two legs list
every task exactly once. The lane's 20 checks pass here; with main's code
18 of them fail, and seven guard mutations are each caught.
Delegate a task to an agent gains a section on a manager agent that keeps
the queue moving. It explains how Find tasks pages a whole queue and which
cursors it refuses, why a pass walks in created order, and how a pass saved
in a checkpoint comment resumes in the next run. It covers what Read a task
shows to tell running, finished and person-bound work apart, and the
routine-question protocol: the working agent posts its question and
finishes, and the manager answers only once that run has finished, then
restarts it with Start other agents on tasks and checks for a lost restart.
Accepting results, answering an automation's question and deciding an
approval stay with people. English, German and French.

@yannickmonney yannickmonney left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Independent review at 306322c: one P2 correctness hold. The actual /execute HTTP parser, workspace bridge, task handler and run-state query reader reproduce it with synthetic auth/context and SQL rows; this is not native database proof. Ten cases and 20 assertions include positive/default page sizes, read outage, project scope, tool grants and missing authentication. Do not merge until the shared page-size normalization is corrected and covered by regression tests.

Review of the read tools found four gaps:

- CI's REST error-code registry guard failed on TASK_CURSOR_INVALID, a
  code listTasksForAgent threw for a position of another order. No door can
  reach that throw, since the bridge binds the order into the cursor and
  refuses first. The position now carries its order and a later page
  follows it, so the throw is gone.
- A limit or runLimit below one read as zero rows. task_find then answered
  an empty page marked done for a non-empty queue, and task_get an empty run
  page with no cursor, which reads a task with a live run as idle. readLimit
  now reads a fraction as one row, for every tool it serves, and the run
  state reads at least one run a page.
- waitingForCapacity showed on a cancelled run that kept its park stamp;
  it is now true only for a queued run.
- The lane's inert-mention check posted while the worker's own run was
  live, where a person's mention also starts nothing, so it could not fail
  for the reason it named. The manager's answer now @mentions the task's
  own idle agent, the case where a person's mention starts a rework run,
  and the lane checks that no run and no job follow. Removing the
  agent-author guard in dispatchMentionedProjectAgent now fails it.

task_find's description also no longer says the board order reads "the
columns as people see them": it groups tasks by status name, keeping each
column's order.
A manager that answered once the asking run had finished could undo a
person's decision. With #3942 a default restart reopens a Done or
Cancelled card and withdraws whatever review is pending. So if a person
accepted the result, or asked for changes and a newer run's review was
waiting, the restart would reopen the accepted task or withdraw the newer
review.

The protocol now answers only while the task still waits on that question:
the run that asked is the task's newest run and has finished, nothing is
live, and the task waits in review of that run (pendingReview.runId). If a
person moved it on, the manager reports the question instead. The restart
message opens with the question key, the answer's comment ID and the
source run, because a later Read a task shows only the first 500
characters of it. The worker reads its own run ID off Read a task.

The board order is now described as grouped by status, keeping each
column's order. The German and French wording follows the English
definition more closely, and the German verb agrees with its plural
subject.
#3942 now gives task_start_agent an atomic precondition for resuming a
question: resumeFrom {runId, approvalId}. Under the task's row lock the
resumption goes ahead only while that run is the task's newest and has
ended, that review is its only pending review and bound to it, the card is
at In review and the run's agent is still the assignee. Otherwise it
answers stale_question and changes nothing. Reading before restarting
could not protect a person's decision made between the read and the
start; this precondition does.

The manager's protocol in Delegate a task to an agent now uses it:

- It keeps the asking run's ID and pendingReview.approvalId from its read,
  and posts its answer as a durable comment.
- It passes both IDs as resumeFrom, with a message that opens with the
  question key, the run ID and the answer's comment ID, within the 500
  characters Read a task shows later.
- On stale_question it re-reads the task and drops the outdated question.
  It never retries, and never without the guard.
- A lost response is reconciled from the newer run's message, and the same
  start sent again answers stale_question and changes nothing.
- A standing task's question waits for no review. The answer is left for
  the run at the schedule's next occurrence, and nobody starts the task
  early to deliver it.

Accepting results, native questions and approvals stay with people.
English, German and French use #3942's terms for standing tasks and
occurrences. No link to #3942's section yet, since its anchor is not on
main.

@yannickmonney yannickmonney left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Independently accepted the requested EN/DE/FR documentation delta at a8759c9. Only the three task-automation pages change; the backend tree is unchanged from accepted b459b7c. All locales preserve the current R/P guard, durable answer, stale refusal without unconditional fallback, first-500-character lost-response reconciliation, and answer-only/next-schedule handling for standing roles. The exact five candidate role documents agree with that protocol.

Focused content/locale and actual Markdown-renderer checks passed: 11 files, 38 tests. The three rendered protocols have five ordered steps with matching technical fields. This is source/translation/render evidence, not native or browser execution proof.

Scheduler source is independently accepted through #3942 f8269c4 within its recorded review scope. Root owns the final combined native proof and normal merges. Current main's separate navRestore typecheck failure is repaired by #3964; please do not duplicate that fix or copy scheduler commits here. Land the scheduler contract before relying on these docs, refresh required CI normally, and keep all schedule/grant activation off.

@yannickmonney

Copy link
Copy Markdown
Contributor Author

The remaining independent manager native gate passed 79/79 checks across all three selected lanes, on the isolated combined scheduler/manager/nav source 9a1b638955c1d7f361aa9a8ecbff97c690f8853f. This includes real paginated task/comment/run reads, the native human-decision barrier, one guarded question resumption with lost-response/fast-terminal recovery, ten unchanged-state refusal controls, standing Answer consumption at the next actual native minute with both cursors preserved, and the existing human-move/retry/completion lane. Native process and wrapper both exited zero.

Detailed scope and limits: #3942 (comment)

This is local synthetic native evidence with inert agent/provider effects. Normal current-head CI, scheduler-first normal merges and actual merged-main source reconciliation remain required. No production schedule or new grant has been enabled.

@yannickmonney
yannickmonney merged commit 3185987 into main Sep 30, 2026
50 checks passed
@yannickmonney
yannickmonney deleted the feat/task-read-tools-pagination branch September 30, 2026 01:15
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.

feat(platform): expose complete task state to project agents

1 participant