Skip to content

perf(agent): hash signed-history snapshots instead of retaining screenshots - #14

Draft
kvnloo wants to merge 3 commits into
review/1151-basefrom
review/1151-shape-digest-cleanup
Draft

kvnloo wants to merge 3 commits into
review/1151-basefrom
review/1151-shape-digest-cleanup

Conversation

@kvnloo

@kvnloo kvnloo commented Oct 17, 2026 •

Copy link
Copy Markdown
Owner

Context

Focused follow-up on e2e-inc#1151 by TheTuso, addressing maintainer okwasniewski's latest review. This draft's base is exact upstream PR head 4c095a6592ed49e956fee54e069f58c0bff9cc9d; please cherry-pick/reapply on the existing upstream PR, not create a duplicate origin PR.

The review verified the signed-thinking fix, and specifically requested:

  1. Revert shrinkForOverflow's identity-preservation helpers now that the comparison is by value.
  2. Optionally replace a second in-memory full screenshot-history copy with a streaming digest; maintainer observed ~20 MB retained per running step for 16 screenshot messages.

Patch

  • message-shape.ts: compute a fixed 64-character SHA-256 digest by streaming the same serialized field delimiters and binary bytes to createHash; model-visible data is hashed synchronously, so a later mutation changes the next digest. Ignore providerOptions and providerMetadata exactly as before.
  • tool-loop.ts: restore the original concise overflow compaction implementation, removing now-redundant clipped and clippedText helpers.
  • Unit regression validates clone equality, in-place edits, and fixed-size fingerprint on 2 MiB screenshot payload.

Evidence and remaining gate

  • Compared against exact upstream PR head: 3 files; 3 commits, no unrelated diff.
  • Source-level review of relevant message-shape tests and current default-branch overflow implementation.
  • Isolated Node 22 smoke of the exact message-shape.ts algorithm: 5/5 assertions (clone equality, 2 MiB binary byte mutation, metadata exclusion, nested tool-result change, 64-character digest). 200 SHA-256 snapshots of a 2 MiB message took 277 ms total (~1.385 ms each) on the sandbox CPU. This is not an e2e benchmark or baseline comparison.
  • Monorepo pnpm check, Vitest and model-backed testbed not run in this sandbox (repository dependencies unavailable, network disabled); CI/author required before promoting.
  • Confirm no benchmark regression from hashing large screenshots in actual agent loop. Digest reduces retained snapshot size; no measured process-memory or latency claim here.

Credit: TheTuso built the original signed-history fix and regression cases; okwasniewski diagnosed and reproduced both remaining cleanup/memory concerns. This is a small helper patch for that existing work, not a competing implementation.

Coordination: #12

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