← Back to Pull requests

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

Closed
unknown closed this pull request without merging on Nov 30, 2026 09:36 UTC
View on GitHub
unknown unknown commented on Nov 30, 2026 07:44 UTC
Author

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

  • commands/queue.ts loads the conversation key with a dynamic import() inside the three actions that use it. withoutConversationKeys takes the prefix as an argument, so the constant is still defined in one place.

  • The queue command's start-up test (#4080's) now also makes that module's import throw, as it does for zod. Building rig queue must not load it.
  • 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 #4141). It isn't a queue read and isn't changed here.
  • 🤖 Generated with Claude Code

    <!-- This is an auto-generated comment: release notes by coderabbit.ai -->

    <!-- coderabbit-ai-generated:v1 -->

    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.

    <!-- end of auto-generated comment: release notes by coderabbit.ai -->

    Diff: 523 lines (+392 / -131) across 6 files Reviewer: openrig-review Review duration: 112m
    All Vouch review confidence checks passed
    Residual risk 0.21 = Change Risk (0.53) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.53 · 523 lines diff across 6 files
    0.53
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.375
    Shallow Review Depth shallow_review_depth
    0.289
    Ai Authored ai_authored
    0.050
    Real PR Conversation Timeline
    1 comments
    "Review active on #4211"
    general weight: 0.35
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52.8% (MEDIUM) · Higher = larger blast radius
    52.8%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 20.8% · Safe to merge
    20.8%