[Hackathon] wire-compat: versioned comms layer with forward/backward …#18
[Hackathon] wire-compat: versioned comms layer with forward/backward …#18mihiragentic wants to merge 1 commit into
Conversation
…compat Problem projnanda#1 (comms): the default nest_native envelope carries no schema version, so across NEST builds a newer field is silently dropped and a breaking-major message is silently mis-decoded. This adds: - comms/versioned.py: a VersionedComms plugin that stamps an explicit SemVer schema_version + kind on every envelope, preserves unknown fields from newer-minor peers (re-emitting them on round-trip), and rejects unknown majors with a typed UnsupportedSchemaError instead of mis-decoding. - Two adversarial validators (comms_reject_unknown_major, comms_no_silent_drop) that FAIL against nest_native and PASS against versioned, encoded independently of any plugin. - A comms_versioning scenario + agents (mixed v1/v2 peers + an auditor) and scenarios/comms_versioning.yaml demonstrating it. - Property-based and end-to-end tests; deterministic under seeds 42/7/1337. make ci-local: all 5 checks pass (365 tests, 0 type errors, lint+format clean). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Reviewer's GuideAdds a new versioned communications plugin and adversarial validation scenario to enforce forward/backward-compatible wire envelopes, wires it into the plugin registry and scenarios, and tests both the plugin and validators end-to-end. Sequence diagram for the comms_versioning scenario with VersionedCommssequenceDiagram
actor PeerAgent
participant AuditorAgent
participant VersionedComms
PeerAgent->>AuditorAgent: ctx.send(_envelope v1.1)
AuditorAgent->>VersionedComms: deserialize(payload)
alt [major == SCHEMA_MAJOR]
VersionedComms-->>AuditorAgent: Message(metadata._unknown preserved)
AuditorAgent->>PeerAgent: ctx.send(ack:<id>:accepted:<preserved_fields>)
else [major > SCHEMA_MAJOR]
VersionedComms-->>AuditorAgent: UnsupportedSchemaError
AuditorAgent->>PeerAgent: ctx.send(ack:<id>:rejected_major:)
end
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="packages/nest-core/nest_core/validators.py" line_range="991" />
<code_context>
+ if len(parts) < 3:
+ continue
+ mid, status = parts[1], parts[2]
+ preserved = {f for f in parts[3].split(",") if f} if len(parts) > 3 else set[str]()
+ acks[mid] = (status, preserved)
+ return acks
</code_context>
<issue_to_address>
**issue (bug_risk):** The fallback `preserved` set uses `set[str]()` which will raise at runtime.
On Python 3.9+, `set[str]` is a `types.GenericAlias`, so calling `set[str]()` raises a `TypeError`, breaking ack parsing when the message has fewer than four segments.
Use a plain empty set for the fallback:
```python
preserved = {f for f in parts[3].split(",") if f} if len(parts) > 3 else set()
```
Since you then treat `preserved` as a regular `set[str]` of strings, this change does not affect typing in practice.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| if len(parts) < 3: | ||
| continue | ||
| mid, status = parts[1], parts[2] | ||
| preserved = {f for f in parts[3].split(",") if f} if len(parts) > 3 else set[str]() |
There was a problem hiding this comment.
issue (bug_risk): The fallback preserved set uses set[str]() which will raise at runtime.
On Python 3.9+, set[str] is a types.GenericAlias, so calling set[str]() raises a TypeError, breaking ack parsing when the message has fewer than four segments.
Use a plain empty set for the fallback:
preserved = {f for f in parts[3].split(",") if f} if len(parts) > 3 else set()Since you then treat preserved as a regular set[str] of strings, this change does not affect typing in practice.
…compat
Problem #1 (comms): the default nest_native envelope carries no schema version, so across NEST builds a newer field is silently dropped and a breaking-major message is silently mis-decoded.
This adds:
make ci-local: all 5 checks pass (365 tests, 0 type errors, lint+format clean).
Summary by Sourcery
Introduce a versioned communications plugin and scenario to enforce forward/backward wire compatibility and validate comms behaviour.
New Features:
Enhancements:
Tests: