trace-codex mvp#2
Merged
Merged
Conversation
hook data lacks LLM spans and timestamps, so we must use the session transcript to build a useful trace
43a54cd to
fe15e74
Compare
f0eddc7 to
ef15805
Compare
worker auto-flushes on an empty queue already so this isn't needed. the only time we want to call flush should also require blocking (when we stop event and we are configured to block).
ef15805 to
4157ec1
Compare
9dc325a to
6eb6748
Compare
6eb6748 to
0b08f64
Compare
Abhijeet Prasad (AbhiPrasad)
approved these changes
Jun 29, 2026
Abhijeet Prasad (AbhiPrasad)
left a comment
Member
There was a problem hiding this comment.
It took me a while to review this because I wanted to take some time to land on what I think is ideal here. But I feel like that would block a lot, so I'm approving to get this shipped and landed.
As a follow up though, I would vastly prefer if we adopted more of a state machine architecture for this.
class CodexEventProcessor implements EventProcessor {
private state: CodexState;
private runtime: EffectRunner;
async process(event: EnqueueEvent) {
const domainEvents = await this.expandHookIntoDomainEvents(event);
for (const domainEvent of domainEvents) {
const result = reduceCodexState(this.state, domainEvent);
this.state = result.state;
await this.runtime.run(result.effects);
}
}
async flush() {
const result = reduceCodexState(this.state, { type: "FlushRequested" });
this.state = result.state;
await this.runtime.run(result.effects);
}
}This gives us a bunch of benefits:
- tests are easier to reason about
- snapshots in tests are nicer
- side effects are easier to track
the state machines themselves can be hierarchal
CodexSessionMachine
├── Root lifecycle
├── Main ScopeMachine
│ ├── TurnMachine(s)
│ │ ├── LlmMachine
│ │ └── ToolMachine(s)
│ └── CompactionMachine(s)
└── Subagent ScopeMachine(s)
├── TurnMachine(s)
├── LlmMachine
└── ToolMachine(s)
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.
initial trace codex. supports:
kitchen sink trace: https://www.braintrust.dev/app/Braintrust%20SDKs/p/andrew-coding-agent/trace?object_type=project_logs&object_id=ebabe4b7-25b2-4884-8d85-55fa6e2e6014&r=ed6f0665-4fd9-4f7b-ad8e-e928ec8421b1&s=ed6f0665-4fd9-4f7b-ad8e-e928ec8421b1