No Codex session found within 120000ms for cwd xxxxxx; refusing fallback.
What version of HAPI is running?
hapi version: 0.16.1
What platform is your computer?
Microsoft Windows NT 10.0.26200.0 x64
What issue are you seeing?
After installing hapi, the hapi server is already running normally, but when I run hapi codex, an error occurs, and it cannot be used normally. The codex process is killed after two minutes. The error message is as follows: No Codex session found within 120000ms for cwd xxxxxx; refusing fallback. [codex-local]: No Codex session found within 120000ms for cwd xxxxxxxx; refusing fallback. [codex-local]: Local Codex process failed: Process exited with code: 1 Failed to execute: "D:\software\DevTools\nvm\v22.22.0\node_modules\@twsxtd\hapi\node_modules\@twsxtd\hapi-win32-x64\bin\hapi.exe" "codex" Binary exited with status 1. Command failed: D:\software\DevTools\nvm\v22.22.0\node_modules@twsxtd\hapi\node_modules@twsxtd\hapi-win32-x64\bin\hapi.exe codex
What steps can reproduce the bug?
On Windows with hapi v0.16.1 and codex-cli v0.114.0, hapi codex --dangerously-bypass-approvals-and-sandbox starts Codex, but then exits after 120s with:
No Codex session found within 120000ms for cwd ...; refusing fallback.
From the logs, Codex is actually starting (session_init: codex_core::codex: new), but instead of creating a new rollout file under ~/.codex/sessions/..., it resumes an existing rollout for the same cwd. hapi appears to only accept a newly created session whose timestamp is within the startup window, so it treats this as a failure and kills the process.
codex alone works, and hapi codex exec ... also works. The problem seems specific to interactive hapi codex local mode and its session scanner logic not handling Codex auto-resume behavior.
What is the expected behavior?
No response
Additional information
Windows11
hapi v0.16.1
codex-cli v0.114.0
Windows Terminal powershell7
Thanks for the detailed report. I checked the current codebase, and the behavior you described matches the local hapi codex startup logic.
When HAPI starts local Codex without a known session ID, it creates a session scanner that tries to discover a Codex rollout by cwd and startup time. In that scanner, a candidate is only accepted if the session_meta.timestamp exists, matches the same cwd, is not earlier than HAPI startup, and is still inside the 120000 ms window. If nothing matches, it emits the exact No Codex session found within 120000ms for cwd ...; refusing fallback. error and exits. I did not find fallback logic here for the case where Codex auto-resumes an older rollout file for the same cwd instead of creating a fresh one, so your analysis is consistent with the current implementation.
There is also a dedicated hapi codex resume <sessionId> code path. That path passes a known session ID directly into both the Codex launch and the scanner, so it does not rely on this cwd + startup-timestamp discovery logic.
Relevant code:
cli/src/codex/codexLocalLauncher.ts:55- localhapi codexstartscreateCodexSessionScanner(...)withcwdand current startup timestampcli/src/codex/utils/codexSessionScanner.ts:187- scanner fails after the start window and emitsNo Codex session found within ...; refusing fallback.cli/src/codex/utils/codexSessionScanner.ts:323- candidate matching requires samecwd, a parsedsession_meta.timestamp, andtimestamp >= startupTimestampMscli/src/codex/utils/codexSessionScanner.ts:339- older session files are explicitly rejected before the 2 minute window checkcli/src/commands/codex.ts:26- dedicatedhapi codex resume <sessionId>command pathcli/src/codex/utils/codexSessionScanner.test.ts:77- current tests cover date-window matching; I did not find a test for reusing an older rollout file for the samecwd
HAPI Bot
https://github.com/tiann/hapi/commit/a30bb398e1e5b24c2b8cb863ee4e1aaf0d7cc65d