Skip to content

perf(responses): reuse measured entry strings for the state snapshot - #6360

Merged
lidge-jun merged 1 commit into
devfrom
codex/pr4732-snapshot-carry
Oct 1, 2026
Merged

lidge-jun merged 1 commit into
devfrom
codex/pr4732-snapshot-carry

Conversation

@lidge-jun

@lidge-jun lidge-jun commented Oct 1, 2026 •

Copy link
Copy Markdown
Owner

Summary

Carries the snapshot half of #4732 by @chilung-cgu onto current dev.

writeBoundedSnapshot already serializes every candidate entry once in selectSnapshotEntries to measure its UTF-8 size, then serialized the whole selection a second time to build the payload. The selector now keeps the measured entry strings and the payload is assembled by joining them, so a snapshot write does one JSON.stringify pass over the entries instead of two. The output is byte-identical.

The router half of #4732 (static PROVIDER_REGISTRY lookup maps) is not carried: dev has since reshaped the snapshot code into selectSnapshotEntries, and a direct measurement showed no measurable routeModel change from the registry cache, so it would add state without a benefit.

Measured with a standalone script (not committed) that runs the previous dev selector verbatim against the new one on a 1,200-entry state map that produces a 23.98 MiB payload, asserting identical output before timing (30 runs after 5 warmups, two rounds):

median p90
previous dev 29.0–30.3 ms 32.8–36.8 ms
this change 17.6–18.0 ms 19.7–22.0 ms

Closes #4732 as carried.

Co-authored-by: WU, CHI-LUNG chilung-cgu@users.noreply.github.com

Verification

  • Local test suite and typecheck were not run, on maintainer instruction; verification is the hosted CI on this exact head.
  • New regression test tests/responses/responses-state-snapshot-select.test.ts pins the exact snapshot bytes across stub and resident entries, multibyte text, escapes, and both byte budgets; it is registered in scripts/test-layout/layout.json and tests/fixtures/test-layout-expected.json.
  • Standalone benchmark above, with the old and new payloads compared for equality before timing.

Checklist

  • Scope stays focused and avoids unrelated cleanup.
  • Docs or release notes were updated when needed. (No user-visible behavior change.)
  • Security-sensitive changes were reviewed for secrets, auth, and unsafe defaults. (No auth, credential, or dependency surface touched.)

Summary by CodeRabbit

  • Improvements
    • Response-state snapshots continue to follow the existing entry selection and size limits, including for entries containing multibyte text.
    • Snapshot output remains consistent across different storage budgets, with an appropriate empty-state format when there are no entries.
    • These changes do not alter which entries are selected for snapshots.

writeBoundedSnapshot already stringifies every candidate entry once in
selectSnapshotEntries to measure its UTF-8 size, then stringified the whole
selection again to build the payload. Keep the measured strings and join them
instead. The output is byte-identical; a pinned-bytes regression test covers
stubs, residents, multibyte text, escapes, and both byte budgets.

Reworks the snapshot half of #4732 onto the two-pass selector now on dev.

Co-authored-by: WU, CHI-LUNG <chilung-cgu@users.noreply.github.com>
@lidge-jun
lidge-jun requested a review from Ingwannu as a code owner October 1, 2026 07:21
@chatgpt-codex-connector

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

Copy link
Copy Markdown

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-01T07:24:13.053488Z a0d9da3 PR opened
ℹ️ 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.

@github-actions

github-actions Bot commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

✅ Deterministic PR hygiene checks passed.

@github-actions github-actions Bot added the enhancement New feature or request label Oct 1, 2026
@coderabbitai

coderabbitai Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

🧰 Additional context used
📚 Code guidelines (2)
scripts/AGENTS.md — auto-discovered
src/AGENTS.md — auto-discovered

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: lidge-jun/opencodex/.coderabbit.yaml

Review profile: ASSERTIVE

Plan: Advanced

Run ID: 3b7f3dae-e407-4984-a66f-76c06ba1059d

📥 Commits

Reviewing files that changed from the base of the PR and between 6429463 and a0d9da3.

📒 Files selected for processing (5)
  • scripts/test-layout/layout.json
  • src/responses/state.ts
  • src/responses/state/snapshot-select.ts
  • tests/fixtures/test-layout-expected.json
  • tests/responses/responses-state-snapshot-select.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.


📝 Walkthrough

Walkthrough

Snapshot selection now returns serialized entries, which the snapshot writer uses to build the version-2 payload. Tests cover serialized output, byte budgets, and the empty-store payload.

Changes

Snapshot serialization

Layer / File(s) Summary
Select entries and build snapshot payload
src/responses/state/snapshot-select.ts, src/responses/state.ts, tests/responses/responses-state-snapshot-select.test.ts, scripts/test-layout/layout.json, tests/fixtures/test-layout-expected.json
selectSnapshotEntries returns serialized entry strings and measures their UTF-8 byte lengths. snapshotPayload assembles the version-2 body, and writeBoundedSnapshot delegates payload construction to it. Tests cover exact output, budget-limited selections, and the empty-store payload. The test-layout mappings include the new test.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Refactor

Merge Risk: ⚪ Minimal · up to a0d9d

The change reuses serialized snapshot entries while preserving the existing format and selection behavior. No concrete merge-blocking issue is identified; normal CI checks should pass before merging.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning Issue [#4732] has two coding objectives. The snapshot objective is implemented: src/responses/state/snapshot-select.ts now serializes each selected entry once, measures UTF-8 bytes, and exposes `sna… Implement the [#4732] router objective in src/router.ts: add the required static registry lookup maps, replace the repeated PROVIDER_REGISTRY.find(...) and related Object.keys() scans in knownModelIdsForProvider, `routedProviderConf…
Docstring Coverage ⚠️ Warning Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 3 files. (2 skipped: 2… Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: reusing measured serialized entry strings when building the responses state snapshot.
Out of Scope Changes check ✅ Passed The changed files stay within the snapshot portion of [#4732]. src/responses/state/snapshot-select.ts reuses serialized entries and builds the version-2 payload. src/responses/state.ts adopts that…
Full details: Linked Issues check

Explanation

Issue [#4732] has two coding objectives. The snapshot objective is implemented: src/responses/state/snapshot-select.ts now serializes each selected entry once, measures UTF-8 bytes, and exposes snapshotPayload; src/responses/state.ts uses that payload builder. tests/responses/responses-state-snapshot-select.test.ts covers exact output, multibyte text, escapes, entry types, and byte budgets. The router objective is not implemented. The reviewed src/router.ts still uses PROVIDER_REGISTRY.find(...) in captureRouteStaticPolicy, knownModelIdsForProvider, and routedProviderConfig, and the repository evidence does not show the required static lookup maps or their routing tests. The issue remains open, so its router requirements apply.

Resolution

Implement the [#4732] router objective in src/router.ts: add the required static registry lookup maps, replace the repeated PROVIDER_REGISTRY.find(...) and related Object.keys() scans in knownModelIdsForProvider, routedProviderConfig, and routeModelInternal with map lookups, and add automated routing tests that verify lookup integrity and behavior. Alternatively, link this PR only to a snapshot-scoped issue if the router work is intentionally excluded.

Full details: Docstring Coverage

Explanation

Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 3 files. (2 skipped: 2 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@lidge-jun
lidge-jun merged commit 0328373 into dev Oct 1, 2026
35 checks passed
@lidge-jun
lidge-jun deleted the codex/pr4732-snapshot-carry branch October 1, 2026 07:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant