Skip to content

feat(invariants): verified-fact elision markers for JSON and log compression - #82

Merged
Patel230 merged 1 commit into
mainfrom
feat/invariant-markers
Aug 23, 2026
Merged

feat(invariants): verified-fact elision markers for JSON and log compression#82
Patel230 merged 1 commit into
mainfrom
feat/invariant-markers

Conversation

@Patel230

Copy link
Copy Markdown
Contributor

Summary

Silent elision forces readers to guess what was dropped — and agent benchmarks (documented in the caveman project) show bare [N collapsed] markers cause 11–97 recovery-call storms. This PR makes every elision state only verified facts about what was removed.

Changes

  • New invariants.go: computes facts that hold across every elided unit:
    • field constants (status=charged ×15)
    • exact enumerations summing to the elided total (state: pending×1 processing×2 shipped×3)
    • numeric ranges from original strings, numerically ordered (amount=5..199.99)
    • distinct-count coverage (order_id: 25 distinct, ord-1000..ord-1024)
    • dense-run upgrade (wh-5000..5008 all 9 present) when prefix+fixed-width+density hold
  • Withhold rules are correctness, not tuning: credential-shaped field names, values with spaces or >24 bytes, >5 buckets, units yielding no fields → fact withheld entirely; runs <3 units never summarized; 160-byte cap.
  • CompressJSON: elided items now replaced by a trailing sentinel {"_tok_elided":{count,facts}} — output stays a valid JSON array; silent drops eliminated.
  • CompressLog: collapsed-run marker now carries the level distribution (info×3 debug×2).
  • Existing test updated for the sentinel (+1 record); new suite covers each fact type and every withhold case.

Verification

Full test suite green (go test ./...), vet clean.

…ression

Silent elision forces readers to guess what was dropped, and agent
benchmarks show the guess is usually 'retrieve everything' — bare
'[N collapsed]' markers caused 11-97 recovery-call storms.

CompressJSON now replaces elided array items with a trailing sentinel
record ({"_tok_elided":{count,facts}}) keeping the array valid JSON,
and CompressLog's collapsed marker carries the level distribution of
the run. Facts state only what was VERIFIED across every elided unit:

- field constants: status=charged x15
- exact enumerations whose counts sum to the elided total:
  state: pending x1 processing x2 shipped x3
- numeric ranges from original value strings: amount=5..199.99
  (numerically ordered, integral floats without decimals)
- distinct-count coverage: order_id: 25 distinct, ord-1000..ord-1024
- dense-run upgrade when prefix+fixed-width+density all hold:
  wh-5000..5008 all 9 present

Withhold rules are correctness, not tuning: credential-shaped field
names, values with spaces or >24 bytes, >5 buckets, units yielding no
fields -> that fact is withheld entirely, never shortened; runs under
3 units are not summarized at all; summaries cap at 160 bytes.
@Patel230
Patel230 merged commit a1d1863 into main Aug 23, 2026
20 checks passed
@Patel230
Patel230 deleted the feat/invariant-markers branch August 23, 2026 02:02
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