Repository navigation
perf(agentcore): reduce projection reads and canonical JSON allocations - #135
Merged
Fodesu merged 11 commits intoOct 20, 2026
Merged
Conversation
Read each distinct checkpoint position once per Bind while preserving per-projection validation and acquisition isolation. Add coverage across reopening and newly appended history.
Decode and verify each checkpoint independently, then replay a shared ledger page. Retain ordinary Load semantics and the minimum observed revision for custom readers. Cover invalid and inherited checkpoints, detached states, and reads after append. Validated with clean-core overlay race suites for session/writer, runtime, and turn/sessionstore, and combined agent app/HTTP/activation race suites.
Find effect-naming closing facts through authoritative commit lookups. Bound arbitrary cancellation scans by a verified local start, preserving full stream fallback for older histories. Reject inherited/foreign proofs and propagate index errors. Cover pending effects, legacy history, and cancellation across page boundaries. Validated with clean-core overlay race suites for session/writer, runtime, and turn/sessionstore, and combined agent app/HTTP/activation race suites.
Reuse a successful immutable encoding only for opted-in state codecs while still decoding every read into a detached value. JSONStateCodec opts in; custom codecs retain per-read encoding unless they declare the capability. Invalidate after a durable consumed event or derived fold failure, preserving encodings across rejected, duplicate, no-op and unrelated commits. Scope validation still runs for every provisional fold. Avoid two redundant checkpoint byte copies without changing seal bytes or digest verification. Cover mutation isolation, invalidation, codec failures, custom opt-out, unknown in-scope events, and legacy checkpoint preimages.
Add a compact input lifecycle projection containing pending IDs, digests, placement and submission positions. Remove settled inputs; retain full lifecycle validation in Surface. Require checkpoint seals and follow domain inheritance so scheduling cannot silently lose work through bad caches. Use this queue in runtime inspection and step routing. Cover legacy submissions, ledger order, lifecycle parity, forks, detached state, retention, read failures and checkpoint fallback. Keep existing event wire formats.
Allow projections to explicitly provide a deterministic CloneState hook for Writer-local reads. Keep codec persistence and fallback behavior intact. Opt the Machine projection into typed snapshots that detach all mutable containers while sharing immutable JSON values. Preserve codec normalization and failures, including omitted empty slices, required null arguments, UTF-8 repair and JCS integer handling. Cover codec parity, mutation isolation, writer reads, health checks and error propagation.
Render valid UTF-8 string tuples directly in JCS form into one buffer, including the unchanged typed-payload prefix. Keep generic encoders and invalid UTF-8 repair on the existing canonical marshaling path. Decode checkpoint envelopes without a growing streaming buffer while retaining state canonicalization, digest verification and cache binding. Pin byte compatibility against independent marshal/JCS references, fuzz string tuples and cover legacy checkpoint acceptance and rejection.
Extract members from immutable canonical objects without decoding, sorting or canonicalizing their remaining fields again. Share only immutable member bytes and detach the remainder, retaining payload version checks and existing diagnostics for malformed or unversioned payloads. Compare extracted values and bodies against independent JSON/map/JCS references, fuzz nested objects and names, and retain the legacy version splitter in tests to check exact byte, version and diagnostic compatibility.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Session activation repeatedly validates the same checkpoint boundaries, replays overlapping projection history, and reconstructs JSON values during reads. Scheduling also reads full chat history to inspect pending inputs.
This PR builds on #134 and reduces that repeated work:
The upper-layer diff contains only AgentCore and its internal canonical JSON helper. The original ten optimization commits were rebased unchanged onto #134; one additional commit resolves lint findings. Application and deployment history is excluded.
Validation:
go test ./agentcore/... ./internal/canonicaljson/... -short -race -count=1 -timeout=120sgo vet ./agentcore/... ./internal/canonicaljson/...GOTOOLCHAIN=go1.26.5 golangci-lint run ./agentcore/... ./internal/canonicaljson/...— 0 issues