Skip to content

feat(context): add opt-in GCF compression as a drop-in alternative to TOON - #83

Merged
veerareddyvishal144 merged 3 commits into
Fast-Editor:mainfrom
blackwell-systems:feat/gcf-context-compression
Jul 17, 2026
Merged

feat(context): add opt-in GCF compression as a drop-in alternative to TOON#83
veerareddyvishal144 merged 3 commits into
Fast-Editor:mainfrom
blackwell-systems:feat/gcf-context-compression

Conversation

@blackwell-systems

@blackwell-systems blackwell-systems commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Adds GCF (Graph Compact Format) as an opt-in alternative to the TOON encoder Lynkr already uses for large-JSON context compression. Same contract as the TOON adapter (encode-only, fail-open, read-only context, never touches tool-protocol payloads); only the encoder differs. Off by default (GCF_ENABLED=false); takes precedence over TOON when enabled.

Two reasons to offer it as an option:

1. Correctness — GCF is lossless by design, and this PR verifies it per payload. TOON's round-trip is not guaranteed. A 100k-case fuzz of the reference @toon-format/toon shows a 7.47% round-trip failure rate — 1.73% of it silent data corruption (wrong value, no error thrown), the rest decode crashes. The failing inputs are deeply-nested / ragged structures; flat uniform records round-trip clean. Lynkr's compressor doesn't constrain payload shape and currently does no round-trip check, so a silent corruption on a nested payload would reach the model undetected. This adapter adds GCF_VERIFY (default on): it decodes each encoding and keeps the original JSON unless it reproduces the input exactly.
Reproduce: eval/toon-fuzz.mjs · 10M-case log

2. Compression — ties TOON on flat records, wins on nested. TOON re-declares a nested object's schema per row, so on nested tool results it can encode larger than minified JSON; GCF path-flattens. Benchmark (50-record payloads, o200k, GCF round-trip verified):

shape minified JSON TOON GCF
flat {id,label,value} 3655 3358 3365
nested meta+metrics 2502 3151 1240

Safety: opt-in, mutually exclusive with TOON, fail-open (keeps JSON if the encoder is missing/throws), never-grow guard (keeps JSON unless the target model's token count actually drops), and the round-trip verify above. @blackwell-systems/gcf is MIT with zero runtime deps.

Config (mirrors TOON_*): GCF_ENABLED, GCF_MIN_BYTES, GCF_FAIL_OPEN, GCF_LOG_STATS, GCF_VERIFY.

In production elsewhere: GCF ships as an opt-in format in Chrome DevTools MCP, is vendored into OmniRoute's headroom compression engine, replaced TOON in NetClaw, and was merged into Speakeasy's oq. Full list: gcformat.com/ecosystem/adopters.

Format + research: spec and playground at gcformat.com (vs-TOON, benchmarks); the format and its underlying tokenizer/attention research are documented in the whitepaper (DOI 10.5281/zenodo.20579817, attention papers linked therein).

Future — delta encoding (phase 2, not in this PR): across turns in a session Lynkr re-sends overlapping structured context; GCF's generic delta profile encodes only changed rows between turns (keyed row diff, content-addressed), which neither JSON nor TOON can do. Lynkr already tracks sessions, so this state could hang off the existing session model. This PR is the stateless foundation a delta layer would build on.

This is opt-in and additive — TOON stays the default and is untouched, GCF only activates behind GCF_ENABLED. Happy to adjust the design, flag names, defaults, or scope to fit the project's conventions.

… TOON

Adds a GCF (Graph Compact Format) encoder for the large-JSON context
compression Lynkr already does with TOON. Same adapter contract as
src/context/toon.js: encode-only, fail-open, read-only context, never
touches tool-protocol payloads. Only the encoder differs.

- Off by default (GCF_ENABLED=false); takes precedence over TOON when on.
- Round-trip verify (GCF_VERIFY, default on): decodes each encoding and
  keeps the original JSON unless it reproduces the input exactly, making
  the compression provably lossless per payload.
- Never-grow guard using the target model's token count, with a byte
  fast-path to skip tokenizing on the hot path.
- Config mirrors TOON_*: GCF_ENABLED, GCF_MIN_BYTES, GCF_FAIL_OPEN,
  GCF_LOG_STATS, GCF_VERIFY.
- @blackwell-systems/gcf: MIT, zero runtime deps.

Tests: test/gcf-compression.test.js (6 cases: disabled no-op, fail-open,
never-grow, verify-mismatch, protocol-field preservation, text-block
compression).
@veerareddyvishal144

veerareddyvishal144 commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

@blackwell-systems Hi
Thanks for contributing to the repo I will be merging the PR today once you submit package-lock.json as well
Since you added a npm package. 😄

@blackwell-systems

Copy link
Copy Markdown
Contributor Author

Thanks! Just pushed the package-lock.json update with the @blackwell-systems/gcf entry (pinned to 2.4.0, lock-only so nothing else changed). Should be good to merge now, let me know if anything else is needed.

@veerareddyvishal144

Copy link
Copy Markdown
Contributor

Thank you I shall merge this PR

@veerareddyvishal144
veerareddyvishal144 merged commit 24e69a7 into Fast-Editor:main Jul 17, 2026
3 checks passed
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