Key the codex session on the instance, not the thread - #194
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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,@tomasand@viktor— then@benreplied 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:That is the same bug
#161fixed 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 —7fc41eepredates it.Change
ensureCodexThreadtakes no thread and keys ond.selfID(), matching agn'sThreadID: d.selfID(). The mapping and its store are keyed and named by instance throughout (instance_idon 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.