Skip to content

fix(orchestration): list worker Dispatches newest first and warn when the page truncates - #21523

Merged
Jinwoo-H merged 2 commits into
mainfrom
sta-7861-worker-list-newest-first
Sep 18, 2026
Merged

Jinwoo-H merged 2 commits into
mainfrom
sta-7861-worker-list-newest-first

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

What the user notices

Before: orca orchestration worker-list --run <id> --json on a Run with more than 100
Dispatches returns the oldest 100. The workers a coordinator just started, and every row
carrying projection.attention.requiresAction, sit on a page nobody fetches. counts and
page.total cover the whole Run, so the receipt reads as complete; only page.hasMore says
otherwise, 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 warnings string saying the page truncated, alongside the existing page.hasMore.

The change

One ordering, flipped — no --order flag, 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.databaseId still means "nothing created after the first call", which is what pins
    page.total and counts across a paging walk.
  • worker-terminal-inventory-counts.ts: scanWorkerTerminalStates orders DESC too. The
    --terminal-state path pages by slicing that scan, so leaving it ascending would have made a
    filtered 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: when hasMore, the receipt gains warnings: [...] — the same
    string[] shape orchestration worker-output already publishes, not a new envelope.
  • worker-terminal-handlers.ts: the CLI feeds server warnings through the warning block it
    already had for partialHostErrors. The More: --cursor <value> line is unchanged.
  • Contract text: the worker-list --help note (orchestration-worker-specs.ts),
    skill-guides/orchestration.md recovery step, and
    skill-guides/orchestration/references/recovery-and-cleanup.md all say newest first.
    src/cli/bundled-skill-guides.ts regenerated with pnpm run generate:bundled-skill-guides.

Consumer census

rg -n "listWorkerTerminalResources|scanWorkerTerminalStates|projectOrchestrationFleet|projectWorkerFleet" src mobile:

Consumer Order dependency
worker-list-method.ts Pages by this order; flipped deliberately.
worker-list-method.ts v3 snapshot store Stores dispatchIds from 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) Slices the array it is handed; never re-sorts.
worker-observation.ts Single dispatchId.
send-group.ts:179 Behaviour change, deliberate. candidates.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 — getActiveDispatchMailboxOwners exists because one handle can own several live mailboxes. This is the correct direction: dispatch-lookup.ts:25 and :69 already resolve handle → Dispatch with ORDER BY rowid DESC, so before this PR send-group was the one resolver in the subsystem that picked the oldest. It now agrees with the rest.
federated-fleet-snapshot.ts (--include-remote) Applies observations by dispatchId onto the page rows. No merge step, no re-sort.
renderer / mobile No fleet list consumer exists (agent-status-orchestration-context.ts only imports the attention comparator).

Nothing depended on ascending order for correctness.

What was deleted

The duplicated 7-field args object literal on projectWorkerListPage /
projectWorkerListPageWithFilteredSnapshot is gone, replaced by one WorkerListPageArgs type
(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 → DESC and one
> → <. Nothing else could be removed — the warning is genuinely new information that
page.hasMore alone does not convey to a caller scanning rows.

Two as casts in the two SQL files carry oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: comments. The casts are unchanged. The
changed-code gate keys on the diagnostic's whole span, which is the entire
this.db.prepare(`…SQL…`).all(…) as {…}[] expression, so editing ORDER BY inside the SQL
makes 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, not
specially justified, and the comments say so.

Verification

Unit (worker-list-pagination.test.ts): a case seeds 105 Dispatches, asserts the unpaged call
returns 105…6 with hasMore and the warning, then follows --cursor and asserts 5…1 while
excluding a Dispatch inserted after the first call, with page.total and counts still at 105
on both pages. A second case walks 6 Dispatches at --limit 2 so a page that is truncated and
not 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 to printResult carries
warnings and the text formatter prints both More: --cursor and the Warning: 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 scratch
profile, a Run, and 105 record-only Dispatches (task-create + dispatch without --inject).
The warning wording below is the final text; the row ordering and paging shown are unchanged
from the recorded run.

$ orca orchestration worker-list --run run_183571540c70 --json
rows        : 100
first row   : ctx_937022a6e2c0 task=task_2043b5c443f0      <- probe 105, newest
last row    : ctx_fb00461a16e3 task=task_d4ec9fad62c7      <- probe 006
page        : {"limit": 100, "total": 105, "hasMore": true,
               "nextCursor": "eyJ2ZXJzaW9uIjoyLCJzbmFwc2hvdCI6eyJkYXRhYmFzZUlkIjoxMDV9LCJhZnRlciI6eyJjcmVhdGVkQXQiOiIyMDI2LTA5LTE4IDIwOjM5OjE0IiwiZGlzcGF0Y2hJZCI6ImN0eF9mYjAwNDYxYTE2ZTMiLCJkYXRhYmFzZUlkIjo2fX0"}
counts      : {"retained": 105}
warnings    : ["Showing 100 of 105 Dispatches, newest first; more are on later pages. Follow page.nextCursor with --cursor."]

$ orca orchestration worker-list --run run_183571540c70 --cursor eyJ2ZXJzaW9uIjoy... --json
rows        : 5
first row   : ctx_f6459595cdcd task=task_40df086fce41      <- probe 005
last row    : ctx_60e1a77a6f98 task=task_e0345ae4e3db      <- probe 001, oldest
page        : {"limit": 100, "total": 105, "hasMore": false, "nextCursor": null}
counts      : {"retained": 105}
warnings    : null

Text tail of the same unpaged call:

ctx_fb00461a16e3 task=task_d4ec9fad62c7 [unsupervised/unknown] attention=unverifiable liveness=unverifiable ... terminal=retained next=none
Terminals: retained=105
Scope: Run run_183571540c70 (--run)
More: --cursor eyJ2ZXJzaW9uIjoyLCJzbmFwc2hvdCI6eyJkYXRhYmFzZUlkIjoxMDV9LCJhZnRlciI6eyJjcmVhdGVkQXQiOiIyMDI2LTA5LTE4IDIwOjM5OjE0IiwiZGlzcGF0Y2hJZCI6ImN0eF9mYjAwNDYxYTE2ZTMiLCJkYXRhYmFzZUlkIjo2fX0
Warning: Showing 100 of 105 Dispatches, newest first; more are on later pages. Follow page.nextCursor with --cursor.

Gates

  • pnpm tc / pnpm run tc:node — pass
  • pnpm 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 — pass
  • pnpm run verify:bundled-skill-guides plus generate-bundled-skill-guides.test.mjs and
    computer-use-skill-guidance.test.mjs — pass
  • pnpm run check:max-lines-ratchet — pass, no new bypasses

Wire compatibility

Per docs/reference/remote-wire-compatibility.md: warnings is a new optional field on the
orchestration.workerList result, which is the safe shape — old clients ignore it, and the CLI
reads it as value.warnings ?? []. No new stream opcode, no capability negotiation needed.

The row order within a page is not a wire contract. page.nextCursor is opaque and is minted
by the same host that interprets it, page.total / counts / page.hasMore are unchanged, and
no 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-remote asks any host anything. --include-remote still
applies federated observations by dispatchId onto whatever rows the page holds, so a remote
worker's live / unverifiable / exited verdict is unaffected and absence still never
promotes to exited. Nothing here reads a git worktree, so folder workspaces and git worktrees
behave identically.

Refs STA-7861

… 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
@coderabbitai

coderabbitai Bot commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

📝 Walkthrough

Walkthrough

Worker-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 36577

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)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning 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… Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly identifies the two main changes: newest-first worker Dispatch listing and truncation warnings.
Description check ✅ Passed The description is detailed and on-topic. It explains the user-visible behavior, implementation, rationale, testing, compatibility, and issue reference. Some template checkboxes and attachment require…
Full details: Docstring Coverage

Explanation

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.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

…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

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ℹ️ No critical issues — one minor wording suggestion inline.

Reviewed changes

  • Newest-first ordering — listWorkerTerminalResources and scanWorkerTerminalStates now order d.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 warnings string when page.hasMore, surfaced by the CLI as a Warning: line next to the existing More: --cursor hint.
  • CLI plumbing — server warnings and partialHostErrors are merged and prefixed with Warning: exactly once; JSON passes warnings through unprefixed.
  • Docs — the recovery step in skill-guides/orchestration.md now mentions newest-first and cursor paging; src/cli/bundled-skill-guides.ts is regenerated (verified with pnpm 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.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ 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 2 and asserts the exact warning on pages 1 and 2 and undefined on page 3, pinning that a continuation page does not claim to hold the newest rows.
  • Docs/help — the worker-list --help note, skill-guides/orchestration.md, and the recovery-and-cleanup reference now say newest first; src/cli/bundled-skill-guides.ts is 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.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: f1c9b6cf-b2ef-41a0-87c9-69dd85180fb4

📥 Commits

Reviewing files that changed from the base of the PR and between 49ea34e and 365778e.

📒 Files selected for processing (8)
  • skill-guides/orchestration/references/recovery-and-cleanup.md
  • src/cli/bundled-skill-guides.ts
  • src/cli/handlers/orchestration-worker-cli.test.ts
  • src/cli/specs/orchestration-worker-specs.ts
  • src/main/runtime/orchestration/db/worker-terminal/worker-terminal-inventory-counts.ts
  • src/main/runtime/orchestration/db/worker-terminal/worker-terminal-listing.ts
  • src/main/runtime/rpc/methods/orchestration/worker/worker-list-method.ts
  • src/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.

Comment on lines +49 to +50
verdict. Rows come newest first and past 100 the response pages, so follow
`page.nextCursor` with `--cursor <value>` until `page.hasMore` is false.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🎯 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.ts

Repository: 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 -240

Repository: 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.ts

Repository: 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.

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