perf(core): cache static registry model lookups and eliminate snapshot traversal allocations - #4732
chilung-cgu wants to merge 687 commits into
Conversation
|
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: trueNo actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository: lidge-jun/opencodex/.coderabbit.yaml Review profile: ASSERTIVE Plan: Advanced Run ID: 📒 Files selected for processing (2)
Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review. 📝 WalkthroughWalkthroughThe change optimizes bounded snapshot serialization and provider registry access. Snapshot entries are serialized once during backward selection. Router paths use precomputed maps for provider, model-ID, and alias lookups. Tests validate snapshot parsing and static model-ID discovery. ChangesRuntime efficiency improvements
Priority: ⬇️ Low Estimated code review effort: 2 (Simple) | ~15 minutes Change: Refactor 🚥 Pre-merge checks | ✅ 4 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
⏳ DRAFT
What to do
Review readiness checklist
0/4 boxes ticked. Current head: |
리뷰 · 우선순위 70 / 80이 PR은 첫째, 라우터 쪽. 지금 둘째, 응답 스냅샷 쪽. 지금 src/router.ts - REGISTRY_* 맵은 모듈 로드 시점에만 채워진다. PROVIDER_REGISTRY가 readonly 상수라서 지금은 맞지만, 나중에 런타임에 레지스트리 항목을 붙이는 길이 생기면 이 캐시는 낡은 값이 된다. 지금은 문제 없고, “정적 전제”를 주석으로 남겨 두면 이후 기여자가 덜 헷갈린다. src/router.ts knownModelIdsForProvider - 예전 코드는 transport guard를 통과한 뒤에야 registry models + hint map keys를 모았다. 새 코드도 guard 안에서 STATIC_MODEL_IDS만 읽으므로 의미는 같다. 다만 기존 slug-codec 테스트( src/responses/state.ts writeBoundedSnapshot - Array.from(states)도 여전히 O(N) 엔트리 배열을 만든다. 진짜 이득은 reverse 복사 제거보다, 전체 트리를 두 번 stringify하지 않는 쪽에 가깝다. PR 설명의 “24–48 MiB transient” 주장은 이 경로를 겨냥한 것이고, 방향은 타당하다. src/responses/state.ts payload 조립 - 손조립 JSON이 digest/skip 로직의 입력이라, 바이트가 한 글자라도 어긋나면 “같다” 판정이 깨지거나 반대로 잘못된 skip이 난다. 로컬 등가성은 확인됐지만, intake: hygiene-blocked / draft - 작성자 checklist는 4/4로 찍혀 있지만, 게이트는 여전히 missing_regression_test로 DRAFT다. “로컬에서 기존 테스트 통과”와 “이 PR이 테스트를 추가했다”는 다른 조건이다. 메인테이너의 판단이 필요한 지점
너의 추천 이 댓글은 grok-bot이 작성했습니다 |
f7ece40 to
8f5a334
Compare
8f86dd2 to
eca2882
Compare
eca2882 to
e70c08c
Compare
…#6317) Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: luvs01 <27862058+luvs01@users.noreply.github.com>
…jun#6308) Co-authored-by: luvs01 <27862058+luvs01@users.noreply.github.com>
* fix(devin): bound held signature type payloads Carry source commit 3a257a6. Count signatureType in the held UTF-16 payload budget and cap its wire bytes before UTF-8 decoding. Preserve the signed retry path below the budget, with exact byte-boundary and multibyte regression coverage. * test(devin): verify oversized-type legacy signature replay --------- Co-authored-by: luvs01 <27862058+luvs01@users.noreply.github.com>
* fix(redaction): bound XML identifying-attribute scans Carry luvs01#691 at f42e713. Replace wall-clock regression with delimiter-work accounting and preserve malformed/escaped credential coverage. * fix(redaction): recognize quoted XML tag delimiters Scan tag terminators outside quoted values, cover credential masking after embedded delimiters, and count manual character work in linear-scaling regressions.
…idge-jun#6326) Preserve display snapshots and legacy login observations while gating pool policy changes on the captured writer. Cover missing writers in compact and WebSocket paths.
…idge-jun#6328) Carries lidge-jun#6281 unchanged plus maintainer review fixes; the contributor gate re-drafted the original after the maintainer push. Co-authored-by: lonefisher <132996955+lonefisher@users.noreply.github.com>
…idge-jun#6329) Carries lidge-jun#6316 unchanged plus maintainer review fixes; the contributor gate re-drafted the original after the maintainer push. Co-authored-by: vadymhimself <11277453+vadymhimself@users.noreply.github.com>
…g row (lidge-jun#6330) Carries lidge-jun#6295 with a maintainer privacy rework: the stored reason is limited to the HTTP status plus an allowlisted Anthropic error type, so upstream message text (which can echo account identifiers or request content) never reaches the request log or usage history. Client responses are unchanged. Co-authored-by: sh940701 <visioner2168@gmail.com>
… publication (lidge-jun#6331) Carries lidge-jun#6260 with a maintainer fix: a file-loaded config keeps its file provenance after discovery inventory drift, so stale discovery is refused under the mutation coordinator instead of disabling a model in memory that a later unrelated save would persist over the operator's choice. Co-authored-by: colthreepv <2657230+colthreepv@users.noreply.github.com>
…licy (lidge-jun#6333) File-backed inventory drift rejected ordinary model reads with catalog_busy. Identical synthetic inventory succeeds on the same cached roster, ruling out row replacement and cache revision churn in the reproduction. Allow read callers to receive a detached new-arrival policy projection. Management renders disabled arrivals; other shared-fetch consumers receive only visible projected rows. Keep retained-sync and direct stale-writer refusal contracts, inventory/revision checks, and persisted merge baselines intact. Verification: eight authorized files, 80 passed / 0 failed; after adding save-safety coverage, runtime-policy and ratchet files, 24 passed / 0 failed. Typecheck and structure checks pass. Full suite and docs build were excluded by the delegated command restrictions.
…jun#6341) * fix(xai): report a current Grok CLI version on the OAuth path xAI now answers Grok OAuth requests that report a client version below 1.0.13 with HTTP 426 ("Your Grok CLI version (0.2.93) is outdated"), so every SuperGrok OAuth request failed. Report 1.0.25, the current stable Grok CLI, in x-grok-client-version and the User-Agent. Carries lidge-jun#6339. Co-authored-by: unsafe9 <24631203+unsafe9@users.noreply.github.com> * test(xai): pin Grok compatibility header regression --------- Co-authored-by: unsafe9 <24631203+unsafe9@users.noreply.github.com>
…idge-jun#6344) Carries lidge-jun#6299 with the buffering note translated into the ja, ko, ru and zh-cn Claude Code guides. Co-authored-by: foxytanuki <45069709+foxytanuki@users.noreply.github.com>
…idge-jun#6345) Carries lidge-jun#6278 with maintainer review fixes: the chip description points at the text-only quota table, and the hover bridge spans both the chip and popover widths so wide chips keep the popover open. Co-authored-by: colthreepv <2657230+colthreepv@users.noreply.github.com>
…jun#6346) PUT /api/subagent-models validated pickerOrder against visible routed slugs only, so the documented complete-picker ordering (a bare native id such as gpt-5.6-sol) could not be saved through the API. Visible, enabled native catalog rows are now accepted; disabled and unknown native ids are still rejected. Closes lidge-jun#6338
…#6351) Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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 lidge-jun#4732 onto the two-pass selector now on dev. Co-authored-by: WU, CHI-LUNG <chilung-cgu@users.noreply.github.com>
Keeps the author history on the PR branch. The tree is the dev-based rework: the router registry cache is dropped (no measurable routeModel change) and the snapshot change is reimplemented on the two-pass selector.
…6360) Carries the snapshot half of #4732: keep the per-entry strings measured by selectSnapshotEntries and join them, so a snapshot write serializes entries once instead of twice. Output is byte-identical; a pinned-bytes regression test covers it. Co-authored-by: WU, CHI-LUNG <chilung-cgu@users.noreply.github.com>
|
Thank you, @chilung-cgu. This landed on What was carried: the snapshot change. What was not carried: the static Closing as carried. Thanks again for finding the double serialization. |
Summary
PROVIDER_REGISTRYmodel definitions insrc/router.tsinto static lookup maps (REGISTRY_BY_ID,REGISTRY_STATIC_MODEL_IDS,REGISTRY_ALIAS_BY_ID), replacing O(N) array scans (.find()) and repeatedObject.keys()array allocations with O(1) lookups inknownModelIdsForProvider,routedProviderConfig, androuteModelInternal.writeBoundedSnapshotinsrc/responses/state.tsby replacing[...states].reverse()with reverse-indexed traversal overArray.from(states), and concatenating pre-serialized entries directly ({"version":2,"states":[" + serializedEntries.join(",") + "]}) instead of a second full-treeJSON.stringify, eliminating 24-48 MiB of transient heap allocations during snapshot schedules.Buffer.byteLength(JSON.stringify(entry), "utf8")) based on benchmark verification.tests/routing/router.test.tsandtests/responses/responses-state-write-amplification.test.tsensuring static registry cache lookup integrity and snapshot serialization output formatting.Verification
bun run typecheck(passed with 0 errors)bun run privacy:scan(passed)bun test tests/codex-integration/app-owned-memory.test.ts tests/routing/router.test.ts tests/lab/core-lab-boundary.test.ts tests/responses/responses-state-write-amplification.test.ts tests/codex-integration/slug-codec.test.ts(76 pass, 0 fail, 206 expect calls)Checklist
Review readiness checklist
This PR stays in draft until every box below is ticked. Tick all four boxes once the requirements are met:
All CI tests are green on my local testing.
I pushed my PR to the latest dev commit.
I resolved all correct Codex and CodeRabbit findings.
My PR is ready for review.
Summary by CodeRabbit
Performance
Reliability