Skip to content

refactor(responses,codex): split state and shim behind facades - #4642

Merged
lidge-jun merged 11 commits into
codex/m2k-l2-ratchetfrom
codex/m2k-l3-state-shim
Sep 14, 2026
Merged

lidge-jun merged 11 commits into
codex/m2k-l2-ratchetfrom
codex/m2k-l3-state-shim

Conversation

@lidge-jun

Copy link
Copy Markdown
Owner

Summary

src/responses/state.tssrc/codex/shim.ts를 파사드로 남기고 리프 모듈로 나눈다. 순수 이동이며 로직·식별자·문자열을 바꾸지 않았다. 두 파일의 공개 export 표면은 이동 전과 동일하므로 소비자의 import 경로는 하나도 바뀌지 않는다.

파일 새 리프
src/responses/state.ts 2,432 1,355 state/replay-fingerprint.ts 80, state/snapshot-codec.ts 103, state/spill-failure.ts 118, state/temp-recovery.ts 257, state/spill-queue.ts 664
src/codex/shim.ts 2,466 1,246 shim-templates.ts 265, shim-fingerprint.ts 222, shim-state-file.ts 151, shim-probe.ts 367, shim-restore-lock.ts 169, shim-inspect.ts 175

모듈 스코프 가변 상태는 소유 모듈 하나에만 둔다. states, 바이트 회계, stateRevision, loaded, persistTimer, replayOverlapSkips는 파사드가 계속 소유하고 큐는 store 핸들로 접근한다. ESM live binding은 밖에서 쓸 수 없어서 소유권을 옮기면 조용히 갈라지기 때문이다. 스필 카운터는 spill-failure가 소유하고 responseStateMetrics가 getter로 읽는다.

shim.ts에서 writeShimfindWindowsCodexTargets는 남겼다. tests/codex-integration/codex-shim.test.ts가 이 파일 원문을 텍스트로 읽어 BOM+PowerShell 빌더 호출, const gitBashLauncher = join(dir, "codex");, for (const path of [cmd, ps1, gitBashLauncher])toContain으로 검사한다. 빌더 정의만 shim-templates.ts로 옮겼고 호출부는 그대로다. lastShimDiscoveryError를 탐색부와 설치부가 양쪽에서 쓰기 때문에 findCodexOnPath도 남겼다.

Verification

  • bun scripts/structure-ssot.tsstructure/ SSOT checks passed
  • bun scripts/file-size-ratchet.tsfile-size ratchet passed
  • Bun.Transpiler 구문 검사 15개 파일 통과
  • 파사드 export 표면 대조(origin/dev 기준): shim.ts 23 → 23, state.ts 38 → 38, 누락 0
  • 로컬 typecheck·full suite·install은 실행하지 않았다. 이 워크트리에 node_modules가 없고 사용자 환경에서 스위트를 돌리지 않는 제약이 있어, 타입 해석과 런타임 회귀는 이 PR head의 hosted CI가 증거다.

알려진 동작 차이 하나를 남긴다. clearResponseStateMemoryForTests가 이제 resetSpillQueueForTests()를 거치면서 메모리 리셋 시에도 큐 바이트 회계가 0으로 내려간다. 원본은 full clear에서만 그랬다. 테스트 전용 헬퍼라 런타임 경로에는 영향이 없지만 CI에서 확인이 필요하다.

Checklist

  • Scope stays focused and avoids unrelated cleanup.
  • Docs or release notes were updated when needed.
  • Security-sensitive changes were reviewed for secrets, auth, and unsafe defaults.

Pure move. state.ts 2432 -> 1355 with five leaves under src/responses/state/, shim.ts 2466 -> 1246 with six shim-* leaves. Public export surfaces are byte-identical in name; consumers keep their import paths.
@lidge-jun
lidge-jun requested a review from Ingwannu as a code owner September 14, 2026 15:31
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 14, 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-09-14T15:36:22.535205Z 913e0d0 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.

@coderabbitai

coderabbitai Bot commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

🗂️ Base branches to auto review (2)
  • ^dev$
  • ^preview$

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Advanced

Run ID: 38e6cf75-272b-4dd5-8f31-d72ccf94890e

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

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.

@github-actions github-actions Bot added chore Maintenance, CI, tests, refactors, or build changes (not a user-facing bug or feature). intake: hygiene-blocked Deterministic PR hygiene checks failed labels Sep 14, 2026
@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Deterministic hygiene checks failed.

  • missing_regression_test — Behavior changed under src/ or gui/src/ without a test change. Add focused coverage or obtain test-exception-approved.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 913e0d071f

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/codex/shim.ts
Comment on lines 15 to +19
import { isWslRuntime, wslAutomountRoot } from "./home";
import { truncateRetainedUtf8 } from "../lib/admission";
import {
buildUnixCodexShim,
buildWindowsCodexShim,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Update the Codex ownership documents for the split

This moves substantial shim responsibilities into six new modules, but the commit changes none of the documents mapped to src/codex/ in structure/INDEX.md; for example, structure/runtime.md still attributes the Codex autostart shim solely to src/codex/shim.ts. Update the mapped structure documents so maintainers can locate the new owners for templates, fingerprints, state, probing, locking, and inspection.

AGENTS.md reference: src/AGENTS.md:L10-L11

Useful? React with 👍 / 👎.

Comment thread src/responses/state.ts
Comment on lines +18 to +21
export type { ResponseStateTempRecoveryResult, ResponseStateTempRecoveryOptions } from "./state/temp-recovery";
export { recoverStaleResponseStateTemps, reclaimAbandonedResponseStateTemps, inspectAbandonedResponseStateTemps, sweepAbandonedResponseStateTemps } from "./state/temp-recovery";
import { recoverStaleResponseStateTemps } from "./state/temp-recovery";
export type { ResponseSpillWriteFailureCode, ResponseSpillWriteStatus, ResponseSpillWriteFailureOrigin } from "./state/spill-failure";

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Update the Responses ownership documents for the split

The response-state implementation is redistributed across five new leaf modules without updating any structure document mapped to src/responses/, leaving the repository's architecture and ownership references unaware of the new queue, recovery, codec, failure-state, and replay-fingerprint owners. Update the mapped structure documents as part of this source-area change.

AGENTS.md reference: src/AGENTS.md:L10-L11

Useful? React with 👍 / 👎.

@github-actions

github-actions Bot commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

✅ READY

  • all PR quality gates passed.

Hygiene

Deterministic PR hygiene checks passed.

@github-actions
github-actions Bot marked this pull request as draft September 14, 2026 15:40
@lidge-jun

Copy link
Copy Markdown
Owner Author

리뷰 · 우선순위 42 / 80

이 PR은 제품 동작을 바꾸려는 기능이 아니라, 너무 커진 두 godfile을 파사드 + 리프 모듈로 나누는 정리입니다. src/responses/state.ts(약 2432줄→1355줄)에서 리플레이 지문·스냅샷 코덱·스필 실패·임시 복구·스필 큐를 src/responses/state/ 아래로 옮기고, src/codex/shim.ts(약 2466줄→1246줄)에서 템플릿·지문·상태 파일·프로브·복원 락·inspect를 shim-*.ts로 옮깁니다. 공개 export 이름과 소비자 import 경로는 그대로 둔다고 명시했고, writeShim/findWindowsCodexTargets/findCodexOnPath처럼 통합 테스트가 파일 원문을 문자열로 검사하는 부분은 파사드에 남겨 두었습니다.

지금 dev가 최적화하는 축은 #4546 cost-guard 스택(이미 wpc/wpe/wpf가 HEAD에 있음)과 별도로, m2k 쪽 godfile 분해·파일 크기 래칫입니다. 이 PR base는 codex/m2k-l2-ratchet(#4636)이고, 그 아래는 codex/m2k-l1-roadmap(#4635, base=dev)입니다. 즉 #4635#4636#4642 스택의 3층이며, dev에 단독으로 올릴 수 있는 PR이 아닙니다. 작성자가 밝힌 알려진 차이 하나는 테스트 헬퍼 clearResponseStateMemoryForTests가 이제 큐 바이트 회계까지 0으로 내린다는 점입니다. 런타임 경로가 아니라고 해도, hygiene가 missing_regression_test로 막힌 이유와 맞닿아 있습니다.

우선순위 숫자는 「기능 가치」보다 「스택·게이트 상태」를 반영했습니다. 분해 방향 자체는 m2k 로드맵과 맞고, SSOT/래칫을 로컬에서 통과했다고 적혀 있습니다. 다만 CI는 intake:hygiene-blocked이고 hygiene 실패 코드가 missing_regression_test(src 변경에 테스트 변경 없음)이며, enforce-target도 base가 dev가 아니라 실패했습니다. 리프 중 spill-queue.ts(664줄)·shim-probe.ts(367줄)는 여전히 커서, 래칫이 「파사드만 줄이고 리프는 다음 라운드」인지도 문서/후속 PR과 맞춰야 합니다.

src/responses/state.ts / src/codex/shim.ts - 순수 이동이라 해도 hygiene는 src 변경 + 테스트 미변경을 missing_regression_test로 차단한다. 예외 라벨/test-exception-approved를 받거나, 파사드 re-export·헬퍼 동작(특히 clearResponseStateMemoryForTests의 큐 회계 리셋)을 고정하는 최소 테스트를 추가해야 한다.

clearResponseStateMemoryForTests - 본문에 적힌 동작 차이는 테스트 전용이라고 해도, 「순수 이동」 주장과 충돌한다. 의도적 변경이면 테스트로 고정하고 PR 요약의 「로직을 안 바꿨다」 문장을 고친다.

src/responses/state/spill-queue.ts (약 664줄) / src/codex/shim-probe.ts (약 367줄) - 파사드는 줄었지만 큰 리프가 남는다. m2k 래칫 기준에 이미 통과하는지, 다음 레이어 몫인지 로드맵(#4635)과 한줄로 맞춰 두면 리뷰어가 헷갈리지 않는다.

모듈 스코프 가변 상태 소유권 - ESM live binding 때문에 파사드가 states/바이트 회계 등을 계속 소유한다는 설명은 타당하다. 다만 리프↔파사드 순환 import나 이중 초기화가 없는지 hosted CI의 typecheck/테스트가 끝날 때까지 머지를 미루는 편이 맞다.

enforce-target / base=codex/m2k-l2-ratchet - dev 직행이 아니다. #4635·#4636이 먼저 랜딩되어야 이 PR의 타깃 게이트가 의미 있다.

메인테이너의 판단이 필요한 지점

너의 추천
지금은 머지하지 말고 hygiene부터 푼다. 가장 싼 길은 clearResponseStateMemoryForTests 큐 회계 리셋을 고정하는 작은 테스트 추가(또는 명시적 test-exception)다. 그다음 #4635#4636#4642 순으로만 올린다. dev에 리베이스해서 혼자 넣으려 하지 말 것.

이 댓글은 grok-bot이 작성했습니다

Pure move. inject.ts 2342 -> 987 with five leaves, catalog/sync.ts 2698 -> 52 with seven leaves. INV-TOML-01 moves to inject/config-toml.ts and INV-AGENT-01 to catalog/subagent-roster.ts. Three source oracles that read these files as text are repointed in the same commit.
@lidge-jun lidge-jun added the test-exception-approved Maintainer approved a non-automated regression-test exception label Sep 14, 2026
@github-actions github-actions Bot removed the intake: hygiene-blocked Deterministic PR hygiene checks failed label Sep 14, 2026
@github-actions
github-actions Bot marked this pull request as ready for review September 14, 2026 16:01
Pure move. routing.ts 3507 -> 1475 with six leaves, quota.ts 3313 -> 558 with five leaves. Dispatchers that would close a cycle stay on the facade. Retry budget scope is unchanged; no new attempt counter exists in any leaf.
Three identifiers lost their binding when the leaves were cut: the spill write-status types were re-exported from state.ts but never imported for local use, snapshot-codec lost OcxProviderContinuationState, and spill-queue lost existsSync. Caught by the translator-budget typecheck fixture on CI.
@github-actions github-actions Bot added intake: hygiene-blocked Deterministic PR hygiene checks failed and removed test-exception-approved Maintainer approved a non-automated regression-test exception labels Sep 14, 2026
@github-actions
github-actions Bot marked this pull request as draft September 14, 2026 16:27
The inject and catalog leaves imported six symbols from modules that never exported them. Each one is re-pointed at where it is actually defined: parsing, account-models, subagent-roster, paths, desired-state. Import paths only; no declaration moved.
…ta split

Fifteen symbols lost their binding: leaves that defined a symbol never exported it, quota type imports pointed at src/types instead of providers/quota-types, and isModelDetourAffinityScope lost its definition entirely while its call site survived. Imports and exports only; no declaration was moved or rewritten.
@lidge-jun lidge-jun added the test-exception-approved Maintainer approved a non-automated regression-test exception label Sep 14, 2026
@github-actions github-actions Bot removed the intake: hygiene-blocked Deterministic PR hygiene checks failed label Sep 14, 2026
The leaf sits one directory deeper than routing.ts, so ../config resolved to src/codex/config, which does not exist. Every test shard that loaded the routing graph failed at import time.
@github-actions
github-actions Bot marked this pull request as ready for review September 14, 2026 16:44
refactor(codex,providers): split routing and quota behind facades
refactor(codex): split inject and catalog sync behind facades
@github-actions github-actions Bot removed the test-exception-approved Maintainer approved a non-automated regression-test exception label Sep 14, 2026
@lidge-jun
lidge-jun merged commit ccb7454 into codex/m2k-l2-ratchet Sep 14, 2026
27 checks passed
@lidge-jun
lidge-jun deleted the codex/m2k-l3-state-shim branch September 14, 2026 17:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

chore Maintenance, CI, tests, refactors, or build changes (not a user-facing bug or feature).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant