Skip to content

Key the codex session on the instance, not the thread - #194

Merged
vitramir merged 1 commit into
mainfrom
fix/codex-session-per-instance
Aug 19, 2026
Merged

Key the codex session on the instance, not the thread#194
vitramir merged 1 commit into
mainfrom
fix/codex-session-per-instance

Conversation

@vitramir

Copy link
Copy Markdown
Contributor

Agent state is instance-scoped: an instance serves many threads and they share one conversation. The codex path keyed its session by platform thread, so a reply arriving on a different thread began with no memory of the request that started it.

Seen with a coordinator that polls three agents. Asked on the user's thread, it sent the topic to @ben, @tomas and @viktor — then @ben replied on the poll thread, and the coordinator woke in a conversation that had never seen the topic, the other two profiles, or the thread it owed an answer to. So it went excavating:

agyn threads list
agyn threads show --thread poll-ai-saas-tax-ben     # no such command
agyn threads --help && agyn threads show --help
agyn threads read --thread ... --thread ... --thread ...
find ~ -maxdepth 4 -type f -name '*agyn*'
cat /root/.agyn/threads.json
cat /root/.agyn/codex/thread-mapping/*.json

That is the same bug #161 fixed for agn, whose comment already describes it: "an agent that asked another agent a question could not read the answer in context". The port to codex was never done — 7fc41ee predates it.

Change

ensureCodexThread takes no thread and keys on d.selfID(), matching agn's ThreadID: d.selfID(). The mapping and its store are keyed and named by instance throughout (instance_id on disk), so the names no longer say thread where they mean instance. Which thread a message came from is in its header, as before.

A stale per-thread mapping file is simply never looked up; the instance starts one session and resumes it after a restart, from the same persisted store.

Tests

New: TestEnsureCodexThreadIsOneConversationAcrossThreads — repeated calls return one codex thread, start it exactly once, and store it under the instance. Existing resume/start tests now assert the instance key. Full suite green.

Agent state is instance-scoped: an instance serves many threads and they
share one conversation. Keying the codex thread by platform thread meant
a reply arriving on a different thread began with no memory of the
request that started it -- a coordinator that asked three agents a
question woke on each reply somewhere that had never seen the question,
and went looking through the CLI for the topic and the thread it owed an
answer to. Which thread a message came from is in its header.

The agn path was keyed this way in #161; this is the same change for
codex. The mapping is keyed and stored by instance id throughout, so the
names no longer say thread where they mean instance.
@vitramir
vitramir merged commit f0bc2aa into main Aug 19, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant