Skip to content

perf(core): remember peer-advert verdicts and imported verification keys - #358

Merged
Mearman merged 5 commits into
mainfrom
perf/advert-verify-memo
Oct 21, 2026
Merged

Mearman merged 5 commits into
mainfrom
perf/advert-verify-memo

Conversation

@Mearman

@Mearman Mearman commented Oct 21, 2026

Copy link
Copy Markdown
Member

A hub re-broadcasts every advert it accepts to every other client and replays the directory to each sender, so with a few dozen devices on one machine each receiver verifies the same advert many times over. A profile of a busy hub process showed verifyPeerAdvert (key import, two digests, signature check) and its CBOR encoding dominating its non-idle time; see ExaDev/agent-comms#434.

The verdict for a given signature over given signed bytes cannot change, so verifyPeerAdvert now keeps it in a byte-budgeted LRU held per verifier object. A repeat of an advert already judged costs one encoding. A refusal is kept too; a check that threw is not, since the same bytes may verify on a retry. The node identity adapter also keeps the imported verification key per device, so a new advert from a known device does not re-import its key.

The tests count checks run through a counting verifier rather than timing anything: the same advert re-sent repeatedly, a hub fed repeated gossip from several peers, and a session replayed the same directory, each checked once per distinct advert. With the memo and key cache disabled six of them fail.

Refs ExaDev/agent-comms#434

A hub re-broadcasts every advert it accepts to every other client and
replays the directory to each sender, so one advert reaches a receiver
many times and a mesh of N devices re-verifies each advert on the order
of N times per receiver. Each check derived a device id, imported the
public key and verified the signature, all from scratch.

The verdict for a signature over given signed bytes is a pure function
of those bytes, so verifyPeerAdvert now remembers it in a byte-budgeted
least-recently-used memo held per verifier. Only a verdict the checks
reached is kept, a refusal included; a check that threw is retried.
The node identity adapter keeps the imported verification key per
device so a first sight of a new advert does not re-import a known key.
@Mearman
Mearman marked this pull request as ready for review October 21, 2026 06:36
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
🔒 Security Review ⚠️ Failed 2026-10-21T12:25:12.435040Z
We couldn’t complete this review. Comment @codex security review to try again.
9107178 Manual request

Security findings

Finding details are still loading. Check the individual review comments.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@Mearman

Mearman commented Oct 21, 2026

Copy link
Copy Markdown
Member Author

@codex security review

1 similar comment
@Mearman

Mearman commented Oct 21, 2026

Copy link
Copy Markdown
Member Author

@codex security review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🛡️ Codex Security Review

Here are some automated security review suggestions for this pull request.

Reviewed commit: 1702fa9182

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

Comment thread ts/packages/core/src/domain/peer-advert.ts Outdated
The cache key was built from the signature and signed bytes before the
budget was checked, so a peer sending a frame near the relay's size limit
made the verifier copy it into a string of the same size before the
signature was ever judged.

The cache now takes the byte parts and works out the key's length from
their lengths alone. An input whose key would exceed the budget is
verified directly and never keyed.
@Mearman

Mearman commented Oct 21, 2026

Copy link
Copy Markdown
Member Author

@codex security review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🛡️ Codex Security Review

Here are some automated security review suggestions for this pull request.

Reviewed commit: dd7fb569ea

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

Comment thread ts/packages/core/src/adapters/node-identity.ts
The imported-key cache id is the key's bytes as a string, built before the
key was checked, so a gossiped advert carrying a key near the frame limit
was copied and encoded in full only to be refused by the import.

A key of the wrong size for its algorithm can never import, so it is now
refused before the id is built, along with an algorithm no verifier here
implements.
@Mearman

Mearman commented Oct 21, 2026

Copy link
Copy Markdown
Member Author

@codex security review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🛡️ Codex Security Review

Here are some automated security review suggestions for this pull request.

Reviewed commit: 256e690abb

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

Comment thread ts/packages/core/src/domain/verdict-cache.ts Outdated
…dget

An entry evicted while its verdict was pending left the map but not memory:
the computation kept its key string until it settled. A peer splitting one
large gossip frame into many adverts, each within the size limit, could hold
a key for every one of them at once.

Keys of unsettled verdicts are now charged to the budget, and an input that
would overflow it is verified directly instead of being keyed.
@Mearman

Mearman commented Oct 21, 2026

Copy link
Copy Markdown
Member Author

@codex security review

@chatgpt-codex-connector

Copy link
Copy Markdown

This security review couldn’t start because the paying account has exhausted its Codex allowance and has insufficient available credits. The payer can check their balance and add credits in the Codex usage dashboard, then try again. If you do not manage the paying account, contact this repository's admins.

@Mearman
Mearman merged commit d9d0b8a into main Oct 21, 2026
16 of 18 checks passed
@Mearman
Mearman deleted the perf/advert-verify-memo branch October 21, 2026 12:30
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 4.0.6 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant