8000 perf(agentcore): reduce projection reads and canonical JSON allocations by Fodesu · Pull Request #135 · felinics/twilight · GitHub
[go: up one dir, main page]

Skip to content

perf(agentcore): reduce projection reads and canonical JSON allocations - #135

Merged
Fodesu merged 11 commits into
integration/agentcore-runtimefrom
perf/agentcore-bind-boundary-reads
Oct 20, 2026
Merged

Fodesu merged 11 commits into
integration/agentcore-runtimefrom
perf/agentcore-bind-boundary-reads

Conversation

@Fodesu
@Fodesu Fodesu commented Oct 20, 2026 •
Copy link
Copy Markdown
Member

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:

  • Share checkpoint-boundary validation and projection log reads; bound durable effect proofs with verified commit-index lookups while retaining legacy fallbacks.
  • Cache decoded headers and projection files with file identity, size, modification time, and native change-time validation. Bound cache entries and bytes; retain detached caller values.
  • Track pending inputs in a compact projection for routing and work inspection, respecting inherited history and checkpoint integrity.
  • Reuse eligible projection encodings, clone machine state without JSON round trips, and reduce canonical JSON, checkpoint digest, and event-version extraction allocations while preserving wire bytes and codec validation.

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=120s
  • go vet ./agentcore/... ./internal/canonicaljson/...
  • GOTOOLCHAIN=go1.26.5 golangci-lint run ./agentcore/... ./internal/canonicaljson/... — 0 issues
  • Targeted race tests rerun after lint cleanup.
  • Regression coverage includes bounded reads, stale/replaced file invalidation, fork inheritance, checkpoint fallback and corruption, detached state, codec errors, and canonical byte parity.

Fodesu added 11 commits October 20, 2026 21:35
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.
@Fodesu
Fodesu added this pull request to stack #136 October 20, 2026 13:36
@Fodesu Fodesu changed the title perf/agentcore bind boundary reads perf(agentcore): reduce projection reads and canonical JSON allocations Oct 20, 2026
@Fodesu
Fodesu merged commit 7a36ec1 into main Oct 20, 2026
6 of 7 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.

1 participant

0