Repository navigation
feat(platform): let project agents page the queue and read run state - #3963
Conversation
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
left a comment
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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.
|
The remaining independent manager native gate passed 79/79 checks across all three selected lanes, on the isolated combined scheduler/manager/nav source 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. |
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_findread the first 200 rows ofstatus, rankand stopped. It answeredtotalFound: 200with "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_getanswered 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 queueisDoneand, while more follow, a signedcontinueCursor. The last page has no cursor to pass back.invalid_args. It is never read as a first page. The page size may change between pages.totalFoundappears only when one page holds every matching task, the one case where the count is a total.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.task_get: ids, continuation and run statetaskId(andnumber). They are read inside the task's own project only, even for a dependency row put in by hand, andsubtasksTruncated/blockedByTruncatedsay when a list was cut.commentId(themessageIdtask_commentanswered) and ISO dates, like the tool's other dates.commentCursorpages older comments through the feed the app and REST read (readTaskCommentPage, split out oflistTaskComments), past the newest 50.agentRuns: the task's project-agent runs, newest-created first onseq(which never ties on a same-millisecond clock), paged withrunCursor(runLimit≤ 20, default 5). Each hasrunId,agentId,status,live(queued or running),trigger, dates,failureCodeand a 500-characterfeedbackexcerpt. 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, withwaitingFor.askcarries itsaskIdbut not the question text;approvalcarries itsapprovalId.pendingReview: the review only a person decides.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.tstocore/lib/signed_cursor.ts, unchanged, andrest/shared.tsre-exports it. The reused bridge cannot importrest/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:
pendingReview.runId). It keeps R and the review'spendingReview.approvalIdfrom that read. If a person has moved the task on (accepted, cancelled, or asked for changes), the manager reports the question instead.task_start_agent({taskId, resumeFrom: {runId: R, approvalId}, feedback}). The feedback opens with the question key Q, R and A, since a latertask_getshows 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.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 withoutresumeFrom.stale_questionand 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
mainand shares no commit with #3942. The read tools do not depend on it. Only the protocol's restart step ships in #3942:task_start_agentwith its guardedresumeFrom: {runId, approvalId}precondition andstale_questionanswer (as of #3942 atf47cc9a07), 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 onmain.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)
checkAgentTaskReadTools(PG 16 + pgvector; driven overPOST /api/tools/executewith 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 (nopg_searchon the scratch cluster).(status, rank, id)and(created_at, id)order, each exactly once. Walking twice gives the same order.includeArchived, another project's run and a foreignprojectIdare refused, and so are garbage, truncated, edited, bare-position, number and object cursors. The unchanged cursor still resumes after page one.task_commentanswered. A comment cursor pages only its own task.settledAt,failureCode) and a 500-character feedback excerpt, with no hidden fields;askId, not the question) and on an approval. Another project's automation run naming the task is not its run.doneis refused (AGENTS_CANNOT_COMPLETE),ask_humanis unavailable to it, and the review stays pending with the card in review;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.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, wheremainignores the cursor and returns the same first page twice.checkTasks,checkTaskDiscussionPaging,checkRestMachineJourney,checkAutomationRunToolLane,checkTaskAgentRuns,checkOneLiveRunPerTask,checkSandboxSpawner,checkCollabMentions,checkTaskCommentBurst,checkTaskCommentCrossTaskBurst,checkTaskBoardSearch,checkAgentTaskReadTools) on the branch and onmain. Nothing fails only on the branch, and 19 checks fail only onmain. Four fail on both for environmental reasons: no S3 (document_create), nopg_search, and a filtered run's missing product seed.a8759c908):f47cc9a07(local only) has no conflicts ingit merge-tree. Its docs suite also passes 200/200, and the page outline composes: this section sits before Handle waiting and failed runs, and feat(platform): let a schedule or another agent start a project agent #3942's section after it.b459b7ce3with feat(platform): let a schedule or another agent start a project agent #3942 at942c16648, before feat(platform): let a schedule or another agent start a project agent #3942 addedresumeFrom.git merge-treeconflicted only intests/manual/readme.md(box counts), a conflict betweenmainand feat(platform): let a schedule or another agent start a project agent #3942 alone. feat(platform): let a schedule or another agent start a project agent #3942 has since mergedmain, and atf47cc9a07there is no conflict at all.checkDelegatedAgentStartTool,checkScheduledAgentStartsandcheckImportCursorContinuation, and a scratch probe of the protocol's restart half: 78/79, with only BM25 failing.942c16648:task_start_agentanswersalready_running;task_getreads back the new run (live,trigger: "delegated", feedback containing the answer id) and the review withdrawn, never approved;task_get, and a repeated start answers the same run.resumeFrom. With feat(platform): let a schedule or another agent start a project agent #3942 atf47cc9a07, a repeated guarded start answersstale_questioninstead. The guarded restart's native proof belongs to feat(platform): let a schedule or another agent start a project agent #3942's own lane (per itsf47cc9a07commit) and to root's combined proof (TALE-369, in preparation). I did not re-run a runtime proof for this revision.tscis clean on the merged final head. The shared unit suites (31 files, 486 tests) passed on the first merge, before the review fixes.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;agent-runs.test.tsandchat/shim.test.ts.tscscoped to every changed file and their import graphs is clean;oxlint --type-awareon every changed file is clean, andoxfmt --checkpasses;lint:manualpasses;check-guideadds no finding for the new register row.2ba3f9d71andb459b7ce3:limitorrunLimitread an empty page as the end;CI's first run caught the REST error-code registry guard on an internal
TASK_CURSOR_INVALID, which is removed.Left open
resumeFrom,stale_question) is feat(platform): let a schedule or another agent start a project agent #3942's. Its native proof belongs to feat(platform): let a schedule or another agent start a project agent #3942's lane and to root's combined proof (TALE-369, in preparation). My earlier probe exercised only the unguarded restart of942c16648.mainyet, and the link check would fail.task_get;task_findrows stay as they were.a8759c908fails withnavRestoreerrors (TS2339) in two files this PR does not touch.main's own Type check at498a95319(feat(platform): remember section entry points across main navigation tiles #3959) fails with the same two errors, and every other check passes. Onb459b7ce3, beforemainbroke, all 44 checks passed.Closes #3955