Skip to content

perf(cli): load the conversation key only for the queue verbs that use it - #4211

Open
mvschwarz wants to merge 1 commit into
mainfrom
perf/cli-read-imports
Open

mvschwarz wants to merge 1 commit into
mainfrom
perf/cli-read-imports

Conversation

@mvschwarz

@mvschwarz mvschwarz commented Nov 30, 2026 •

Copy link
Copy Markdown
Owner

The problem

Everyday rig queue list and rig queue show became slower than in 0.7.26, by about 5% of a read's time on the reads measured. The cost is in the CLI process, not the daemon.

For one queue list --json, the CLI on main opens four more modules than 0.7.26's. One module it already loaded also grew:

  • @openrig/daemon/conversation-key: this re-exports from the openrig plugin's hook bridge script, assets/claude-hook-bridge.cjs.
    • That script is about 60 KB of CommonJS (49,659 B in 0.7.26, 58,972 B now). When an ES module imports it, Node reads the whole file for its named exports at every load, before compiling it.
    • It now also brings issued-conversation-address.
    • Importing this surface alone in a fresh process took a median 12.7 ms on 0.7.26's package and 20.1 ms on a later one (30 runs each).
  • rig queue list and rig queue show never use it. Only rig queue create uses it, to record a conversation's key with --return-route auto, and the two handoff verbs use it to drop a given key. It was imported at the top of commands/queue.ts, so every queue command paid for it.

What changes

How it was checked

  • Red first: at main, the start-up test fails with "the conversation key was loaded with the queue command module". With the change, it passes.

  • Tests: every CLI queue* test file, plus the MCP queue, lazy program, bin wrapper and daemon start tests: 32 files, 820 passed, 1 skipped. npm run lint passed.

  • Measurement. Three CLIs were installed side by side in one home against one daemon, on a shared 4-core Linux box (load 2.3-2.8), with Node 22.23.4:

    • published 0.7.26 (A);
    • main as packed (M);
    • main with this change (F).

    Each command ran 100 rounds per CLI, the order rotating each round, and every exit was 0. Medians, with child CPU time (user + sys) from wait4 first and wall time second:

Read M/A F/A F−M
queue list --json 1.050 / 1.034 0.939 / 0.974 −40.5 / −15.3 ms
queue show <id> --full --json 0.979 / 1.011 0.918 / 0.986 −26.8 / −7.8 ms
view show escalations --json 1.008 / 1.015 1.012 / 1.037 +1.6 / +5.3 ms (noise; the same modules load)
--version 0.992 / 0.994 1.009 / 1.020 +3.0 / +3.9 ms (noise)

An earlier run on the same box gave F−M of −39.9 / −19.9 ms for queue list and −32.1 / −12.4 ms for queue show. With this change, queue list and queue show load fewer modules than 0.7.26 did, because 0.7.26 loaded the hook bridge for them too.

Limits

  • Measured on one Linux box under shared load, in sittings of 100 rounds. These are medians with wide spreads, not a controlled benchmark. Child CPU time is the steadier signal here, and wall time follows it.
  • A smaller addition is left as it is. daemon-lifecycle now also imports @openrig/daemon/bind-plan, which brings the bearer-token middleware. Every read command loads that (three files, about 13 KB). Its cost didn't show above noise on view show.
    • Moving it into the daemon start path would change that path's timing, and it made one fake-timer start test hang.
  • rig send also imports the conversation key at start-up (isIssuedConversationAddress, since fix(delivery): give issued conversations a queue reply hint #4141). It isn't a queue read and isn't changed here.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Improvements
    • The queue command now loads conversation-key support only when needed, helping keep command startup lightweight.
    • Create and handoff operations continue to filter and deduplicate tags as before.

…e it

`rig queue list` and `rig queue show` loaded @openrig/daemon/conversation-key at
start-up. That module is the openrig plugin's hook bridge script, about 60 KB of
CommonJS that Node reads for its named exports at every load, and it has grown
since the queue reads were last made fast. Only `rig queue create` (recording a
conversation's key with --return-route auto) and the two handoff verbs (dropping
a given key) use it, so they now load it when they run.

The queue command's start-up test now refuses that module at start-up, as it
already refuses zod.
@coderabbitai

coderabbitai Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The queue command now dynamically loads conversation-key utilities during create and handoff tag processing. A startup test checks that importing and constructing the command does not load those utilities.

Changes: Queue conversation-key loading

Layer / File(s) Summary
Lazy loading and tag filtering
packages/cli/src/commands/queue.ts, packages/cli/test/queue-command-startup.test.ts
The create and handoff paths load conversation-key utilities when needed and pass the prefix to the tag filter. The startup test checks that the conversation-key module and zod remain unloaded while the queue command is imported and constructed.

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

Change: Refactor

Suggested reviewers: openrig-review, ezotoff

Merge Risk: Minimal · up to c2bb1

This change defers loading conversation-key utilities until the queue create and handoff actions need them, which speeds up the startup of other queue commands. No actionable merge risk remains.

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: the conversation-key module is now loaded only for the queue verbs that use it, and the change is a performance improvement. The raw summary, objectives, and startup t…
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: the conversation-key module is now loaded only for the queue verbs that use it, and the change is a performance improvement. The raw summary, objectives, and startup test all match this scope. The title uses the conventional commit prefix and stays under one line.

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: c5bd682c-10bb-414b-9cf2-b9ecb0f5c1f4
Commits

Reviewing files that changed from the base of the PR and between 7a3094e and c2bb161.

Files selected for processing: 2

  • packages/cli/src/commands/queue.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; 2 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.

Approving the reviewed head c2bb161 to start the macOS package tests. rig queue list and rig queue show no longer load the conversation key, the openrig plugin's hook bridge script, at start-up. Only rig queue create and the two handoff verbs load it, when they run. The queue command's start-up test now fails if that module loads with the command, as it already does for zod.

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.

2 participants