Skip to content

fix(core): reuse durable event codecs - #43778

Closed
opencode-agent[bot] wants to merge 1 commit into
v2from
cpu-event-codecs
Closed

opencode-agent[bot] wants to merge 1 commit into
v2from
cpu-event-codecs

Conversation

@opencode-agent

Copy link
Copy Markdown
Contributor

Summary

  • cache durable-event schema encoders by immutable event definition
  • cache matching decoders at replay and synchronization boundaries
  • keep serialized event shapes and validation behavior unchanged

Verification

  • bun test test/session-tool-progress.test.ts from packages/core (1 passed)
  • git diff --check

Requested by: @rekram1-node (Aiden via Slack)

Co-authored-by: Hona <10430890+Hona@users.noreply.github.com>
@Enough1122

Copy link
Copy Markdown

AI code review — automated review for reference; please use your judgment.

  • packages/core/src/bus.ts:70 — The WeakMap fast path only pays off if Event.Definition instances are stable singletons; if Durable.get ever reconstructs or wraps definitions per lookup, every call becomes a miss plus an extra map write (a small regression instead of a win) — worth asserting definition identity stability in the durable registry or adding a debug counter to confirm hit rate.
  • packages/core/src/bus.ts:79 — Cached decoders silently pin the schema captured at first use: if a definition's data schema is mutated or its event type is re-registered at runtime (dynamic registration, dev hot-reload), events keep validating against the stale codec with no error — either document that definitions must be immutable, or clear these caches wherever the Durable registry is updated.
  • packages/core/src/bus.ts:282 — Both call sites still duplicate the as Record<string, unknown> cast after the helper returns unknown — moving the cast inside encodeData (typed return) would remove the repetition and give callers a safer contract.
  • packages/core/src/bus.ts:70 — No regression test accompanies the change; a cheap guard would round-trip the same durable event twice and spy that the second encode/decode reuses the cached codec (or simply assert identical output across many iterations), so future refactors of the cache don't silently change validation semantics.

— AI code review (automated)

renekris added a commit to renekris/opencode-lowmem that referenced this pull request Aug 26, 2026
, adapted)

Effect Schema codecs for durable events are compiled once per
definition and cached in a module-level WeakMap (dynamically-created
definitions are never retained by the cache). decodeSerializedEvent,
the durable commit encode path, and replay decoding all share it.
Upstream anomalyco#43778 by app/opencode-agent (AI-authored; credited in README
prose only).

README: ported row for the codec cache, customs rows for the payload
budget and LSP document LRU with knob tables.
@github-actions

Copy link
Copy Markdown
Contributor

Automated PR Cleanup

Thank you for contributing to opencode.

Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions.

This PR was closed because it matched the following cleanup criteria:

  • The PR was created more than 1 month ago
  • The PR had fewer than 2 positive reactions
  • Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR

PRs created within the last month are not affected by this cleanup.

If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate.

Thanks again for taking the time to contribute.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants