Skip to content

fix: reduce repeated history hashing in Responses requests - #189796

Merged
steipete merged 2 commits into
mainfrom
steipete/perf-micro-responses-prefix-fingerprint-rehash-20260919
Oct 31, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/perf-micro-responses-prefix-fingerprint-rehash-20260919

Conversation

@steipete

@steipete steipete commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Long OpenAI Responses conversations repeatedly encode and hash their entire history while validating persisted replay state, increasing request CPU and garbage collection as the conversation grows.

User Impact

Immutable text history now hashes only newly appended entries. Request bytes, persisted SHA-256 fingerprints, restart compatibility, and prompt-cache identity remain unchanged; no configuration or storage migration is needed.

Why This Change Was Made

The fingerprint is persisted, so a hash-of-entry-hashes would change its contract. The fingerprint owner instead keeps weakly owned SHA state at immutable prefix boundaries and validates the ordered entry identity chain before extending it. Rewrites, branches, and replacement compaction state invalidate incompatible checkpoints.

Read-only diagnostic/prompt observers and unchanged text sanitation now preserve the converter's existing immutable publications. Genuine payload hooks still receive editable copies. Validated saved compaction state publishes data-free entry identities without retaining decoded windows or image URLs.

A linear identity walk remains. Mutable inputs, image-bearing sanitation output, and reconstructed inline-compaction assistant tails can stop prefix reuse; their suffix retains the original hashing behavior. This does not remove independent compaction validation or request serialization.

Evidence

  • Regression fails on the base because retained text is encoded again; the fix passes exact canonical SHA, append work-count, branch/reorder/shortening, cold reload, mutable-hook, and composed compaction replay checks.
  • Final affected run: 130 tests passed across continuation, real transport wrappers, reasoning updates, compaction/V2, and sanitation. Earlier owner/prefix-stability proof: 170 tests passed.
  • Independent Codex autoreview: scoped clean through P2.
  • pnpm check:changed --staged --base HEAD and the full rerun exposed the inherited dead export below plus test fixture typing/lint errors, now repaired. Core production typechecking, all test-type shards (including the repaired package shard), core/script lint, and 58 affected tests pass; the observer-option typing repair additionally passes all 22 transport tests. All remaining guards completed successfully; the dead-export finding is the only unresolved local failure.
  • The final test-only repair also passed isolated Codex autoreview through P2; runtime code is unchanged from the second full review. Exact-head CI run 41246298999 and the aggregate CI, dependency, and security-sensitive gates are green at d3d314c01e500d2952aff2695ca5ca214343bb15. Native preparation preserved that head.
  • Inherited main regression: publishPluginSourceSnapshot is unused in production. The exact parent 680003ae23115f5ad68a34808a0f44265427916d reproduces the same sole production Knip finding. It was introduced by 8e6129a813f88f1eb145a979c39d141cd8437c93 (feat(plugins): publish installed source snapshots #189624), whose new export has test consumers only. This patch does not touch that owner. Main independently repaired this regression in a6a2378739fc116e8b44bac495d6b62463134683 (fix(plugins): remove test-only snapshot publisher #189770) while this lane ran; final main-source inspection confirms the wrapper is removed.

Synthetic fixture: 20 interleaved sessions, approximately 2 KiB per history entry, five one-entry appends per session, actual request preparation/sanitation. Five counterbalanced A1/A2 rounds per owner; ten samples of 100 warm calls. CPU is process CPU; allocation uses V8 sampling including GC-collected objects. No production data or live provider traffic.

History entries Median CPU µs, before → after Median sampled bytes/request, before → after
50 235.97 → 37.93 437,752 → 11,660
500 1,439.48 → 84.68 4,128,685 → 9,631
2,000 6,212.10 → 340.06 16,440,454 → 9,175

At 2,000 entries: CPU −94.5%, allocation −99.94%. A/A median CPU controls were 6,230/6,194 µs before and 343/327 µs after. Cold first-hash CPU was flat or improved; cold allocation grew 3.4–3.6%. A separate retention probe measured approximately 245 KB additional heap at 2,000 entries and confirmed weak input collection. These are fingerprint-owner measurements, not Gateway latency or prompt-cache hit-rate claims.

Reproduce with scripts/perf/responses-prefix-fingerprint-measure.ts against a saved baseline owner. Acceptance: identical legacy digests, no historical encoding on immutable append, lower warm CPU/allocation, and disclosed cold/retained-state cost. Host: Node 26.12.1, macOS, 32 logical CPUs; shared-host timing noise is covered by A/A controls.

Production net +178 LOC, tests +290, benchmark +210. The growth preserves exact persisted hashes and immutable ownership through the existing observer/sanitation/compaction boundaries; no schema-hash cache or new persisted state was added. Author simplification pass complete.

@clawsweeper

clawsweeper Bot commented Oct 31, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@openclaw-barnacle openclaw-barnacle Bot added scripts Repository scripts agents Agent runtime and tooling size: L labels Oct 31, 2026
@steipete
steipete marked this pull request as ready for review October 31, 2026 21:54
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-31T22:04:00.543061Z d3d314c New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 31, 2026
@steipete
steipete merged commit 2c16bf5 into main Oct 31, 2026
146 of 147 checks passed
@steipete
steipete deleted the steipete/perf-micro-responses-prefix-fingerprint-rehash-20260919 branch October 31, 2026 22:14
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

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

Labels

agents Agent runtime and tooling clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. scripts Repository scripts size: L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant