Skip to content

feat(runtime): Add durable conversation execution profiles#890

Open
dcramer wants to merge 12 commits into
mainfrom
codex/shared-conversation-runtime
Open

feat(runtime): Add durable conversation execution profiles#890
dcramer wants to merge 12 commits into
mainfrom
codex/shared-conversation-runtime

Conversation

@dcramer

@dcramer dcramer commented Jul 13, 2026

Copy link
Copy Markdown
Member

Fixes #876, the first slice of #883.

Every agent entry point now loads one immutable conversation execution profile before entering the shared Pi runtime. The profile is stored as typed columns on junior_conversations: model profile, reasoning, additional instructions, and an optional tool allowlist. There is no serialized profile document or profile schema version.

The durable records have separate ownership:

Record Owns
junior_conversations Conversation identity, lifecycle, and execution configuration.
junior_conversation_messages Destination-visible user and assistant history.
junior_agent_steps Append-only execution history and context epochs used for continuation. Each epoch owns one model profile and exact model ID.
junior_conversation_turns Only (conversation_id, turn_id, starting_seq), identifying a user request and its starting position in the step log.

junior_conversation_turns.starting_seq has a composite foreign key to junior_agent_steps. The dashboard derives the turn's starting model from the containing context epoch; model identity is not duplicated on messages, turn rows, or resumability metadata.

The epoch invariant is: every execution using an epoch uses that epoch's exact model ID. A handoff opens a new epoch within the same turn. If a model profile resolves differently between fresh turns, the runtime opens a model_change epoch before execution. Timeout, auth, and yield resumes keep the existing binding, while compaction and rollback preserve it. The step writer rejects attempts to append output from a different model.

Review the typed conversation columns and three-column turn table first, then the projection/runtime changes that enforce the epoch invariant. 0004 and 0005 include generated Drizzle snapshots, which account for most of the line count.

@vercel

vercel Bot commented Jul 13, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
junior-docs Ready Ready Preview Jul 14, 2026 12:32am

Request Review

Comment thread packages/junior/src/chat/agent/index.ts
Comment thread packages/junior/src/chat/agent/tools.ts Outdated
@dcramer dcramer changed the title feat(runtime): Add durable conversation execution profiles feat(runtime): Persist conversation execution policy Jul 13, 2026
dcramer and others added 4 commits July 13, 2026 14:07
Materialize immutable model, reasoning, instruction, and tool policies for
conversation execution. Preserve handoff epochs and host authority across
retries and continuation slices.

Fixes #876
Co-Authored-By: OpenAI Codex <noreply@openai.com>
Load local CLI runtime dependencies only after selecting the memory state
adapter. Keep both explicit and host-configured fixed reasoning authoritative
when restoring a resumable session.

Refs #876
Co-Authored-By: OpenAI Codex <noreply@openai.com>
Replace nested conditional expressions with named state and straightforward
branches so reasoning and tool-policy precedence are easier to follow.

Refs #876
Co-Authored-By: OpenAI Codex <noreply@openai.com>
Expose catalog dispatchers automatically when the filtered tool set contains
allowed deferred tools, without granting access to tools outside the profile.

Refs #876
Co-Authored-By: OpenAI Codex <noreply@openai.com>
Replace the versioned JSON execution profile with the minimum typed conversation columns. Keep host and adaptive modes encoded through nullability while preserving empty tool allowlists as a distinct restriction.

Refs #876
Co-Authored-By: OpenAI Codex <noreply@openai.com>
@dcramer dcramer changed the title feat(runtime): Persist conversation execution policy feat(runtime): Add durable conversation execution profiles Jul 13, 2026
@dcramer dcramer force-pushed the codex/shared-conversation-runtime branch from 9932d6d to 032b8ca Compare July 13, 2026 21:44
Define the conversation execution profile as immutable conversation-owned configuration used by each execution slice. Remove baseline and policy wording that obscures the established term.

Refs #876
Co-Authored-By: OpenAI Codex <noreply@openai.com>
Keep the model used when a turn begins separate from the model active at the latest persisted boundary. Conversation detail headers now show the starting model while handoff events retain the transition to the new model.

Refs #876
Co-Authored-By: OpenAI Codex <noreply@openai.com>
Comment thread packages/junior/src/chat/runtime/conversation-runtime.ts
Treat dispatch routing as an internal conversation identity before applying Slack thread parsing. Keep correlation and destination checks intact while allowing agent-dispatch records to use their canonical ids.

Refs #876
Co-Authored-By: OpenAI Codex <noreply@openai.com>
Record each durable turn as an identity plus its starting agent-step
boundary. Derive the starting model from the containing context epoch
instead of duplicating model state in messages, SQL, or resume records.

Require every context epoch to own one exact model. Open an explicit
model_change epoch when a fresh turn resolves its profile differently.
Preserve the binding across resumes and compaction, and reject commits
from a different model.

Refs #876
Co-Authored-By: OpenAI Codex <noreply@openai.com>
Comment thread packages/junior/src/chat/conversations/projection.ts
When message steps predate explicit context-epoch markers, open a bound
replacement epoch with the conversation execution profile. This prevents the
projection default from silently selecting the standard model role.

Refs #876
Co-Authored-By: OpenAI Codex <noreply@openai.com>
Comment thread packages/junior/src/api/conversations/detail.query.ts
Comment thread packages/junior/src/api/conversations/detail.query.ts Outdated
Use SQL execution.run_id to select the turn whose settings the dashboard
reports. Do not borrow a model from an older completed turn when the current
run has only sparse operational metadata.

Retain a bounded compatibility fallback to session model metadata for
conversations created before durable turn rows shipped.

Refs #876
Co-Authored-By: OpenAI Codex <noreply@openai.com>

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit ab984f1. Configure here.

Comment thread packages/junior/src/api/conversations/detail.query.ts
Select the newest turn-session summary as the reporting authority. Mailbox
execution run IDs can identify worker attempts rather than user turns, so they
are only a fallback for recordless runs.

Cover a mailbox run ID that differs from the durable turn ID.

Refs #876
Co-Authored-By: OpenAI Codex <noreply@openai.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: high PR risk score: high

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor agent execution around a shared conversation runtime

1 participant