You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
refactor(json): centralize serialization through the JSON wrapper #616
Polylogue has a canonical typed JSON layer in polylogue/lib/json.py, but many production and devtools paths still bypass it with direct stdlib json calls or direct orjson imports.
Evidence from current master:
polylogue/lib/json.py defines JSONValue, JSONDocument, dumps, dumps_bytes, loads, and validation/coercion helpers backed by orjson with stdlib fallback.
rg "json\.(loads|dumps|load|dump)\(" polylogue devtools finds many direct call sites.
proof hash and evidence paths repeatedly configure sort_keys, separators, and ensure_ascii locally.
polylogue/browser_capture/server.py reads request JSON through stdlib json.loads while using dumps_bytes for responses.
polylogue/browser_capture/receiver.py imports orjson directly for pretty sorted output.
Some direct stdlib JSON use may be legitimate for compatibility-sensitive formats. The current code does not mark those exceptions, so generic machine-output and artifact code keeps reinventing formatting/parsing policy.
Impact
The repository already pays for the orjson dependency and typed JSON contracts, but serialization behavior remains scattered. This adds boilerplate, makes stable hash/pretty-output behavior harder to reason about, and weakens the value of the central JSON abstraction.
Acceptance criteria
Define a policy for when code should use polylogue.lib.json versus direct stdlib json.
Add compact helper functions for common forms, for example:
pretty JSON text/bytes
canonical hash bytes
JSON file read/write with typed validation
JSON CLI output to stdout
Migrate generic production/devtools call sites to the wrapper.
Leave explicit comments or local helper names for compatibility-sensitive direct stdlib JSON uses.
Add a lint/check or focused test that prevents new generic direct JSON bypasses outside the allowlist.
Run focused JSON/proof/devtools tests and devtools verify --quick.
Additional scope from the compactness audit: centralizing JSON serialization should not mean keeping every recursive JSON guard as a permanent mini-framework.
polylogue/lib/json.py has two different behaviors today:
strict helpers such as require_json_value() and require_json_document() fail when a producer violates the JSON contract;
forgiving helpers such as json_document() and json_document_list() silently coerce invalid values to {} or drop invalid list items.
The strict serialization wrapper is still useful because the project needs canonical dumping, Decimal handling, and non-finite JSON rejection. But at typed boundaries such as manifests, schema packages, proof attributes, provider capability payloads, and browser-capture payloads, Pydantic models or TypeAdapter validation should replace silent {} coercion where strictness matters.
Acceptance should include an audit of current json_document() / json_document_list() call sites and a rule: parser-shape probing may use forgiving coercion, but repo-control manifests and machine-output payload construction should fail loudly on invalid JSON-compatible data.
Superseded by #614. I consolidated this finding into the composite issue so the work can be handled as one coherent slice instead of as a tiny standalone ticket. The original evidence remains available in this issue history.
Activity
Sinity commentedon May 1, 2026
Additional scope from the compactness audit: centralizing JSON serialization should not mean keeping every recursive JSON guard as a permanent mini-framework.
polylogue/lib/json.pyhas two different behaviors today:require_json_value()andrequire_json_document()fail when a producer violates the JSON contract;json_document()andjson_document_list()silently coerce invalid values to{}or drop invalid list items.The strict serialization wrapper is still useful because the project needs canonical dumping, Decimal handling, and non-finite JSON rejection. But at typed boundaries such as manifests, schema packages, proof attributes, provider capability payloads, and browser-capture payloads, Pydantic models or
TypeAdaptervalidation should replace silent{}coercion where strictness matters.Acceptance should include an audit of current
json_document()/json_document_list()call sites and a rule: parser-shape probing may use forgiving coercion, but repo-control manifests and machine-output payload construction should fail loudly on invalid JSON-compatible data.Ref #629
Ref #578
Sinity commentedon May 1, 2026
Superseded by #614. I consolidated this finding into the composite issue so the work can be handled as one coherent slice instead of as a tiny standalone ticket. The original evidence remains available in this issue history.