Skip to content

[codex] Fix SWM Sender Key setup after joined CG approval#900

Merged
branarakic merged 20 commits into
mainfrom
codex/fix-joined-cg-swm-sender-key
Jun 1, 2026
Merged

[codex] Fix SWM Sender Key setup after joined CG approval#900
branarakic merged 20 commits into
mainfrom
codex/fix-joined-cg-swm-sender-key

Conversation

@Jurij89
Copy link
Copy Markdown
Contributor

@Jurij89 Jurij89 commented Jun 1, 2026

Summary

  • Addresses PR [codex] Fix SWM Sender Key setup after joined CG approval #900 review feedback on SWM Sender Key setup retry semantics for joined/private context graphs.
  • Adds a backward-compatible structured reasonCode field to SwmSenderKeyPackageAck so receiver-side rejection classes are machine-readable while reason remains operator-facing text.
  • Uses structured receiver errors (SwmSenderKeySetupRejectionError plus the existing StaleSenderKeyTargetError) rather than parsing human-readable error strings to populate ACK reason codes.
  • Keeps delivered negative Sender Key setup ACKs hard. In particular, reasonCode: stale-target is not soft-queued, because the original package targets an obsolete recipientKeyId and resending the same bytes cannot recover. A future soft path would need to re-resolve and rebuild the package against a current recipient key.
  • Preserves pending Sender Key retry for cases where no application-level rejection was delivered: no advertised peer ID and transport-level queued/offline delivery. Those queued packages are retried on connection:open and during later publishes when recipient resolution now supplies a peer ID.
  • Extracts the pending-drain send/ACK/removal bookkeeping into a shared helper used by both reconnect and publish-time drains. Only accepted=true ACKs count as successfully drained; hard rejections and malformed/legacy ACKs are terminal for that queued package but are not reported as successful drains.

Related

Files changed

File What
packages/core/src/proto/swm-sender-key.ts Adds the optional ACK reasonCode protobuf field and exported TypeScript union for structured Sender Key setup rejection reasons.
packages/core/src/proto/index.ts Re-exports the ACK reason-code type.
packages/core/test/swm-sender-key-proto.test.ts Pins ACK reasonCode encode/decode roundtrip behavior.
packages/agent/src/dkg-agent.ts Emits structured ACK reason codes from receiver-side errors; keeps delivered negative ACKs hard; retries only no-peer/transport-queued pending setup packages on reconnect or later publish; shares pending-drain bookkeeping across both retry triggers.
packages/agent/test/swm-sender-key-pending-by-agent.test.ts Adds regression coverage for later-publish drain, fatal stale-target/auth/key/unknown delivered ACKs, hard rejection drain semantics, malformed ACK drain semantics, reconnect drain, and pending epoch supersession.

Test plan

  • Ran TypeScript build for the affected package graph:

    node node_modules/typescript/bin/tsc -b packages/core packages/storage packages/query packages/publisher packages/chain packages/random-sampling packages/agent
  • Ran core Sender Key protobuf tests:

    node node_modules/vitest/vitest.mjs run --reporter verbose test/swm-sender-key-proto.test.ts

    Result: 1 passed, 3 passed.

  • Ran focused agent Sender Key pending/fanout tests with the temporary no-global-setup config:

    node node_modules/vitest/vitest.mjs run --config $env:TEMP\vitest-dkg-agent-swm.config.mjs --reporter verbose test/swm-sender-key-pending-by-agent.test.ts test/swm-sender-key-parallel-fanout.test.ts

    Latest result: 2 passed, 16 passed.

  • Ran git diff --check.

Verification notes and constraints

  • The normal package install path in this Windows worktree remains blocked by @cyfrin/aderyn postinstall rejecting Windows_NT; dependency linking was already sufficient for direct package binaries, so verification used those binaries directly.
  • The default packages/agent Vitest config invokes chain global setup. These Sender Key tests do not need chain state, so the focused run used the temporary no-global-setup config already used for this PR.

Risk

Medium. This changes the ACK wire schema in a backward-compatible way by appending an optional string field and tightens delivered rejection handling compared with the first draft. Older peers that do not send reasonCode continue to produce hard delivered rejections. Pending retry remains limited to no-peer and transport-queued setup packages, where the original package can still become deliverable once a peer ID or connection becomes available.

@Jurij89 Jurij89 marked this pull request as ready for review June 1, 2026 16:06
Comment thread packages/agent/src/dkg-agent.ts Outdated
Comment thread packages/agent/src/dkg-agent.ts Outdated
Comment thread packages/agent/src/dkg-agent.ts Outdated
Comment thread packages/agent/src/dkg-agent.ts
Comment thread packages/agent/src/dkg-agent.ts Outdated
Comment thread packages/agent/src/dkg-agent.ts Outdated
Comment thread packages/agent/src/dkg-agent.ts Outdated
Comment thread packages/agent/src/dkg-agent.ts Outdated
Comment thread packages/core/src/proto/swm-sender-key.ts Outdated
Comment thread packages/agent/src/dkg-agent.ts
Comment thread packages/agent/src/dkg-agent.ts Outdated
Comment thread packages/agent/src/dkg-agent.ts Outdated
Comment thread packages/agent/src/dkg-agent.ts Outdated
Comment thread packages/core/src/proto/swm-sender-key.ts
Comment thread packages/agent/src/dkg-agent.ts
Comment thread packages/agent/src/dkg-agent.ts Outdated
Comment thread packages/agent/src/dkg-agent.ts Outdated
Comment thread packages/agent/src/dkg-agent.ts
Comment thread packages/agent/src/dkg-agent.ts Outdated
Comment thread packages/agent/src/dkg-agent.ts
Comment thread packages/agent/src/dkg-agent-swm-state.ts
Comment thread packages/agent/src/dkg-agent.ts Outdated
Comment thread packages/agent/src/dkg-agent.ts
Comment thread packages/agent/src/dkg-agent.ts
Comment thread packages/agent/src/dkg-agent.ts Outdated
Comment thread packages/agent/src/dkg-agent.ts Outdated
Comment thread packages/agent/src/dkg-agent.ts
Comment thread packages/agent/src/dkg-agent.ts Outdated
Comment thread packages/agent/src/dkg-agent.ts
Comment thread packages/agent/src/dkg-agent.ts Outdated
Comment thread packages/agent/src/dkg-agent.ts Outdated
Comment thread packages/agent/src/dkg-agent.ts
Comment thread packages/agent/src/dkg-agent.ts
Comment thread packages/agent/src/dkg-agent.ts
Comment thread packages/agent/src/dkg-agent.ts Outdated
Comment thread packages/agent/src/dkg-agent.ts
Comment thread packages/agent/src/dkg-agent.ts
Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

Codex review completed — no issues found.

@branarakic branarakic merged commit 19c1f15 into main Jun 1, 2026
38 of 40 checks passed
@branarakic branarakic mentioned this pull request Jun 2, 2026
3 tasks
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