Skip to content

perf(cli): rig send checks an issued sender without the hook bridge or, for a seat, the database - #4213

Merged
mvschwarz merged 2 commits into
mainfrom
perf/send-start-cost
Nov 30, 2026
Merged

mvschwarz merged 2 commits into
mainfrom
perf/send-start-cost

Conversation

@mvschwarz

@mvschwarz mvschwarz commented Nov 30, 2026 •

Copy link
Copy Markdown
Owner

The problem

Every rig send that isn't --raw asks whether its sender is a conversation OpenRig issued an address to, for its reply hint (#4141). Since then, rig send costs more to start than it did in 0.7.26. Agents send all the time, so this matters. It comes from two things:

  • The import. The check, isIssuedConversationAddress, came through @openrig/daemon/conversation-key. Evaluating that surface also evaluates the openrig plugin's hook bridge script beside it: about 60 KB of CommonJS that Node reads for its named exports at every load.
    • In a fresh process, importing the surface took a median 21.8 ms, against 2.7 ms for the check's own module (30 runs each).
  • The database. Each send opened the local database read-only to run the check's one-row query: a config read, daemon.json, loading better-sqlite3, the open, the query and the close.
    • That took a median 15.0 ms in a fresh process, after the imports.

What changes

  • A surface of its own: @openrig/daemon/issued-conversation-address exports only hasIssuedAddressShape and isIssuedConversationAddress. rig send imports it, and the conversation-key surface no longer re-exports the check, since send was its only user. The check is still implemented once.
  • No database for a seat: every issued address has one shape, conversation-<12 hex>@kernel, from issuedReturnAddress. A route carried from another host keeps it with that host after it (…@kernel@<host>). So isIssuedConversationSender returns false, without opening the database, for a sender with neither shape, which nearly always means a seat.
    • A host-qualified issued address is checked against the database as before. A forwarded route keeps its host and its basis on the receiving host, and rig send's SSH relay names its sender there by that same origin. So an issued conversation that sends across hosts keeps its reply hint.
    • One definition of the format: issuedReturnAddress now lives beside the shape in domain/issued-conversation-address.ts and is still re-exported from return-route.ts. The prefix, the rig and the hash length are each written once. A rig send process already loads node:crypto, so this adds nothing to its start.
    • A test ties 500 generated addresses, alone and carried from another host, to the shape.
  • What send does is unchanged. An issued sender still gets the hint, and every other sender still doesn't, apart from the case under Limits.

How it was checked

  • Red first, at main:
    • the new start-up test fails with "rig send loaded the conversation key";
    • the sender tests fail because isIssuedConversationSender isn't exported (TypeError);
    • the shape test can't find the new surface.
  • Red, at this PR's first head, for the host-qualified case: the sender test's carried cases read false ("conversation-3f2a9c1b7e44@kernel@host-a (issued): expected false to be true"), and it opened the database twice for four senders with the shape; the shape test refused an address carried from another host.
  • Green: daemon: 20 files (issued addresses, return routes, conversation keys, the session transport, and every test that records a route's basis), 1,113 passed; CLI: 11 files (every send* file, the MCP server and network-request files, the lazy program, the bin wrapper and the queue start-up), 332 passed. 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.1-2.5), with Node 22.23.4: published 0.7.26 (A), main as packed (M) and main with this change (F). Each sent 100 rounds of a non-raw rig send from a sender session to a seat that doesn't exist, the order rotating each round. This was measured at the first head. The later change doesn't touch a seat's path: a seat's name still fails the shape before any database read.
A M F
Child CPU, median 387.5 ms 430.4 ms (M/A 1.111) 396.4 ms (F/A 1.023, F−M −34.0)
Wall, median 310.4 ms 331.1 ms (M/A 1.066) 317.3 ms (F/A 1.022, F−M −13.8)
JS files opened (strace) 134 155, the hook bridge and the database included 139, neither
  • What F still opens beyond A: the check's small surface and module, and daemon-lifecycle's bind-plan import (three files), which every read command has loaded since an earlier change. Its CPU spread overlaps A's.

Limits

  • An issued route renamed by a queue transfer. An authorized queue transfer can map an issued route to another name and keep its basis. rig send doesn't recognize a sender by that name as issued: only a database read could, and that read is the cost this removes from every seat's send. Such a sender gets the ordinary reply hint ("Reply: rig send …", or "has no session"), not the queue one. Delivery is unchanged.
  • One shared Linux box, 100 rounds per CLI, as medians with wide spreads. This isn't a controlled benchmark.
  • An issued sender (a person's own conversation sending with rig send) still opens the database, as it must to answer.
  • The bind-plan import in daemon-lifecycle is left as it is here, as it was in perf(cli): load the conversation key only for the queue verbs that use it #4211.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Issued conversation addresses now follow a consistent format and can include a host component. The address format is recognized across supported workflows.
  • Bug Fixes
    • The send command now checks whether a sender matches the issued-address format before checking local conversation records. Invalid or unmatched senders are treated as not issued, and database lookup failures are handled safely.

…r, for a seat, the database

Every `rig send` that isn't --raw asks whether its sender is a conversation
OpenRig issued an address to, for its reply hint. That cost two things the send
path didn't have before:

- The check came through @openrig/daemon/conversation-key, so importing it
  evaluated the hook bridge script beside it (about 60 KB of CommonJS that Node
  reads for its exports at every load). The check now has its own surface,
  @openrig/daemon/issued-conversation-address, which brings only the check, and
  the conversation-key surface no longer re-exports it.
- Each send opened the local database read-only (loading better-sqlite3) to run
  the one-row query. Every issued address has one shape, conversation-<hash>@kernel,
  so a sender without it (a seat, nearly always) is answered without opening the
  database. The shape is built from the same constants issuedReturnAddress uses,
  and a test ties the two together.

What send does is unchanged: an issued sender still gets the hint, and anything
else still doesn't.
@coderabbitai

coderabbitai Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The daemon now exposes issued conversation address helpers through a package subpath. The CLI uses the shape check to reject non-matching senders before opening the local database. Tests cover address generation, sender lookup, database handling, and command startup.

Changes: Issued address validation

Layer / File(s) Summary
Define the issued-address contract
packages/daemon/src/domain/issued-conversation-address.ts, packages/daemon/src/domain/return-route.ts, packages/daemon/src/issued-conversation-address-surface.ts, packages/daemon/src/conversation-key-surface.ts, packages/daemon/package.json, packages/daemon/test/issued-conversation-address-shape.test.ts
The daemon defines deterministic issued-address generation and a shape check for addresses with 12 lowercase hexadecimal characters, optionally followed by a host component. Return-route generation re-exports the shared generator and rig constant. The daemon exports the address checks through a package subpath. Tests cover generated, forwarded, and malformed addresses.
Filter senders before database lookup
packages/cli/src/commands/send.ts, packages/cli/test/send-command-startup.test.ts, packages/cli/test/send-issued-sender.test.ts
The CLI exports isIssuedConversationSender and rejects absent or non-matching senders before opening the database. Tests cover issued route bases, unmatched routes, database closure and open failures, and command startup.

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

Change: Refactor

Suggested reviewers: openrig-review, ezotoff

Merge Risk: Minimal · up to 21492

This change reduces startup work for non-raw sends by skipping the database check for senders that cannot be issued addresses. Senders that match the issued-address shape still go through the database lookup, so reply hints are preserved. No merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: rig send checks an issued sender without loading the hook bridge, and for a seat sender it skips the database. The raw summary and objectives match this. The title fol…
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.
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Full details: Title check

Explanation

The title names the main change: rig send checks an issued sender without loading the hook bridge, and for a seat sender it skips the database. The raw summary and objectives match this. The title follows the perf(cli) convention and is specific, though it is long at 96 characters.

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: 3baba63c-bc23-4fd3-a5bf-3ef7b40a78fb
Commits

Reviewing files that changed from the base of the PR and between ca33d55 and 2149251.

Files selected for processing: 5

  • packages/cli/src/commands/send.ts
  • packages/cli/test/send-issued-sender.test.ts
  • packages/daemon/src/domain/issued-conversation-address.ts
  • packages/daemon/src/domain/return-route.ts
  • packages/daemon/test/issued-conversation-address-shape.test.ts
Files skipped from review as they are similar to previous changes: 1

  • packages/cli/src/commands/send.ts

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

@mvschwarz mvschwarz moved this to In Progress in OpenRig roadmap Nov 30, 2026
…abase check

A forwarded route keeps its host and its issued basis on the receiving
host, and rig send's SSH relay names its sender there by that same
origin (conversation-<hash>@kernel@<host>). The shape now takes that
optional host part, so such a sender is still checked against the
database and keeps its reply hint. A seat's name still fails the shape
before any read.

issuedReturnAddress moves beside the shape in
domain/issued-conversation-address.ts and stays re-exported from
return-route.ts, so the address format is written once.

The sender tests now query real recorded rows: an issued address under
either basis, alone and carried from another host, is recognized, and
an unrecorded look-alike isn't.

@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 2149251 to start the macOS package tests. rig send's check for whether its sender is a conversation OpenRig issued an address to now comes through its own small package export, @openrig/daemon/issued-conversation-address, instead of the surface that also loads the hook bridge script. A sender without an issued address's shape (conversation-@kernel, optionally carried from another host) is answered without opening the local database, so a seat's send opens neither. An issued sender, including one carried from another host, is still checked against the database and keeps its reply hint. What send delivers is unchanged.

@mvschwarz
mvschwarz merged commit e865462 into main Nov 30, 2026
17 checks passed
@mvschwarz
mvschwarz deleted the perf/send-start-cost branch November 30, 2026 11:35
@github-project-automation github-project-automation Bot moved this from In Progress to Done in OpenRig roadmap Nov 30, 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