Skip to content

perf(cli): load zod at a queue transfer verb's first parse, not with every rig queue command - #4080

Merged
mvschwarz merged 1 commit into
mainfrom
dev60review/queue-transfer-lazy-zod
Nov 28, 2026
Merged

mvschwarz merged 1 commit into
mainfrom
dev60review/queue-transfer-lazy-zod

Conversation

@mvschwarz

@mvschwarz mvschwarz commented Nov 28, 2026 •

Copy link
Copy Markdown
Owner

What this changes

rig queue list and rig queue show run about 45–85 ms faster again, back to 0.7.24's time. The output is unchanged.

The CLI loads only the module of the command being run (lazy-program.ts). The queue command module registers queue transfer (#3917), and queue-transfer.ts imported zod at the top level and built two schemas when it loaded. So every rig queue command, list and show included, loaded zod's roughly 95 modules at start-up, although only the transfer verbs use it.

queue-transfer.ts now builds its three schemas from a dynamic import("zod") at a transfer verb's first parse. It already loads @openrig/daemon/queue-transfer-records the same way. The type-only import("zod") in type positions compiles away. Every use is inside an async action, and a parse error is a rejection from the same action as before.

Evidence

Setup: one Linux test machine (4 vCPU, Node 22.23.4) with one daemon, the current version with no kernel, on a synthetic queue of about 350 rows. Three CLIs read the same rows:

  • A: published 0.7.24;
  • B: the CLI package built from main at f9e55998, before this change (the queue command path is unchanged from there to this PR's base);
  • P: B's installed package with only this edit applied to dist/commands/queue-transfer.js. A recursive diff of the two installs names that file alone.

Request sequence: each read sends the same two requests in every arm, GET /healthz and then the read (logged through a recording proxy). So the cost isn't in what the CLI asks for.

Modules loaded:

Read A B P
queue list / show 48 files, no zod 144 files, 95 of them zod 49 files, no zod
view show 34 34 34

B's extra files are queue-transfer.js and zod's 95, nothing else.

Wall and CPU time: medians in ms of 60 runs per arm and read. They come from two runs of 18 blocks each, with the arms rotated so each is in each position equally often. Each block's first run is discarded.

Read A wall B wall P wall B−A P−A CPU A / B / P
queue list --json 339 423 360 +84 +20 359 / 453 / 361
queue list --json --state blocked 284 362 279 +78 −5 358 / 460 / 357
queue list --json --owned 333 420 337 +87 +3 356 / 467 / 348
queue show <id> --full --json, five rows 287–304 328–367 275–300 +42 to +65 −25 to −2 341–357 / 431–456 / 353–360
view show escalations --json (control) 250 261 253 +11 +3 312 / 326 / 317
view show pickup --json (control) 311 330 316 +19 +5 310 / 327 / 326

The same URLs over curl took 2–62 ms in every arm. The machine is shared, so single blocks vary by tens of ms. CPU time is the steadier signal: B costs about 80–110 ms more than A on every queue read, and P matches A.

Output: the output is byte-identical between B and P for:

  • all eight JSON reads;
  • the human-readable queue list and queue show;
  • a missing row's error and an unreachable daemon's error, with the same exit codes;
  • the queue and queue transfer help.

The two views match once their generatedAt time is normalized. A's output equals B's for all of these except the help, where B also lists queue transfer.

Tests

The new test, packages/cli/test/queue-command-startup.test.ts, loads the queue command module with zod mocked to throw, then builds rig queue with list, show and transfer (with its subcommands). Without this change it fails at queue-transfer.ts's import { z } from "zod" ("zod was loaded with the queue command module"); with it, it passes.

On Linux (Node 22.23.4), from the base's source plus this commit:

  • Build and lint: npm run build and npm run lint pass.
  • Related tests: queue-transfer, queue-import, queue-export, lazy-program, bin-wrapper and the new test pass (6 files, 51 tests).
  • Whole CLI suite: 8,054 passed, 7 skipped and 1 failed. The failure is release-surface.test.ts's non-existent-ref case, which needs a git checkout ("without a repo it cannot run"), and the test copy was an archive.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Queue commands can now load and display their available actions without loading validation support during startup. Transfer requests continue to be validated when parsed, helping the command remain available even if that support cannot be loaded immediately.

…every rig queue command

The queue command module registers `queue transfer`, so its top-level zod import put zod on every
`rig queue list` and `show` start-up, which lazy-program.ts otherwise keeps to the queue command's
own imports. The schemas are now built from a dynamic import on first use, as the module already loads
@openrig/daemon/queue-transfer-records. A test loads the queue command with zod mocked to throw.
@coderabbitai

coderabbitai Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The queue transfer command now loads Zod schemas on demand and reuses them for record, receipt, and staging-response validation. A startup test checks that importing and constructing the queue command does not load Zod.

Changes: Queue transfer schema loading

Layer / File(s) Summary
Lazy schema loading and validation
packages/cli/src/commands/queue-transfer.ts, packages/cli/test/queue-command-startup.test.ts
The command dynamically loads and caches schemas for record, receipt, and staging-response validation. The startup test checks that importing and constructing the queue command does not load Zod and verifies its subcommands.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Refactor

Suggested reviewers: ezotoff, openrig-review

Merge Risk: Minimal · up to b8dd6

This change delays loading zod until a queue transfer command first parses input, so list and show commands start faster. No actionable merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: deferring zod loading until a queue transfer verb's first parse, rather than at every rig queue command. The raw summary shows queue-transfer.ts switching from a stati…
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.
Full details: Title check

Explanation

The title names the main change: deferring zod loading until a queue transfer verb's first parse, rather than at every rig queue command. The raw summary shows queue-transfer.ts switching from a static zod import to a dynamic import with cached schemas, and a startup test that mocks zod to throw. The title is specific, uses the conventional perf(cli) prefix, and fits the changeset. Its length (92 characters) is slightly long but within reason.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 361050a2-66b5-4af9-b83a-851547c0f230
Commits

Reviewing files that changed from the base of the PR and between 3fca7c3 and b8dd663.

Files selected for processing: 2

  • packages/cli/src/commands/queue-transfer.ts
  • packages/cli/test/queue-command-startup.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 4 remain after this review.

@openrig-review openrig-review left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reviewed and tested at b8dd663: rig queue list and show no longer load zod at start-up, because the transfer verbs load it at their first parse, so those reads are back to their earlier speed. Transfer validation, errors and outputs are unchanged. Approving this head so the macOS package tests run.

@mvschwarz
mvschwarz merged commit 01bfe5f into main Nov 28, 2026
17 checks passed
@mvschwarz
mvschwarz deleted the dev60review/queue-transfer-lazy-zod branch November 28, 2026 04:41
@mvschwarz mvschwarz moved this to Done in OpenRig roadmap Nov 28, 2026
@mvschwarz mvschwarz added this to the v0.7.26 milestone Nov 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants