Skip to content

feat(zap): ZAP wire v1.0 — handshake/seq/retry/FIN session layer + spec + vectors (#85) - #129

Closed
Pattermesh wants to merge 1 commit into
mainfrom
pattermesh/issue-85-zap-wire-v1
Closed

feat(zap): ZAP wire v1.0 — handshake/seq/retry/FIN session layer + spec + vectors (#85)#129
Pattermesh wants to merge 1 commit into
mainfrom
pattermesh/issue-85-zap-wire-v1

Conversation

@Pattermesh

Copy link
Copy Markdown
Collaborator

Implements ZAP wire v1.0 for #85: spec doc, pure-Python session state machine, conformance vectors, 25 TDD tests.

🤖 Generated with Claude Code

Add the connection-level ZAP wire v1.0 session semantics that sit under the
existing PaymentOffer/PaymentProof codecs. Pure-Python, no zap_py dependency.

Spec (docs/zap-wire-spec-v1.0.md): 26-byte frame header (magic 0x5A50,
wire version, frame type, flags, per-direction u32 seq, cumulative u32 ack,
u64 request_id, length-prefixed payload); HELLO/WELCOME handshake; capability
bitmask = 8 bits version + 24 bits feature flags (baseline 0x0100001F);
cumulative ACK; configurable-RTT retry with exponential backoff; request_id
idempotency/dedup; graceful FIN with orphaned-sequence handling; RST error
codes; full state machine.

Code (switchboard/zap_transport.py): SessionFrame encode/decode, capability
make/negotiate helpers, and the ZapSession state machine (handshake, in-order
+ reorder-buffered delivery, cumulative ack, retransmit queue with injectable
clock, idempotent dedup, FIN/close + incomplete-gap detection).

Tests: 25 new pure-Python tests in tests/test_zap_transport.py plus static
byte-for-byte conformance vectors in tests/protocol_vectors/zap_session.v1.json.
`python3 -m pytest tests/test_zap_transport.py -q` -> 28 passed, 36 skipped.

Does not touch x402_middleware.py, gas_*.py, or lucidly.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
FRAME_RST,
}
# Frame types that consume sequence space (spec §5).
_SEQ_CONSUMING = {FRAME_HELLO, FRAME_WELCOME, FRAME_DATA, FRAME_FIN}
@abhicris

Copy link
Copy Markdown
Contributor

Welcome to kcolbchain, @Pattermesh — glad you're here. 🌱

Here's what happens from this PR:

  1. Our automated review looks for obvious issues (tests, secrets, size) within a couple of hours.
  2. If it's clean and CI passes, we merge without back-and-forth.
  3. If we need changes, we'll leave a specific comment — not a generic nit. Push another commit and we re-review.

While you wait:

  • Run the repo's tests locally (see the repo README.md).
  • Keep the PR scoped to one concern — bigger PRs land slower.
  • Don't commit tokens or .env contents.

What happens after your first merge

Thanks for writing the code. We're building this to last.

@abhicris

abhicris commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

This issue/PR has had no activity for 21 days and is being closed automatically by the kcolbchain PR pipeline.

If it's still relevant, reopen or leave a comment and we'll re-triage. For the full policy see pipeline docs.

@abhicris abhicris closed this Aug 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants