Skip to content

Post-1.0 code-shrink backlog (deferred from 2026-06-18 security review) #338

Description

@laulpogan

Deferred code-shrink candidates from the 2026-06-18 full security-review + shrink pass. Held until after the 1.0 soak — these touch security-critical relay/pairing hot paths, and refactoring them now would reset soak confidence on exactly the files that matter most. All are behaviour-preserving extractions; ship them once 1.0 is out.

The low-risk peripheral dedups from that pass already landed in #337 (parse_body_arg, hex_exact::<N>). The relay DoS-ceiling fixes landed in #336.

Relay (src/relay_server.rs)

  • post_event + handle_intro share identical size/quota/dedup/slot-insertion logic (~30 LOC). Extract a common post_event_internal helper. Highest care — both are on the live relay ingest path.
  • well_known_agent_card_a2a + well_known_agent share nick-parse → handle-lookup → 404 (~25 LOC). Extract the shared lookup; the two differ only in response envelope shape.

Pairing (src/pair_invite.rs)

  • send_pair_drop_ack repeats the self relay/slot/token resolution-with-fallback logic also present in maybe_consume_pair_drop and send.rs::attempt_deliver (3 sites, ~40 LOC). Centralize into one resolver. Trust-adjacent — needs the pairing integration tests as the safety net.

Trivial single-use inlines (low value, evaluate individually)

These were skipped on "no single-use abstraction" grounds; only take the ones that genuinely improve clarity:

  • agent_card::max_schema_version (~20 LOC, one caller) — simplify or inline
  • agent_card::build_agent_cardtrust::add_self_to_trust JSON object overlap (~15)
  • signing.rs [u8;32] validate+copy pattern (~15)
  • enc/wire_x25519 context_info length-prefix framing helper (~6); nonce-init pattern (~5)
  • platform.rs line-matching parse helpers (~8); read_wire_home_from_pid env-line parse (~6); parent_pid parse (~5)
  • same_machine::local_fingerprint (~5); trust::now_iso inline (~4); org_membership::keypair test helper (~4)
  • config.rs atomic-write-with-lock / lock-path helpers (~8)
  • group.rs invalidate_signature (epoch++ / sig.clear) (~2)

Context

🤖 Generated with Claude Code

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions