Skip to content

Make memory service canonical JSON locale-independent and lossless - #3221

Open
Kevin Turcios (KRRT7) wants to merge 1 commit into
microsoft:mainfrom
KRRT7:fix/memory-canonical-json
Open

Kevin Turcios (KRRT7) wants to merge 1 commit into
microsoft:mainfrom
KRRT7:fix/memory-canonical-json

Conversation

@KRRT7

Copy link
Copy Markdown

Summary

  • Procedure and view hashes (canonicalizeProcedure, viewHash) sorted object keys with localeCompare using the host's default locale. The same document could hash differently across machines: Estonian and Danish hosts put keys in a different order than en-US. Keys now sort with a pinned en collator. That matches the hashes already stored by en-locale hosts, so stored review content hashes and fingerprints stay valid.
  • Agent session request hashes were sha256(JSON.stringify(request)), so an identical retry with keys in a different order failed with "idempotency key has different content". Requests now hash a canonical form, and hashes stored in the old format are still accepted (marked with a TODO to remove).
  • Session event redaction silently dropped a value when two keys redacted to the same text (e.g. two sk-... keys both becoming [REDACTED]). Both values are now kept ([REDACTED], [REDACTED] (2)). An event stored before this change may not match its saved digest when re-sent. In that case only, the chunk is re-parsed the old way so the stored digest is still recognized instead of being rejected as conflicting content.
  • The four copies of the sort-keys-then-serialize helper are replaced by one shared canonicalJson.ts. Session event text keeps code-point key order, because stored event digests depend on it.

Scope

Seven files, all in memory/service: five source files, plus a new spec and additions to an existing spec. No changes to stored formats, dependencies, or other packages.

Testing

  • memory/service: all 73 suites pass (853 tests), including the new canonicalJson.spec.ts and collision tests in agentSessionParsing.spec.ts.
  • Compared old-format digests against the parser at main on colliding, nested-colliding, and non-colliding events: all match, and non-colliding events hash the same as before.
  • Lint, complexity, and debt ratchets and the circular-dependency check all pass against origin/main.

Replace four copies of the sort-keys-then-serialize helper with one
shared canonicalJson module.

- Procedure and view hashes sorted keys with the host's default locale,
  so the same document hashed differently on, e.g., Estonian or Danish
  hosts. Pin an "en" collator, which matches hashes already stored by
  en-locale hosts.
- Agent session request hashes depended on key order, so an identical
  retry with reordered keys was rejected as different content. Hash a
  canonical form and still accept hashes stored in the old format.
- Session event redaction silently dropped a value when two keys
  redacted to the same text. Keep both ("[REDACTED] (2)") and accept
  the old lossy digest for events stored before this change.

Session event text keeps code-point key order, since stored event
digests depend on it.
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

This branch has not been deployed

No deployments
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