Skip to content

feat(protocol): frame representations — full/compact/reference (CGEP phase 2)#41

Merged
macanderson merged 1 commit into
mainfrom
feat/frame-representations
Jul 22, 2026
Merged

feat(protocol): frame representations — full/compact/reference (CGEP phase 2)#41
macanderson merged 1 commit into
mainfrom
feat/frame-representations

Conversation

@macanderson

Copy link
Copy Markdown
Owner

What this is

CGEP lifecycle phase 2 — frame representations. A ContextFrame now states
how it carries its content, per the lifecycle build prompt
§"ContextFrame representations". This is the implementation the pre-shipped
witness test (contextgraph-types/tests/frame_representation_witness.rs, added
by #35) has been asserting — and failing on main for.

Representation Inline content content_ref + canonical_content_hash content_digest transform
full required optional optional absent
compact required (a transformed rendering) required required required
reference absent required absent absent

Additive and backward-compatible: representation absent ⇒ full, and
full/legacy frames are byte-identical on the wire (the field is skipped when
full). Query-only providers are untouched.

Feature surface

  • Types (contextgraph-types): Representation, ContentFidelity,
    ContentRef, Transform, InlineContentRequirement. ContextFrame.content
    Option<String> (absent for references) plus the fields above,
    canonical_content_hash, canonical_token_cost, tokenizer_ref.
    ContextFrame::{full,reference} constructors and representation_invariants().
  • Negotiation: ContextQuery.representation_preferences (+
    select_representation), Capabilities.representations + resolve (+
    representations_consistent — advertising compact/reference requires resolve).
  • Wire: JSON Schema $defs + per-representation invariants (allOf/if-then,
    which reject e.g. a reference carrying inline content); content no longer
    globally required. New examples/ messages (compact + reference frames, a
    representation-capable handshake, a query with preferences) that validate.
  • Docs: docs/protocol-surface.md representation section; ADR 0005; CHANGELOG.

The invariants are enforced in three places that agree: Rust, JSON Schema, and
tests.

Scope decision — token_cost kept required (deviation note)

The chosen scope said "token_cost → optional". I kept token_cost: u32
required
and added canonical_token_cost/tokenizer_ref additively instead.
Making token_cost optional reopens PR #33's B3 decision on the same field and
the same budget-accounting functions PR #33 rewrites
— a guaranteed conflict on
its headline. The witness passes with token_cost: 0 present, so the feature
does not need it. token_cost-optionality belongs in the B3 reconciliation (below).
Happy to flip it here instead if you'd rather.

Also unbreaks main

contextgraph-host and contextgraph-conformance did not compile on main
(a half-applied #37 merge): missing ConsentReceipt/EgressScope/FrameId/
DropReason imports, a DataFlow literal missing egress_scopes, a missing
CHECK_VERIFY_HONESTY test import, and a stale 67 check-count assertion.
Fixed here so the workspace builds — these are pre-existing and unrelated to the
feature, split out in the CHANGELOG's Fixed section.

Verification (local — see note)

cargo test --workspace                 all suites pass (incl. witness, both cases)
cargo clippy --workspace --all-targets -- -D warnings   clean
cargo fmt --all -- --check             clean
python3 schema/validate-examples.py    all examples validate

main has no CI workflows (PR #33 adds them), so this PR shows no GitHub
Actions checks — verification above is local. This does not by itself flip
PR #33's red test check: that check clears once PR #33 rebases onto this
once landed.

Rebase reconciliation for PR #33

This lands to main; PR #33 then rebases onto it. Expect these to touch the same
lines (all trivial, but flagged so nothing surprises):

Known limitation (pre-existing, not fixed here)

The schema lists provenance/relations as required, but the Rust type skips
them when empty (skip_serializing_if = "Vec::is_empty"). So a bare
ContextFrame::reference(...) serializes without them and would fail the schema;
the bundled examples pass because they include [] explicitly. This mismatch
pre-dates representations (any minimal frame hits it) — reference frames just make
it more visible. Left for a separate schema/wire-strictness pass.

…phase 2)

Extend ContextFrame so a frame states *how* it carries its content, per the CGEP
lifecycle build prompt §"ContextFrame representations". Additive and
backward-compatible: `representation` absent ⇒ `full`, and full/legacy frames are
byte-identical on the wire. Satisfies frame_representation_witness.rs (both cases).

Types (contextgraph-types):
- Representation {full|compact|reference}, ContentFidelity, ContentRef, Transform,
  InlineContentRequirement.
- ContextFrame: `content` → Option (absent for references); adds representation,
  content_fidelity, canonical_content_hash, content_ref, transform,
  minimum_content_fidelity, inline_content_requirement, canonical_token_cost,
  tokenizer_ref. `content_digest` kept as the inline-content hash (the spec's
  content_hash, which feeds FrameId); canonical_content_hash is the full-source
  hash. `full`/`reference` constructors + representation_invariants().
- Negotiation: ContextQuery.representation_preferences (+ select_representation);
  Capabilities.representations + resolve (+ representations_consistent).

token_cost kept required (u32); canonical_token_cost/tokenizer_ref added
additively. Making token_cost optional reopens PR #33's B3 budget-accounting
decision on the same field, so it is deferred to that reconciliation.

Wire + docs deliverables:
- JSON Schema: new $defs + per-representation invariants (allOf if/then); `content`
  no longer globally required.
- examples/reference-messages.json: representation-capable handshake_ack, a query
  with representation_preferences, and compact + reference frames (all validate).
- docs/protocol-surface.md representation section; docs/adr/0005; CHANGELOG.

Also unbreaks `main`: contextgraph-host and -conformance did not compile from a
half-applied #37 merge (missing ConsentReceipt/EgressScope/FrameId/DropReason
imports, a DataFlow literal missing egress_scopes, a CHECK_VERIFY_HONESTY test
import, and a stale check-count assertion). Fixed so the workspace builds and the
full suite passes.

@sourcery-ai sourcery-ai 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.

Sorry @macanderson, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@vercel

vercel Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
context-graph-protocol Ready Ready Preview, Comment Jul 22, 2026 9:57pm

@macanderson
macanderson marked this pull request as ready for review July 22, 2026 22:10
@macanderson
macanderson merged commit 2b07508 into main Jul 22, 2026
4 checks passed
@macanderson
macanderson deleted the feat/frame-representations branch July 22, 2026 22:10
macanderson added a commit that referenced this pull request Jul 22, 2026
Reconcile the pre-freeze normative sweep (#33) with frame representations
(#41, full/compact/reference) and context/verify (#38), which landed on main
after this branch forked.

Key reconciliations:
- Capabilities: keep #33's ADR-0004 removal of upsert/subscribe/filters and its
  `correlation` field; add #41's `verify`/`representations`/`resolve`.
- ContextFrame: adopt main's optional `content` + representation model
  (representation/content_ref/canonical_content_hash/…); rename #33's
  `canonical_token_cost()` method to `expected_inline_token_cost()` to free the
  name for #41's `canonical_token_cost` field, and make it handle absent content.
- wire::Envelope: keep #33's correlation `id` on query/frames and structured
  `error` (id/code) AND #41's Verify/Verified variants.
- Conformance fixture: keep #33's strict frame-building (valid F5 digests,
  F4 timestamps) so its enhanced checks pass, grafted with main's verify
  (verify_honestly/current_digest derived from the fixture's own digests).
- schema/examples: union of #33's stricter validations (timestamp/embedding
  patterns) and #41's representation $defs; drop the removed capability fields.

Verified green: cargo build/clippy -D warnings/test, schema validate-examples,
and conformance-red.sh (all 14 misbehave modes caught, integrating both #33's
and #41's). The frame-representations witness (previously #[ignore]) now passes
against main's implementation.
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.

1 participant