Skip to content

[codex] Start the guardian child session when parent session is started#27982

Merged
jgershen-oai merged 5 commits into
mainfrom
codex/guardian-attached-session
Jun 22, 2026
Merged

[codex] Start the guardian child session when parent session is started#27982
jgershen-oai merged 5 commits into
mainfrom
codex/guardian-attached-session

Conversation

@jgershen-oai

@jgershen-oai jgershen-oai commented Jun 12, 2026

Copy link
Copy Markdown
Collaborator

Why

The first auto-review currently creates its Guardian child session on demand, adding avoidable latency before the review can begin. Creating the ordinary Guardian child during parent-session initialization lets that child use the existing session startup WebSocket prewarm before the first escalation. This does not introduce a Guardian-specific prewarm mechanism.

What changed

  • initialize the existing Guardian review-session manager owned by Session when a thread starts with auto-review enabled and an approval policy that routes to Guardian
  • use the standard Guardian child-session construction and the existing session startup WebSocket prewarm
  • preserve the existing reuse-key invalidation and lazy creation fallback when startup initialization fails or the effective review configuration changes
  • add an integration test that verifies normal root-session startup emits a Guardian generate=false prewarm request

Benchmark

I compared release builds against main. Each prompt first ran a non-escalated sleep 3, then requested an escalated marker command.

binary count avg Guardian duration median Guardian duration avg Guardian TTFT
origin-main 10 4008.7 ms 3949.5 ms 3746.5 ms
session-fix 10 2865.0 ms 2594.0 ms 2492.7 ms

Guardian duration fell by 28.5% and Guardian TTFT fell by 33.5%. These measurements cover Guardian review latency; they do not measure parent thread-start latency.

@jgershen-oai jgershen-oai force-pushed the codex/guardian-attached-session branch 2 times, most recently from 7e4332c to 274762d Compare June 13, 2026 00:24
@jgershen-oai jgershen-oai force-pushed the codex/guardian-attached-session branch from 274762d to 6aebfd0 Compare June 13, 2026 00:28
@jgershen-oai jgershen-oai changed the title [codex] Prewarm attached Guardian sessions for auto-review [codex] Start the guardian child session when parent session is started Jun 13, 2026
@jgershen-oai jgershen-oai marked this pull request as ready for review June 13, 2026 00:54
@jgershen-oai jgershen-oai requested a review from a team as a code owner June 13, 2026 00:54
Comment thread codex-rs/core/src/session/session.rs Outdated
Comment thread codex-rs/core/tests/suite/guardian_review.rs Outdated
Comment thread codex-rs/core/src/session/session.rs Outdated
warn!("failed to initialize guardian review session: {err:#}");
}
}));
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Non-blocking but we might also want to trigger this when a user switches permissions mid-thread

@jgershen-oai jgershen-oai merged commit 15f448d into main Jun 22, 2026
31 checks passed
@jgershen-oai jgershen-oai deleted the codex/guardian-attached-session branch June 22, 2026 18:54
@github-actions github-actions Bot locked and limited conversation to collaborators Jun 22, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants