Skip to content

refactor(executor): modularize Codex runtime - #2136

Merged
qdaxb merged 3 commits into
mainfrom
refactor/codex-runtime-modules
Jul 23, 2026
Merged

qdaxb merged 3 commits into
mainfrom
refactor/codex-runtime-modules

Conversation

@qdaxb

@qdaxb qdaxb commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • split Codex Home/configuration, interaction routing, turn-state reduction, and diagnostics into focused modules
  • move the Codex regression suite out of the orchestration file
  • document the new runtime module boundaries in Chinese and English architecture guides

Why

executor/src/agents/codex.rs mixed configuration, authentication, interaction correlation, event reduction, diagnostics, orchestration, and tests in one high-churn file. Separating stable responsibility boundaries reduces coupling while preserving the public API and runtime behavior.

Impact

No protocol or user-facing behavior changes. codex.rs remains the public API and orchestration layer; focused implementation and tests now live under executor/src/agents/codex/.

Validation

  • cargo test --manifest-path executor/Cargo.toml --no-fail-fast
  • cargo clippy --manifest-path executor/Cargo.toml --all-targets -- -D warnings
  • pre-push: cargo fmt --check, cargo test --all-features --lib, cargo clippy
  • isolated real-Tauri flow: launch Wework, select no-project local workspace, submit a Codex prompt, observe running state, and verify final response Codex重构验证通过
  • reviewed the five-step screenshot chain and isolated Tauri/executor logs

Summary by CodeRabbit

  • Documentation

    • Clarified the modular responsibilities of the Codex runtime and where future behavior should be implemented.
  • Bug Fixes

    • Improved Codex configuration and authentication setup, including legacy configuration migration.
    • Improved handling of user interaction responses and message-stream state.
    • Added concise diagnostics for large command and tool outputs.
  • Tests

    • Expanded coverage for configuration, interaction routing, message processing, launch behavior, and input transformations.

@coderabbitai

coderabbitai Bot commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@qdaxb, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 27 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a2333a77-6528-485c-9c11-80de7dd0e83e

📥 Commits

Reviewing files that changed from the base of the PR and between 3ac28fd and 4141413.

📒 Files selected for processing (5)
  • executor/src/agents/codex/diagnostics.rs
  • executor/src/agents/codex/home.rs
  • executor/src/agents/codex/interaction.rs
  • executor/src/agents/codex/run_state.rs
  • executor/src/agents/codex/tests.rs
📝 Walkthrough

Walkthrough

The Codex executor was reorganized into dedicated modules for home management, diagnostics, interaction routing, and run-state processing. The main orchestration file now wires these modules, while tests and architecture documentation were moved or updated accordingly.

Changes

Codex runtime modularization

Layer / File(s) Summary
Executor wiring and launch behavior
executor/src/agents/codex.rs, executor/src/agents/codex/tests.rs, docs/*/wegent/developer-guide/architecture.md
codex.rs wires extracted modules and retains launch, request, turn, and app-server orchestration; tests cover configuration, provider routing, permissions, input transformation, and launch behavior.
Codex home preparation
executor/src/agents/codex/home.rs, executor/src/agents/codex/tests.rs
Home resolution, config normalization, atomic config replacement, authentication linking or copying, and related environment behavior are implemented and tested.
Diagnostics and JSON previews
executor/src/agents/codex/diagnostics.rs, executor/src/agents/codex/tests.rs
JSON field extraction, serialized-size measurement, raw-log sanitization, and text truncation utilities are added with preview coverage.
Interaction answer routing
executor/src/agents/codex/interaction.rs, executor/src/agents/codex/tests.rs
InteractionAnswerRouter correlates, buffers, and closes request_user_input responses, with concurrency and channel-closure tests.
Run-state processing and telemetry
executor/src/agents/codex/run_state.rs, executor/src/agents/codex/tests.rs
CodexRunState processes turn events, filters subagent and phase-specific content, derives outcomes, and records structured telemetry with state-handling tests.

Estimated code review effort: 4 (Complex) | ~60 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 73.24% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: modularizing the Codex runtime in the executor.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/codex-runtime-modules

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@qdaxb
qdaxb marked this pull request as ready for review July 22, 2026 17:12
@qdaxb

qdaxb commented Jul 22, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 5

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@executor/src/agents/codex/diagnostics.rs`:
- Around line 34-39: Update raw_log_preview and its sanitize_raw_log_value path
to prevent secrets from appearing in previews: redact sensitive key, token,
API-key, authentication-file, and content fields or apply a safe allowlist
before serialization and truncation. Preserve useful non-sensitive diagnostics,
and add a regression test covering representative secret values and asserting
none appear in the generated preview.

In `@executor/src/agents/codex/home.rs`:
- Around line 160-165: Update executor_home’s WEGENT_EXECUTOR_HOME lookup to
reject empty environment values before converting them to PathBuf, matching
wework_codex_home’s !value.is_empty() handling; preserve the existing
home-directory and relative fallback behavior for absent or empty values.

In `@executor/src/agents/codex/interaction.rs`:
- Around line 29-51: The answer-routing loop in the spawned interaction receiver
silently discards responses when interaction_answer_key returns no key and
state.pending is not exactly one entry. Update this branch to make unroutable
answers observable by logging the discarded answer and relevant routing context,
while preserving normal keyed delivery and single-pending fallback behavior.
- Around line 55-73: Update receive so it checks state.pending for an existing
correlation key before inserting the new oneshot sender. Return the duplicate
pending interaction error without modifying the existing entry, preserving the
original waiter's sender and response routing.

In `@executor/src/agents/codex/run_state.rs`:
- Around line 350-363: Update log_codex_run_state_error to pass params through
the existing raw_log_preview sanitization helper, matching
log_codex_raw_turn_message, before truncating and logging params_preview. Remove
the direct unsanitized serialization path while preserving the existing
serialization-failure handling and logged fields.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 34eb15dc-2d25-4f84-aaf0-1823ac4d2eee

📥 Commits

Reviewing files that changed from the base of the PR and between 97a6800 and 3ac28fd.

📒 Files selected for processing (8)
  • docs/en/wegent/developer-guide/architecture.md
  • docs/zh/wegent/developer-guide/architecture.md
  • executor/src/agents/codex.rs
  • executor/src/agents/codex/diagnostics.rs
  • executor/src/agents/codex/home.rs
  • executor/src/agents/codex/interaction.rs
  • executor/src/agents/codex/run_state.rs
  • executor/src/agents/codex/tests.rs

Comment thread executor/src/agents/codex/home.rs Resolved
Comment thread executor/src/agents/codex/run_state.rs Resolved
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.

1 participant