Skip to content

trace-codex mvp#2

Merged
Andrew Kent (realark) merged 17 commits into
mainfrom
ark/trace-codex-mvp
Jun 29, 2026
Merged

trace-codex mvp#2
Andrew Kent (realark) merged 17 commits into
mainfrom
ark/trace-codex-mvp

Conversation

@realark

@realark Andrew Kent (realark) commented Jun 22, 2026

Copy link
Copy Markdown
Collaborator

@realark Andrew Kent (realark) changed the title trace-codex mvp trace-codex Jun 23, 2026
@realark Andrew Kent (realark) force-pushed the ark/trace-codex-mvp branch 4 times, most recently from f0eddc7 to ef15805 Compare June 23, 2026 17:07
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).
@realark Andrew Kent (realark) force-pushed the ark/trace-codex-mvp branch 2 times, most recently from 9dc325a to 6eb6748 Compare June 23, 2026 22:06
@realark Andrew Kent (realark) marked this pull request as ready for review June 24, 2026 17:42
@realark Andrew Kent (realark) changed the title trace-codex trace-codex mvp Jun 24, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. tests are easier to reason about
  2. snapshots in tests are nicer
  3. 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)

@realark Andrew Kent (realark) merged commit a8e84e5 into main Jun 29, 2026
4 checks passed
@realark Andrew Kent (realark) deleted the ark/trace-codex-mvp branch June 29, 2026 16:47
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.

2 participants