Skip to content

[Bug]: Duplicate [hooks.state."…"] tables accumulate in codex-runtime-home/config.toml on every close→reopen, breaking Codex startup #3190

Closed

Description

@mubeda

Operating system

Windows 11

Orca version

1.4.33.0

Details

SUMMARY

On Windows, Orca's managed Codex config at
%APPDATA%\orca\codex-runtime-home\home\config.toml accumulates duplicate
[hooks.state."<abs-path-to-hooks.json>:::"] tables across
close/reopen cycles. Because duplicate keys/tables are invalid in TOML, the next
launch fails to parse the file and the agent will not start.
This looks like an append-instead-of-update serializer bug: hook-trust state
is re-written (appended) on shutdown rather than replaced in place, so the same
quoted-path key is emitted more than once. It is very likely compounded by the
process-lifecycle bug described in the optional second issue (a stale Orca/Codex
process surviving window close means two writers touch the same file).

Steps to reproduce

Use Codex in Orca in a workspace that has a hooks.json with a SessionStart
(session_start) hook, so Orca persists hook-trust state.
Close the Orca window.
Reopen Orca (or relaunch the Codex agent in the same workspace).
Repeat the close→reopen cycle a few times.

Actual behavior
Codex fails to start and emits a TOML parse error pointing at a [hooks.state."…"]
table. Example (line number varies as duplicates accumulate; username redacted):

    |
145 | [hooks.state."C:\\Users\\<USER>\\AppData\\Roaming\\orca\\codex-runtime-home\\home\\hooks.json:session_start:0:0"]
    |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Inspecting config.toml shows the same [hooks.state."…hooks.json:session_start:0:0"]
header present two or more times. Removing the duplicate header(s) and relaunching
resolves it immediately — until the next close→reopen cycle reintroduces the duplicate.
Expected behavior

Hook-trust state should be updated in place (one table per unique hook key),
never appended as a duplicate.
If a malformed/duplicate config.toml is encountered on startup, Orca should
surface a clear, recoverable error (and ideally self-heal the managed file it owns)
rather than failing the agent launch.

Suspected root cause

The [hooks.state] serializer appends a new table per shutdown instead of
replacing the existing entry keyed by the absolute hooks.json path + event +
indices.
A stale Orca/Codex process surviving window close (see optional second issue)
causes overlapping writes to the same config.toml, increasing the chance of
duplication.

Activity

  1. added
    bug
    on May 29, 2026
  2. nwparker commented on May 29, 2026

    @nwparker
    Contributor

    Opened PR #3196 with a focused fix for the duplicate managed Codex hook-state tables: #3196

    What I reproduced:

    • a Windows-style managed codex-runtime-home\home\hooks.json:session_start:0:0 key duplicated in config.toml
    • current upsert replaced only the first matching table and left the later duplicate in place, so the malformed TOML never self-healed

    What the PR changes:

    • the Codex trust writer now finds every matching [hooks.state."..."] block for a key
    • it replaces the first block, removes later duplicates, preserves unrelated hook-state tables, and keeps enabled = false if any duplicate copy had been disabled

    Validation:

    • failing regression reproduced before the fix
    • pnpm exec vitest run --config config/vitest.config.ts src/main/codex/config-toml-trust.test.ts src/main/codex/hook-service.test.ts src/main/agent-hooks/installer-utils-remote.test.ts (89 tests)
    • pnpm run typecheck:node
    • pnpm exec oxlint src/main/codex/config-toml-trust.ts src/main/codex/config-toml-trust.test.ts
    • git diff --check
    • git merge-tree --write-tree origin/main HEAD

    This should repair already-duplicated managed config files on the next trust upsert/install path. #3191 may still need a separate Windows lifecycle fix if stale processes remain after window close, but this removes the deterministic config-corruption path.

  3. nwparker commented on May 30, 2026

    @nwparker
    Contributor

    Oh wait, @brennanb2025 might have fixed this one yesterday

  4. nwparker commented on May 30, 2026

    @nwparker
    Contributor

    @mubeda can you update to the latest Orca version?

  5. brennanb2025 commented on May 30, 2026

    @brennanb2025
    Contributor

    Thanks for the detailed report @mubeda, I reproduced the important failure mode here: once the managed Codex config.toml contains duplicate [hooks.state."..."] tables, Orca’s trust writer was updating only the first matching table and leaving later duplicates behind, so the file stayed invalid and Codex could not start.

    PR #3196 has been updated to make the managed trust writer self-heal this state. On the next Codex hook install/trust sync, Orca now collapses duplicate trust tables for the same key, preserves unrelated hook state, and keeps enabled = false if any duplicate copy had been disabled. We also added regression coverage for the Windows-style codex-runtime-home\home\hooks.json:session_start:0:0 case and the restart-install path.

    This will be included in the next stable release!

  6. mubeda commented on Jun 1, 2026

    @mubeda
    Author

    Hi there! You are welcome, just tried the latest version 1.4.38 , i updated current installation but still facing the same error:
    \AppData\Roaming\orca\codex-runtime-home\launch\host\system\home\config.toml:152:14: duplicate key
    \AppData\Roaming\orca\codex-runtime-home\home\hooks.json:session_start:0:0".

    I uninstalled the application and installed it again.
    Same problem.

  7. mubeda commented on Jun 1, 2026

    @mubeda
    Author

    Also i notice, not sure if related with this issue, that the app , after closed in windows do not starts again. i need to kill the orca process in other to launch it again

  8. brennanb2025 commented on Jun 1, 2026

    @brennanb2025
    Contributor

    I'm looking into it! I do think there were a few separate PRs related to Codex account switching that were pretty involved that could have re-introduced some issues, sorry about that. We'll get a fix out in the next release.

  9. brennanb2025 commented on Jun 5, 2026

    @brennanb2025
    Contributor

    Hi @mubeda , sorry about the delay - this was fixed in the latest release. Please let me know if you run into any more trouble. Appreciate your patience, we're actively working on increasing reliability for Windows.

  10. mubeda commented on Jun 5, 2026

    @mubeda
    Author

    i just cleanup and uninstall everything and removed manually the C:\Users\MYYSER\AppData\Roaming\orca (the uninstaller do not delete it so if you install and launch codex the error appears first start )
    I installed the new version 1.4.48.0 . The first time works, the second time i open a codex terminal for a different project while the other is still open i got the error again.

    \AppData\Roaming\orca\codex-runtime-home\home\config.toml:147:14: duplicate key
    \AppData\Roaming\orca\codex-runtime-home\home\hooks.json:session_start:0:0"]

    before installed i ask codex to review my .codex folder settings as well the one i have in the repo. No problem founds on my settings files.

  11. beiton-06 commented on Jun 20, 2026

    @beiton-06

    @brennanb2025 @Jinwoo-H

    I can confirm this issue is still present in V1.4.81-rc2. The duplicate [hooks.state.*] keys continue to accumulate, and I've encountered a new critical symptom that may be relevant to the ongoing fix in #4710:

    New Symptom: batchWrite Persistence Failure

    When users apply the read-only workaround (attrib +R) to prevent further duplicate key corruption, the TUI fails to persist legitimate hook trust updates with:

    Failed to trust hooks: config/batchWrite failed while updating hook trust in TUI: 
    config/batchWrite failed: failed to persist config.toml (code -32603)
    

    This creates an unrecoverable UX trap:

    • Writable config → Duplicate keys accumulate → CLI startup fails
    • Read-only config → TUI cannot trust new hooks → batchWrite fails with -32603

    Reproduction Context (V1.4.81-rc2)

    • OS: Windows
    • Trigger: Opening multiple Codex terminals for the same project concurrently (different from @mubeda's report above)
    • The serializer still appends double-quote escaped keys ([hooks.state."C:\\..."]) without deduplicating against existing single-quote literal keys ([hooks.state.'C:\...'])

    Suggestion for #4710

    Please ensure the retry/self-heal logic in #4710 also handles:

    1. Semantic deduplication across quoting styles (single vs double quote)
    2. Graceful error messaging when the file is read-only, instead of the generic -32603 code
    3. Atomic write operations to prevent corruption during concurrent multi-project access

    Happy to provide sanitized config files or test any upcoming patches. Thank you for your work on Windows reliability! 🙏

  12. mubeda commented on Jun 20, 2026

    @mubeda
    Author

    yes, i still have this issue, the only way i avoided this problem is not trusting hooks anymore. Before ,I was fixing manually config.toml removing the duplicated hooks.

  13. added theissue type on Jul 12, 2026
  14. AmethystLiang commented on Aug 18, 2026

    @AmethystLiang
    Contributor

    thanks for reporting. looking into it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugos:Windows

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions