Repository navigation
fix(orchestration): list worker Dispatches newest first and warn when the page truncates - #21523
Conversation
… the page truncates `worker-list` paged `ORDER BY d.rowid ASC` with a 100-row cap, so a Run with more than 100 Dispatches answered with its OLDEST 100. The workers a coordinator had just started, and the rows carrying `projection.attention.requiresAction`, were on a page nobody fetched, while `counts` and `page.total` covered the whole Run so the receipt read as complete. One ordering, flipped: the detail query and the terminal-state scan it pages by both order `d.rowid DESC`, and the cursor fence walks down (`d.rowid < anchor`). The snapshot fence is unchanged — `d.rowid <= snapshot` still means "nothing created after the first call". When the page truncates the receipt now carries a `warnings` string, the same shape `worker-output` already uses, alongside `page.hasMore`. Text output keeps its `More: --cursor` line and prints the warning through the block it already had for partial-host errors. Refs STA-7861
📝 WalkthroughWalkthroughWorker-list results now use newest-first ordering and cursor pagination. Paginated responses include a warning that identifies the returned Dispatches and the next cursor. The CLI preserves and formats runtime warnings with partial host errors. Tests cover ordering, cursor behavior, filtered results, pinned counts, warning propagation, and CLI output. Documentation describes the pagination procedure. Priority: ⬇️ Low Merge Risk: 🔵 Low · up to Operators using a small page limit could stop before reviewing all Dispatches. Clarify the cursor guidance before merge or accept this bounded documentation risk. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Docstring CoverageExplanation Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 7 files. (1 skipped: 1 unsupported.)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
…very page The warning said "Showing the N newest of T Dispatches" unconditionally, but `hasMore` is true on every page except the last, so page 2 of a 300-Dispatch Run claimed to be the newest 100 while showing rows 200..101. This PR exists because a receipt read as complete when it was not; that warning shipped a receipt that read as the newest page when it was not. The page count and the ordering are separate facts, so state them separately: "Showing N of T Dispatches, newest first; more are on later pages." True on page one and page N alike, no extra state. The 105-row case only ever reached the last page, where `hasMore` is false, which is why it missed this; a new case walks 6 Dispatches at `--limit 2` so a page that is truncated AND not page one is covered. Also: the `worker-list` --help note and the recovery-and-cleanup reference still described the oldest-first contract; both now say newest first. The snapshot test is renamed to the property it actually proves — under DESC a later insert is unreachable by arithmetic, so what the `d.rowid <= snapshot` fence still earns is pinned `page.total` and `counts`, not row exclusion. The continuation comment says "below the anchor" next to `d.rowid < ?`, and the two SAFETY rationales now say what they are: an unchanged cast the gate flagged because the diff moved inside its span. Refs STA-7861
There was a problem hiding this comment.
ℹ️ No critical issues — one minor wording suggestion inline.
Reviewed changes
- Newest-first ordering —
listWorkerTerminalResourcesandscanWorkerTerminalStatesnow orderd.rowid DESC, and the continuation fence walks down (d.rowid < ?). The snapshot fence (d.rowid <= snapshot.databaseId) and the pre-v3 anchor resolution are untouched, so the stable-snapshot and index-for-index snapshot checks still hold. - Truncation warning — the paginated result gains an optional
warningsstring whenpage.hasMore, surfaced by the CLI as aWarning:line next to the existingMore: --cursorhint. - CLI plumbing — server
warningsandpartialHostErrorsare merged and prefixed withWarning:exactly once; JSON passeswarningsthrough unprefixed. - Docs — the recovery step in
skill-guides/orchestration.mdnow mentions newest-first and cursor paging;src/cli/bundled-skill-guides.tsis regenerated (verified withpnpm run verify:bundled-skill-guides). - Tests — a new pagination case seeds 105 Dispatches, asserts the exact page order, warning text, and counts, then follows the cursor while excluding a Dispatch inserted after the first call; a CLI case asserts the warning reaches the formatter. Existing order assertions were inverted.
I independently checked the consumer census: send-group.ts (membership only), worker-observation.ts / federated-worker-show (single Dispatch), projectOrchestrationFleet (preserves input order, never sorts), and renderer/mobile/cloud (no worker-list consumer). No order-dependent consumer was missed, and pnpm exec vitest run over the worker, CLI, and shared suites passes.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
Since the prior pullfrog review at 49ea34ec:
- Warning wording — now
Showing N of M Dispatches, newest first; more are on later pages., which is true on every truncated page rather than only page one. - Middle-page regression test — a new case walks 6 Dispatches at
--limit 2and asserts the exact warning on pages 1 and 2 andundefinedon page 3, pinning that a continuation page does not claim to hold the newest rows. - Docs/help — the
worker-list--helpnote,skill-guides/orchestration.md, and therecovery-and-cleanupreference now say newest first;src/cli/bundled-skill-guides.tsis regenerated. - Comment/SAFETY polish — the moved-cast rationale now states the cast is unchanged, and the paging comment says the continuation "sits below the anchor".
The ordering flip, snapshot/cursor invariants, CLI warning plumbing, and the documented send-group newest-mailbox alignment are unchanged from the initial review and were verified there.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: f1c9b6cf-b2ef-41a0-87c9-69dd85180fb4
📒 Files selected for processing (8)
skill-guides/orchestration/references/recovery-and-cleanup.mdsrc/cli/bundled-skill-guides.tssrc/cli/handlers/orchestration-worker-cli.test.tssrc/cli/specs/orchestration-worker-specs.tssrc/main/runtime/orchestration/db/worker-terminal/worker-terminal-inventory-counts.tssrc/main/runtime/orchestration/db/worker-terminal/worker-terminal-listing.tssrc/main/runtime/rpc/methods/orchestration/worker/worker-list-method.tssrc/main/runtime/rpc/methods/orchestration/worker/worker-list-pagination.test.ts
🚧 Files skipped from review as they are similar to previous changes (3)
- src/main/runtime/rpc/methods/orchestration/worker/worker-list-method.ts
- src/cli/handlers/orchestration-worker-cli.test.ts
- src/main/runtime/orchestration/db/worker-terminal/worker-terminal-listing.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 0 remain after this review.
| verdict. Rows come newest first and past 100 the response pages, so follow | ||
| `page.nextCursor` with `--cursor <value>` until `page.hasMore` is false. |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
rg -n -- '--limit|limit:' src/cli/specs/orchestration-worker-specs.ts src/cli/handlers/orchestration src/main/runtime/rpc/methods/orchestration/worker/worker-list-method.ts
sed -n '40,58p' skill-guides/orchestration/references/recovery-and-cleanup.md
sed -n '270,315p' src/main/runtime/rpc/methods/orchestration/worker/worker-list-method.tsRepository: stablyai/orca
Length of output: 4003
🏁 Script executed:
sed -n '1,190p' src/main/runtime/rpc/methods/orchestration/worker/worker-list-method.ts
rg -n --glob '*.ts' 'ORCHESTRATION_WORKER_LIST_SNAPSHOT_MAX_ROWS|hasMore|nextCursor|worker-list' src/main/runtime src/cli | head -240Repository: stablyai/orca
Length of output: 50372
🏁 Script executed:
sed -n '190,285p' src/main/runtime/rpc/methods/orchestration/worker/worker-list-method.ts
sed -n '1,180p' src/main/runtime/rpc/methods/orchestration/worker/worker-release-schemas.ts
sed -n '105,130p' src/cli/specs/orchestration-worker-specs.tsRepository: stablyai/orca
Length of output: 5693
Describe pagination relative to the selected limit.
worker-list accepts --limit <1-100>. The RPC sets page.hasMore and page.nextCursor when more than the selected limit exists, so --limit 2 can paginate after two rows. Replace “past 100” with wording that makes page.hasMore the condition for following page.nextCursor, and state that 100 is the maximum page size.

What the user notices
Before:
orca orchestration worker-list --run <id> --jsonon a Run with more than 100Dispatches returns the oldest 100. The workers a coordinator just started, and every row
carrying
projection.attention.requiresAction, sit on a page nobody fetches.countsandpage.totalcover the whole Run, so the receipt reads as complete; onlypage.hasMoresaysotherwise, and the main guide's recovery step ("after three empty waits, enumerate with
worker-list and act on attention") never mentioned the cursor. The user's own DB has Runs with
417, 316 and 144 Dispatches.
After: page one is the newest 100 rows. A coordinator acting on page one sees the
workers it just started and every recent attention row. When more pages exist the JSON receipt
carries a
warningsstring saying the page truncated, alongside the existingpage.hasMore.The change
One ordering, flipped — no
--orderflag, no config knob, no second code path.worker-terminal-listing.ts:ORDER BY d.rowid DESC, and the cursor fence walks down(
d.rowid > anchor→d.rowid < anchor). The snapshot fence is untouched:d.rowid <= snapshot.databaseIdstill means "nothing created after the first call", which is what pinspage.totalandcountsacross a paging walk.worker-terminal-inventory-counts.ts:scanWorkerTerminalStatesordersDESCtoo. The--terminal-statepath pages by slicing that scan, so leaving it ascending would have made afiltered page take the oldest N matches and then print them newest-first. Counting is
order-independent, so this is its only behavioural consumer.
worker-list-method.ts: whenhasMore, the receipt gainswarnings: [...]— the samestring[]shapeorchestration worker-outputalready publishes, not a new envelope.worker-terminal-handlers.ts: the CLI feeds serverwarningsthrough the warning block italready had for
partialHostErrors. TheMore: --cursor <value>line is unchanged.worker-list--helpnote (orchestration-worker-specs.ts),skill-guides/orchestration.mdrecovery step, andskill-guides/orchestration/references/recovery-and-cleanup.mdall say newest first.src/cli/bundled-skill-guides.tsregenerated withpnpm run generate:bundled-skill-guides.Consumer census
rg -n "listWorkerTerminalResources|scanWorkerTerminalStates|projectOrchestrationFleet|projectWorkerFleet" src mobile:worker-list-method.tsworker-list-method.tsv3 snapshot storedispatchIdsfrom the same query and re-reads them with the same query, then asserts index-for-index equality. Both sides moved together, so the pin still holds.projectOrchestrationFleet(src/shared)worker-observation.tsdispatchId.send-group.ts:179candidates.find((c) => c.handle === handle)is first-wins over this listing, so when one terminal handle owns two live Dispatches in a Run, a@all/ group send now writes to the newest Dispatch's mailbox instead of the oldest. That population is real —getActiveDispatchMailboxOwnersexists because one handle can own several live mailboxes. This is the correct direction:dispatch-lookup.ts:25and:69already resolve handle → Dispatch withORDER BY rowid DESC, so before this PRsend-groupwas the one resolver in the subsystem that picked the oldest. It now agrees with the rest.federated-fleet-snapshot.ts(--include-remote)agent-status-orchestration-context.tsonly imports the attention comparator).Nothing depended on ascending order for correctness.
What was deleted
The duplicated 7-field args object literal on
projectWorkerListPage/projectWorkerListPageWithFilteredSnapshotis gone, replaced by oneWorkerListPageArgstype(net −9 lines in that file, which is what kept it under the 300-line cap after the warning
landed). The ordering change itself is a pure edit, not an addition: two
ASC→DESCand one>→<. Nothing else could be removed — the warning is genuinely new information thatpage.hasMorealone does not convey to a caller scanning rows.Two
ascasts in the two SQL files carryoxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY:comments. The casts are unchanged. Thechanged-code gate keys on the diagnostic's whole span, which is the entire
this.db.prepare(`…SQL…`).all(…) as {…}[]expression, so editingORDER BYinside the SQLmakes a pre-existing cast read as new; its moved-code exemption needs ≥90 % of the span to match
base in order and gives up after the first mismatch. Hoisting the row type or the prepared
statement was tried and fails outright (a genuinely new cast line has no base anchor). ~40
identical casts in the same
db/layer carry no such comment — these two are the same debt, notspecially justified, and the comments say so.
Verification
Unit (
worker-list-pagination.test.ts): a case seeds 105 Dispatches, asserts the unpaged callreturns 105…6 with
hasMoreand the warning, then follows--cursorand asserts 5…1 whileexcluding a Dispatch inserted after the first call, with
page.totalandcountsstill at 105on both pages. A second case walks 6 Dispatches at
--limit 2so a page that is truncated andnot page one is covered — that is what caught the first draft of the warning, which said "the
N newest" unconditionally and was therefore false on every continuation page. Eleven existing
order assertions were inverted (including three legacy-cursor cases whose anchors moved from the
oldest row to the newest so they still page a non-empty result). CLI
(
orchestration-worker-cli.test.ts): a case asserts the receipt handed toprintResultcarrieswarningsand the text formatter prints bothMore: --cursorand theWarning:line.Live receipt — built CLI against an isolated dev runtime
pnpm run build:cli && pnpm run build:electron-vite, then a headless runtime on a scratchprofile, a Run, and 105 record-only Dispatches (
task-create+dispatchwithout--inject).The warning wording below is the final text; the row ordering and paging shown are unchanged
from the recorded run.
Text tail of the same unpaged call:
Gates
pnpm tc/pnpm run tc:node— passpnpm test src/main/runtime/rpc/methods/orchestration src/main/runtime/orchestration/db src/cli—246 files / 2347 tests pass
pnpm run check:code-quality:changed— pass,pnpm run check:react-doctor:changed— passpnpm run verify:bundled-skill-guidesplusgenerate-bundled-skill-guides.test.mjsandcomputer-use-skill-guidance.test.mjs— passpnpm run check:max-lines-ratchet— pass, no new bypassesWire compatibility
Per
docs/reference/remote-wire-compatibility.md:warningsis a new optional field on theorchestration.workerListresult, which is the safe shape — old clients ignore it, and the CLIreads it as
value.warnings ?? []. No new stream opcode, no capability negotiation needed.The row order within a page is not a wire contract.
page.nextCursoris opaque and is mintedby the same host that interprets it,
page.total/counts/page.hasMoreare unchanged, andno client sorts or index-addresses the array. An old client paired to a new host simply reads
its Run newest-first — which is the fix; a new client paired to an old host reads it
oldest-first, exactly as it does today, because the ordering lives entirely in the host's SQL.
SSH and folder workspaces
No execution-host contact is involved: the ordering and the warning are both derived from the
home orchestration DB before
--include-remoteasks any host anything.--include-remotestillapplies federated observations by
dispatchIdonto whatever rows the page holds, so a remoteworker's
live/unverifiable/exitedverdict is unaffected and absence still neverpromotes to
exited. Nothing here reads a git worktree, so folder workspaces and git worktreesbehave identically.
Refs STA-7861