test(rotation): prove concurrent canonical TUI sessions keep their state - #643
Conversation
#639 dropped the per-session shadow home for interactive TUI routing, so two concurrent sessions now share the real Codex home. Review flagged that as an unguarded race. This settles it with evidence instead of a lock. The test launches two canonical TUI sessions, has each write its own session file into the shared home, and asserts both survive. It also asserts the two run windows actually intersect -- without that, the sessions could serialise and the test would pass while proving nothing. Verified the test can fail: injecting a wipe of the sessions directory makes it fail on the clobbered session, so it is a real guard rather than a vacuous one. No lock is added, deliberately. Nothing on this path copies or syncs state, so there is nothing to clobber -- the two hazards the wrapper does own are already handled (the shim sweep skips live PIDs via isProcessAlive, and the helper status file is display-only, read by rotation/status rather than used for lifecycle). Serializing interactive sessions would regress against the stock CLI, which lets you run two `codex` sessions at once. Docs were stale after #639: storage-paths, architecture, and configuration all described runtime rotation as always using a shadow CODEX_HOME. They now describe the canonical-home TUI path and its concurrency semantics. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (4)
📜 Recent review details⏰ Context from checks skipped due to timeout. (1)
🧰 Additional context used📓 Path-based instructions (12)docs/**/*.md📄 CodeRabbit inference engine (docs/STYLE_GUIDE.md)
Files:
docs/{index.md,getting-started.md,faq.md,architecture.md,features.md,configuration.md,troubleshooting.md,privacy.md,upgrade.md}📄 CodeRabbit inference engine (docs/DOCUMENTATION.md)
Files:
docs/**/*.{md,mdx}📄 CodeRabbit inference engine (docs/troubleshooting.md)
Files:
**/*📄 CodeRabbit inference engine (AGENTS.md)
Files:
docs/**⚙️ CodeRabbit configuration file
Files:
test/**/*.test.ts📄 CodeRabbit inference engine (test/AGENTS.md)
Files:
test/**/codex-bin-wrapper.test.ts📄 CodeRabbit inference engine (test/AGENTS.md)
Files:
**/*.{ts,js,mjs}📄 CodeRabbit inference engine (AGENTS.md)
Files:
test/**/*.ts📄 CodeRabbit inference engine (AGENTS.md)
Files:
**/*.{js,ts,mjs,cjs}📄 CodeRabbit inference engine (README.md)
Files:
test/**⚙️ CodeRabbit configuration file
Files:
docs/reference/**/*.md📄 CodeRabbit inference engine (docs/STYLE_GUIDE.md)
Files:
🧠 Learnings (3)📓 Common learnings📚 Learning: 2026-06-04T06:14:18.093ZApplied to files:
📚 Learning: 2026-06-04T06:14:24.975ZApplied to files:
🪛 ast-grep (0.44.1)test/codex-bin-wrapper.test.ts[warning] Importing child_process exposes a command-execution surface; ensure any command/argument built from input is validated, and prefer execFile/spawn with an argument array over exec. (detect-child-process-typescript) 🪛 LanguageTooldocs/configuration.md[grammar] ~143-~143: Ensure spelling is correct (QB_NEW_EN_ORTHOGRAPHY_ERROR_IDS_1) 🔇 Additional comments (5)
📝 WalkthroughMinor-risk documentation and regression-test PR; no runtime code or locking changes are introduced. It covers potential session-state data loss by verifying concurrent canonical-home TUI sessions preserve both files, with a regression test confirming true overlap and failure under injected deletion; no security changes are involved. Review should focus on the architectural decision to route TUI sessions through the canonical
Walkthroughthe documentation clarifies canonical Changescanonical tui home behavior
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
Suggested labels: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
✨ Simplify code
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
test/codex-bin-wrapper.test.tsOops! Something went wrong! :( ESLint: 10.0.0 Error: The 'jiti' library is required for loading TypeScript configuration files. Make sure to install it. 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 |
Two fixes that change where the official Codex CLI keeps its state, plus a diagnostic that can now repair the first instead of only reporting it. Minor rather than patch: behaviour changes, it is not purely corrective. The wrapper now writes cli_auth_credentials_store into ~/.codex/config.toml at first run and on wrapper startup, where before it only did so on switch or login. 2.7.1 was explicitly "no new features and no configuration changes"; this one does change configuration behaviour, and documents a previously undocumented opt-out. Closes ndycode#641. Landed as ndycode#642, ndycode#639, and ndycode#643.
Summary
Closes the one review finding left open when #639 merged: with the per-session shadow home dropped for interactive TUI routing, two concurrent sessions share the real Codex home, and review flagged that as an unguarded race on session/SQLite state.
This settles it with evidence rather than a lock, and fixes the docs #639 left stale.
What Changed
A concurrency regression test (
test/codex-bin-wrapper.test.ts) — launches two canonical TUI sessions, each writing its own session file into the shared home, and asserts both survive.Two things make it a real test rather than a green checkmark:
fs.rmSync(sessionsDir, …)into the fake binary makes it fail on the clobbered session (ENOENT … beta.jsonl). Reverted after confirming.Docs (
storage-paths.md,architecture.md,configuration.md) — all three still described runtime rotation as always using a shadowCODEX_HOME. They now describe the canonical-home TUI path, thatconfig.tomlis never rewritten on it, and the concurrency semantics.Why no lock
The review suggested either a regression test or a single-instance/flock design. I took the first, because the evidence says the second would be actively wrong:
cpSync(force: true)for session directories — a genuine last-writer-wins step that no longer exists.sweepStaleRuntimeRotationAppServerShimDirsskips live PIDs viaisProcessAlive, and the helper status file is display-only (read byrotation/status; helper lifecycle uses the child handle, so nothing can be orphaned).codexsessions at once. A lock would trade a non-existent race for a real usability loss.If a reviewer disagrees, the concrete counter-example to produce is a state file that one session loses to another on this path — the test above is the harness for it.
Validation
npm run lintnpm run typechecknpm test— 335 files, 5270 passed, 0 failednpm test -- test/documentation.test.tsnpm run buildRisk and Rollback
🤖 Generated with Claude Code
note: greptile review for oc-chatgpt-multi-auth. cite files like
lib/foo.ts:123. confirm regression tests + windows concurrency/token redaction coverage.Greptile Summary
this pr documents canonical-home tui routing and adds a concurrent-session regression test.
Confidence Score: 4/5
the pr appears safe to merge, with a non-blocking concurrency coverage gap around genuinely shared codex state.
the new vitest case proves process overlap and retention of two independent files, but it cannot detect races affecting shared sqlite, session-index, or observability state; no production or token-handling code changes.
Files Needing Attention: test/codex-bin-wrapper.test.ts, docs/reference/storage-paths.md
Important Files Changed
Prompt To Fix All With AI
Reviews (1): Last reviewed commit: "test(rotation): prove concurrent canonic..." | Re-trigger Greptile
Context used: