Skip to content

Compact fragment header (1-char codec tag) - #71

Merged
baanish merged 3 commits into
mainfrom
codex/compact-header
Jun 19, 2026
Merged

Compact fragment header (1-char codec tag)#71
baanish merged 3 commits into
mainfrom
codex/compact-header

Conversation

@baanish

@baanish baanish commented Jun 19, 2026

Copy link
Copy Markdown
Owner

Summary

Collapses the legacy fragment header agent-render=v1.<codec>.<dictVersion>. (~22 chars) into a single URL-unreserved tag char that encodes (wire version, codec, dictVersion). This is the improvement the wire-format research flagged as larger than arx3's own visible-char advantage — and unlike arx3 it helps every codec and every metric (visible and transport). Stacked on #70.

Wire format

Legacy Compact
deflate #agent-render=v1.deflate.<payload> #d<payload>
arx3 #agent-render=v1.arx3.1.<baseBMP> #c<baseBMP>

Tag table: p/l/d = plain/lz/deflate; a/b/c = arx/arx2/arx3 (dictVersion 1 implied). The payload stays self-describing (base64url B., baseBMP U+FFF0 marker, base76 length prefix), so the alphabet isn't in the header.

Back-compat (no migration)

Decode branches on whether the fragment starts with agent-render=: if so, the legacy parser runs unchanged; otherwise char 0 is the codec tag. This is collision-free — no compact fragment can begin with agent-render= because the wire alphabets never contain =. So every existing shared link keeps decoding, and new links are compact.

Savings

The entire header (~18–23 chars depending on codec) per fragment — a fixed win that dominates short URLs (the common case: a small snippet's header was a large fraction of the URL).

Tests

tests/compact-header.test.ts pins the tag table (characterization), round-trip across all six codecs, legacy back-compat decode, and the savings. Existing codec/fragment/link-creator tests updated to the compact format; the legacy decode path stays covered by the back-compat test and the existing legacy-fragment decode tests. Regenerated the precomputed homepage sample links to compact and updated the URL-explainer / viewer format references.

npm run check green (lint + 224 tests + bench + typecheck + build + budgets; homepage 107.5 / 115 KiB).

Follow-ups (not in this PR)

  • scripts/bench-codecs.mjs still measures the legacy header overhead in its visible-char totals (it reimplements encoding independently; the codec comparison is unaffected). Worth refreshing to the compact header in a separate pass.
  • Playwright visual snapshots for the URL-explainer / "Protocol shape" copy may need a --update-snapshots run (e2e isn't part of npm run check).

🤖 Generated with Claude Code

…<codec>.<dictVer>.

Replaces the ~22-char legacy fragment header with a single URL-unreserved tag char
that encodes (wire version, codec, dictVersion); arx-family tags imply dictVersion 1.
The payload stays self-describing (base64url B. prefix, baseBMP U+FFF0 marker, base76
length prefix), so the alphabet is not encoded in the header.

- Encode emits the compact form for every codec (e.g. `d<payload>`, `c<baseBMP>`).
- Decode reads both: a fragment starting with `agent-render=` uses the legacy parser
  unchanged; otherwise char 0 is the codec tag. Collision-free, since the wire
  alphabets never contain `=`, so existing shared links keep decoding.
- Saves the entire header (~18-23 chars) per fragment, which dominates short URLs
  (the common case) — the win the wire-format research found larger than arx3's own
  visible-char advantage.

Regenerated the precomputed homepage sample links to the compact form and updated the
URL-explainer / viewer format references. Pinned by tests/compact-header.test.ts (tag
table, round-trip across all codecs, legacy back-compat, savings).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 67411daa-9ccd-4ee4-a8e5-e1fdc652f76e

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/compact-header

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jun 19, 2026

Copy link
Copy Markdown

Deploying agent-render with  Cloudflare Pages  Cloudflare Pages

Latest commit: 1ff15e7
Status: ✅  Deploy successful!
Preview URL: https://66666d37.agent-render.pages.dev
Branch Preview URL: https://codex-compact-header.agent-render.pages.dev

View logs

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c898d1f356

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

const payloadEnvelope = { ...envelope, codec };
const json = JSON.stringify(packed ? packEnvelope(payloadEnvelope) : payloadEnvelope);
const value = `${PAYLOAD_FRAGMENT_KEY}=v1.${codec}.${encodePayload(json, codec)}`;
const value = `${compactTagForCodec(codec)}${encodePayload(json, codec)}`;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Update e2e expectations for compact links

Because buildFragment now emits #p/#l/#d... bodies instead of #agent-render=..., the homepage link-creator E2E still asserts the generated textarea and copied value contain #agent-render= (tests/e2e/viewer.spec.ts:65-71). That test is part of npm run test:ci via package.json:32-34, so the CI path fails once the flow reaches link generation; update the Playwright expectations to accept the compact tag format.

Useful? React with 👍 / 👎.

Comment thread src/lib/payload/schema.ts
Comment on lines +17 to +21
export const compactCodecTags = {
plain: "p",
lz: "l",
deflate: "d",
arx: "a",

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Keep public protocol docs in sync

This tag table changes the public fragment contract to compact #<tag><payload> links, but the docs and agent skill that the homepage points users to still document only the legacy #agent-render=v1... shapes (docs/payload-format.md:11-15, docs/url-fragments.md:22-30, skills/agent-render-linking/SKILL.md:27-31). Users and OpenClaw agents following those files will see stale guidance and keep producing legacy links despite the UI/link creator emitting compact-only links, so update the public docs/skill alongside the protocol change.

Useful? React with 👍 / 👎.

@greptile-apps

greptile-apps Bot commented Jun 19, 2026

Copy link
Copy Markdown

Greptile Summary

This PR replaces the 18–23 character legacy agent-render=v1.<codec>.<dictVersion>. fragment header with a single URL-unreserved tag character that encodes (wire version, codec, dictVersion). Back-compat is maintained by branching on the agent-render= prefix, keeping all existing shared links decodable while all newly emitted links use the compact form.

  • Schema (schema.ts): adds compactCodecTags map (p/l/d/a/b/c) and two helper functions; the tag table is pinned by a characterization test in compact-header.test.ts.
  • Encode/decode (fragment.ts, fragment-arx.ts): buildFragment now prefixes with the tag char; parseFragmentHeader dispatches to the legacy or compact path; the existing splitArxFragmentRemainder versioning fallback in the ARX path handles both formats without changes.
  • Docs/skills/samples: all updated to the compact shape; AGENTS.md omits arx3 (tag c) from its codec lists (see inline comments).

Confidence Score: 5/5

Safe to merge; the compact header change is well-isolated and all existing shared links continue to decode correctly via the legacy branch.

The encode/decode logic is straightforward and thoroughly covered by the new characterization and round-trip tests. Legacy back-compat is gated on the literal agent-render= prefix, which is unambiguous from the compact tag alphabet. The only gap is a missing arx3 entry in AGENTS.md, which affects documentation consistency but not runtime behavior.

AGENTS.md — the arx3 codec and its c tag are absent from both the product-contract and payload-protocol sections.

Important Files Changed

Filename Overview
src/lib/payload/fragment.ts Core encode/decode logic updated with compact header; back-compat branch for legacy agent-render= fragments is clean and the disambiguation is correctly positional
src/lib/payload/schema.ts Adds compactCodecTags map and compactTagForCodec/codecForCompactTag helpers; tag table is correct and fully pinned by the characterization test
src/lib/payload/fragment-arx.ts ARX candidate builders now emit compact #a/b/c prefix; splitArxFragmentRemainder versioning logic unchanged and handles both compact and legacy payloads correctly
src/lib/payload/link-creator.ts JSDoc updated to reflect compact hash format; getFragmentCodec handles both legacy and compact headers; no issues
tests/compact-header.test.ts New test file: pins the tag table as a characterization test, round-trips all 6 codecs, verifies legacy back-compat decode, and measures header savings
AGENTS.md Updated for compact header format, but arx3 (tag c) is absent from the codec tag list and codec enumeration in both the product-contract and payload-protocol sections
docs/payload-format.md Correctly updated to compact fragment shape including all six tags (p/l/d/a/b/c)
skills/agent-render-linking/SKILL.md Correctly updated with compact fragment shape including all six tags and arx3 description
src/components/home/sample-link-data.ts Precomputed sample links regenerated to compact format; arx showcase uses #c (arx3)

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["Fragment received\n#hash"] --> B{starts with\nagent-render=?}
    B -- yes --> C["Legacy parser\nparseLegacyFragmentHeader"]
    C --> D["Extract version, codec, encoded\nfrom v1.<codec>.<payload>"]
    B -- no --> E["Compact parser\nfragment[0] = tag char"]
    E --> F["codecForCompactTag(tag)\np→plain l→lz d→deflate\na→arx b→arx2 c→arx3"]
    F -- unknown tag --> G["❌ invalid-format error"]
    F -- known tag --> H["encoded = fragment.slice(1)"]
    D --> I{arx family?}
    H --> I
    I -- no --> J["Sync decode\n(plain / lz / deflate)"]
    I -- yes --> K["Async decode\ndecodeArxFragmentPayload"]
    K --> L["splitArxFragmentRemainder\n(handles legacy dictVersion prefix)"]
    J --> M["JSON.parse → envelope validation"]
    L --> M
    M --> N["✅ ParsedPayload"]
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
    A["Fragment received\n#hash"] --> B{starts with\nagent-render=?}
    B -- yes --> C["Legacy parser\nparseLegacyFragmentHeader"]
    C --> D["Extract version, codec, encoded\nfrom v1.<codec>.<payload>"]
    B -- no --> E["Compact parser\nfragment[0] = tag char"]
    E --> F["codecForCompactTag(tag)\np→plain l→lz d→deflate\na→arx b→arx2 c→arx3"]
    F -- unknown tag --> G["❌ invalid-format error"]
    F -- known tag --> H["encoded = fragment.slice(1)"]
    D --> I{arx family?}
    H --> I
    I -- no --> J["Sync decode\n(plain / lz / deflate)"]
    I -- yes --> K["Async decode\ndecodeArxFragmentPayload"]
    K --> L["splitArxFragmentRemainder\n(handles legacy dictVersion prefix)"]
    J --> M["JSON.parse → envelope validation"]
    L --> M
    M --> N["✅ ParsedPayload"]
Loading

Fix All in Codex

Reviews (2): Last reviewed commit: "Update docs and skills for the compact f..." | Re-trigger Greptile

Comment thread src/lib/payload/fragment.ts Outdated

// Compact header: a single tag char encodes (version, codec, dictVersion); the payload follows.
// No compact fragment can begin with the `agent-render=` literal (the wire alphabets exclude
// `=`), so the two forms stay unambiguous on decode.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

SUGGESTION: The collision-safety justification here is inaccurate.

The parenthetical "the wire alphabets exclude =" doesn't hold for base76: that wire shape uses = as its extended length marker (BASE76_EXTENDED_LENGTH_MARKER in arx-codec.ts), so a large arx base76 payload is emitted as a=… (i.e. = at payload position 0). The conclusion is still correct, but for a positional reason, not the stated one: a collision would need = at fragment position 12 (the end of agent-render=), while = can only appear at payload-position 0 (= fragment position 1, after the single tag char) for base76, and the other arx wires can't begin with gent-render anyway (B. prefix / non-ASCII base1k / U+FFF0 baseBMP marker). Worth rewording so a future wire variant that places = elsewhere isn't assumed safe.


Reply with @kilocode-bot fix it to have Kilo Code address this issue.

@kilo-code-bot

kilo-code-bot Bot commented Jun 19, 2026

Copy link
Copy Markdown

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Incremental review of 2 commits since c898d1f. The update resolves all previously flagged items and introduces no new issues in the changed code.

Previously flagged — now resolved
  • e2e breakage (was P1, fragment.ts:157)tests/e2e/viewer.spec.ts now asserts the generated link is the compact form (not #agent-render=, matches /#\w) and that the copied value equals the generated link (format-agnostic). Verified the input is bound to generatedLink.url (link-creator.tsx:357) and handleCopy copies the same value (link-creator.tsx:170), so toBe(linkValue) is consistent. getBaseUrl() always returns a value in-browser, so /# is always present.
  • Stale docs/skills (was P2, schema.ts:21)AGENTS.md, docs/architecture.md, docs/payload-format.md, docs/url-fragments.md, both SKILL.md files, and the link-creator.ts JSDoc now document the compact #<tag><payload> form. The documented tag table (p/l/d/a/b/c) matches compactCodecTags (schema.ts:17-24).
  • Collision-safety comment (was SUGGESTION, fragment.ts:355) — rewritten with the correct positional justification (the tag occupies fragment[0], so a payload = can only land at fragment[1]+). Verified BASE76_EXTENDED_LENGTH_MARKER = "=" (arx-codec.ts:670), confirming base76 does use =.
Other Observations (not in diff)
File Line Issue
src/lib/payload/schema.ts 16 The sibling collision-safety comment still gives the old tag-alphabet justification: "none can begin the legacy agent-render= literal". The a (arx) tag does begin agent-render= (its first char is a), so this is the same inaccuracy the fragment.ts comment was just corrected away from — the real safety is positional, per the fixed fragment.ts comment. Cosmetic only (decode is provably safe); worth aligning for consistency so a future wire change doesn't rely on the tag-alphabet claim.
Files Reviewed (9 files)
  • src/lib/payload/fragment.ts - 0 issues (comment fix verified accurate)
  • src/lib/payload/link-creator.ts - 0 issues (JSDoc fix)
  • tests/e2e/viewer.spec.ts - 0 issues (assertions robust)
  • AGENTS.md - 0 issues
  • docs/architecture.md - 0 issues
  • docs/payload-format.md - 0 issues
  • docs/url-fragments.md - 0 issues
  • skills/agent-render-linking/SKILL.md - 0 issues
  • skills/selfhosted-agent-render/SKILL.md - 0 issues
Previous Review Summary (commit c898d1f)

Current summary above is authoritative. Previous snapshots are kept for context only.

Previous review (commit c898d1f)

Status: 1 Issue Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 0
SUGGESTION 1
Issue Details (click to expand)

SUGGESTION

File Line Issue
src/lib/payload/fragment.ts 355 Collision-safety comment justification is inaccurate. It claims "the wire alphabets exclude =", but base76 uses = as its extended length marker (BASE76_EXTENDED_LENGTH_MARKER in arx-codec.ts), so a large arx base76 payload is emitted as a=…. The decode is still collision-free, but for a positional reason (the tag occupies fragment[0]; = can only land at payload-position 0 = fragment[1], never at fragment[12] where agent-render= needs it), not the stated one. Worth rewording so a future wire variant that places = elsewhere isn't assumed safe.
Other Observations (not in diff)

Two items were already flagged by a prior review pass — listing here for a consolidated picture, plus a few additional stale files not yet covered.

1. e2e test breakage (already flagged P1 on fragment.ts:157). tests/e2e/viewer.spec.ts:66 asserts the generated link matches /#agent-render=/ and :71 asserts the copied localStorage value contains #agent-render=, but the link creator now emits compact #<tag><payload> bodies. Playwright runs via npm run test:ci (package.json: test:ci includes test:e2e), so this fails on the CI path. Note npm run check (which the PR reports green) excludes e2e, so this isn't caught locally by check.

2. Public protocol docs/skill stale (already flagged P2 on schema.ts:21). docs/payload-format.md, docs/url-fragments.md, and skills/agent-render-linking/SKILL.md still document only the legacy #agent-render=v1.<codec>.<payload> shapes.

3. Additional stale contract references not covered by the prior P2:

File Line Issue
docs/architecture.md 100 Still describes arx2 wire as v1.arx2.<dictVersion>.<payload>.
skills/selfhosted-agent-render/SKILL.md 39, 65, 82, 245, 251, 360 Instructs building agent-render=v1.plain.<payload> / agent-render=v1.<codec>. payloads. (Selfhosted validatePayload only checks non-empty/length, so compact payloads still store fine — no runtime break, just stale guidance.)
AGENTS.md 26 Documents the legacy fragment format as the product contract; per the repo's own change-discipline rule, this should move with the contract.
src/lib/payload/link-creator.ts 141 JSDoc still says hash: #agent-render=v1... though the encoder now emits compact #<tag>....

Selfhosted path: selfhosted/validate.ts is format-agnostic (non-empty string + length budget only), so compact fragments store and round-trip through the UUID flow without code changes.

Files Reviewed (14 files)
  • src/lib/payload/fragment.ts - 1 issue
  • src/lib/payload/schema.ts - 0 issues
  • src/lib/payload/fragment-arx.ts - 0 issues
  • src/lib/payload/link-creator.ts - 0 issues (stale JSDoc noted above)
  • src/components/viewer-shell.tsx - 0 issues
  • src/components/viewer/artifact-stage.tsx - 0 issues
  • src/components/home/sample-link-data.ts - 0 issues
  • src/app/url-explainer/page.tsx - 0 issues
  • tests/compact-header.test.ts - 0 issues
  • tests/arx-codec.test.ts - 0 issues
  • tests/fragment-arx-selection.test.ts - 0 issues
  • tests/fragment.test.ts - 0 issues
  • tests/link-creator.test.ts - 0 issues
  • tests/sample-link-data.test.ts - 0 issues

Fix these issues in Kilo Cloud


Reviewed by GLM-5.2 · Input: 235.6K · Output: 30.1K · Cached: 832.6K

baanish and others added 2 commits June 19, 2026 21:09
The compact header (this PR) emits `#<tag><payload>` links, so the e2e
assertions on `/#agent-render=/` for the generated and copied link were
obsolete and failed `test:e2e` in CI (`npm run check` excludes e2e, so it
passed locally). Assert the generated link is the compact form (not the
legacy `#agent-render=`) and that the copied value equals the generated
link — format-agnostic, so it survives future tag additions.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The compact header (#<tag><payload>) replaced the legacy
agent-render=v1.<codec>.<dictVersion>. form as the emitted format; legacy
links still decode. Update the skills external agents follow, the product
contract in AGENTS.md, the payload/url-fragment/architecture docs, and the
link-creator JSDoc. Also correct the fragment.ts collision-safety comment:
base76 uses = as its extended-length marker, so unambiguity holds for a
positional reason (tag at fragment[0]), not because the alphabets exclude =.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@baanish
baanish changed the base branch from codex/dependabot-deps to main June 19, 2026 16:48
@baanish
baanish merged commit 7edc5ee into main Jun 19, 2026
10 checks passed
@baanish
baanish deleted the codex/compact-header branch June 19, 2026 16:49
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