Skip to content

fix(executor): preserve Codex runtime task titles - #1636

Merged
qdaxb merged 1 commit into
mainfrom
fix/codex-runtime-title
Jun 30, 2026
Merged

qdaxb merged 1 commit into
mainfrom
fix/codex-runtime-title

Conversation

@qdaxb

@qdaxb qdaxb commented Jun 30, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • preserve the initial Wegent runtime task title by applying it to the Codex thread after thread creation
  • keep follow-up sends from changing the Codex thread name
  • write the runtime-work index via a temporary file and atomic rename to avoid partial reads

Tests

  • cargo fmt --manifest-path executor/Cargo.toml
  • cargo test --manifest-path executor/Cargo.toml runtime_work --lib

Summary by CodeRabbit

  • New Features

    • New tasks can now start with a title shown as the conversation/thread name.
    • Thread names can be set automatically when a task begins, making work easier to identify.
  • Bug Fixes

    • Runtime index updates are now saved more safely, reducing the chance of partial writes if saving is interrupted.

@coderabbitai

coderabbitai Bot commented Jun 30, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Two independent changes: run_codex_app_server_turn gains an initial_thread_name: Option<String> parameter and conditionally sends a "thread/name/set" JSON-RPC after thread start; create_task passes the task title as that name. Separately, RuntimeWorkStore::write_index now writes to a temp file and renames atomically.

Changes

Thread naming on task creation

Layer / File(s) Summary
thread/name/set RPC in run_codex_app_server_turn
executor/src/agents/codex.rs
Signature extended with initial_thread_name: Option<String>; after thread start, trims the name and sends "thread/name/set" RPC when non-empty. CodexAppServerEngine::run passes None.
spawn_turn and create_task wiring
executor/src/runtime_work/handler.rs
spawn_turn accepts and forwards initial_thread_name; create_task passes Some(title); send_message passes None.

Atomic index file writes

Layer / File(s) Summary
Atomic write_index via temp file and rename
executor/src/runtime_work/store.rs
Adds SystemTime/UNIX_EPOCH imports; write_index writes JSON to a timestamp+PID-named temp file, then fs::renames it to the final path; cleans up temp on rename failure.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐇 A thread gets a name, a file writes with care,
Atomic and tidy, no tears in the air.
The temp file steps in, then quietly bows,
While titles are set with the quietest vows.
Hop hop, all is clean — the index is there! 🌿

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% 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 reflects the main executor change: preserving Codex runtime task titles.
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 docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/codex-runtime-title

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.

@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: 1

🧹 Nitpick comments (1)
executor/src/agents/codex.rs (1)

355-370: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Constrain the initial name RPC to newly started threads.

Line 355 only checks whether a name exists, so any future caller that passes both resume_thread_id and initial_thread_name will rename an existing Codex thread. Guard this on the start path to preserve the “initial title only” contract at the callee boundary.

Proposed fix
-        if let Some(name) = initial_thread_name
-            .as_deref()
-            .map(str::trim)
-            .filter(|name| !name.is_empty())
-        {
-            with_rpc_timeout(
-                "thread/name/set",
-                timeout_seconds,
-                rpc.request(
-                    "thread/name/set",
-                    json!({"threadId": thread_id.clone(), "name": name}),
-                    &mut state,
-                ),
-            )
-            .await?;
+        if thread_operation == "thread/start" {
+            if let Some(name) = initial_thread_name
+                .as_deref()
+                .map(str::trim)
+                .filter(|name| !name.is_empty())
+            {
+                with_rpc_timeout(
+                    "thread/name/set",
+                    timeout_seconds,
+                    rpc.request(
+                        "thread/name/set",
+                        json!({"threadId": thread_id.clone(), "name": name}),
+                        &mut state,
+                    ),
+                )
+                .await?;
+            }
         }
🤖 Prompt for 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.

In `@executor/src/agents/codex.rs` around lines 355 - 370, Guard the thread naming
RPC in codex.rs so it only runs for newly started threads, not when resuming an
existing one. Update the initial_thread_name handling in the code path around
with_rpc_timeout and rpc.request("thread/name/set", ...) to additionally check
that resume_thread_id is absent (or equivalent start-path condition) before
sending the rename request. Keep the “initial title only” behavior enforced at
the callee boundary by tying the name-setting logic to the thread creation flow,
not just the presence of initial_thread_name.
🤖 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/runtime_work/store.rs`:
- Around line 125-128: The write path in store.rs uses fs::rename to swap the
temporary file into index_path, which fails to overwrite an existing destination
on Windows. Update the write flow in the affected store method to use a
cross-platform replace/atomic overwrite approach when promoting
temporary_index_path(&self.index_path) to self.index_path, and keep the cleanup
of the temp file for failure cases.

---

Nitpick comments:
In `@executor/src/agents/codex.rs`:
- Around line 355-370: Guard the thread naming RPC in codex.rs so it only runs
for newly started threads, not when resuming an existing one. Update the
initial_thread_name handling in the code path around with_rpc_timeout and
rpc.request("thread/name/set", ...) to additionally check that resume_thread_id
is absent (or equivalent start-path condition) before sending the rename
request. Keep the “initial title only” behavior enforced at the callee boundary
by tying the name-setting logic to the thread creation flow, not just the
presence of initial_thread_name.
🪄 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: b56f46e0-7fd0-4272-af3f-58b9cceee304

📥 Commits

Reviewing files that changed from the base of the PR and between c6d4362 and 705b953.

📒 Files selected for processing (3)
  • executor/src/agents/codex.rs
  • executor/src/runtime_work/handler.rs
  • executor/src/runtime_work/store.rs

Comment on lines +125 to +128
let temp_path = temporary_index_path(&self.index_path);
if fs::write(&temp_path, payload).is_ok() {
if fs::rename(&temp_path, &self.index_path).is_err() {
let _ = fs::remove_file(temp_path);

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.

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "Checking whether the repo advertises Windows support in CI/docs/manifests..."
fd -HI 'README.md|Cargo.toml|*.yml|*.yaml' . \
  | xargs -r rg -n -i 'windows|windows-latest|target_os\s*=\s*"windows"|cfg\(windows\)'

echo
echo "Looking for existing file-replacement helpers or atomic-write utilities..."
rg -n 'replace|rename\(|NamedTempFile|persist|atomic' executor .

Repository: wecode-ai/Wegent

Length of output: 565


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "Repo files mentioning Windows/support targets:"
git ls-files | rg -n '(^|/)(README\.md|Cargo\.toml|.*\.(ya?ml))$' || true
echo

echo "Search for Windows-target or Windows CI references:"
git ls-files | rg -n '(^|/)(README\.md|Cargo\.toml|.*\.(ya?ml))$' | while read -r f; do
  rg -n -i 'windows|windows-latest|target_os\s*=\s*"windows"|cfg\(windows\)' "$f" || true
done
echo

echo "Relevant store.rs excerpt:"
sed -n '1,220p' executor/src/runtime_work/store.rs
echo

echo "Search for atomic-write / temp-file helpers:"
rg -n 'NamedTempFile|persist|atomic|rename\(' executor src . || true

Repository: wecode-ai/Wegent

Length of output: 50372


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "Relevant manifest/docs files:"
git ls-files | rg '(^|/)(README\.md|Cargo\.toml|.*\.(ya?ml))$' || true

Repository: wecode-ai/Wegent

Length of output: 1949


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "Relevant repo files:"
git ls-files | rg '(^|/)(README\.md|Cargo\.toml|.*\.(ya?ml))$' || true
echo

echo "Windows references in those files:"
while IFS= read -r f; do
  rg -n -i 'windows|windows-latest|target_os\s*=\s*"windows"|cfg\(windows\)' "$f" || true
done < <(git ls-files | rg '(^|/)(README\.md|Cargo\.toml|.*\.(ya?ml))$')
echo

echo "store.rs excerpt:"
sed -n '110,170p' executor/src/runtime_work/store.rs
echo

echo "Any atomic-write or helper utilities elsewhere:"
rg -n 'NamedTempFile|persist|atomic|replace\(' . || true

Repository: wecode-ai/Wegent

Length of output: 2029


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "Manifest/docs files:"
git ls-files | rg '(^|/)(README\.md|Cargo\.toml|.*\.(ya?ml))$'

Repository: wecode-ai/Wegent

Length of output: 1940


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "executor/Cargo.toml:"
sed -n '1,220p' executor/Cargo.toml
echo

echo ".github/workflows/test-windows-executor.yml:"
sed -n '1,220p' .github/workflows/test-windows-executor.yml
echo

echo "Windows cfg / target references in executor:"
rg -n 'target_os\s*=\s*"windows"|cfg\(windows\)|windows-latest|windows' executor .github/workflows/test-windows-executor.yml README.md executor/Cargo.toml

Repository: wecode-ai/Wegent

Length of output: 10643


Use a cross-platform replace when writing index_path. fs::rename won’t overwrite an existing file on Windows, so once the index exists these updates can fail and the new payload gets dropped during cleanup.

🤖 Prompt for 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.

In `@executor/src/runtime_work/store.rs` around lines 125 - 128, The write path in
store.rs uses fs::rename to swap the temporary file into index_path, which fails
to overwrite an existing destination on Windows. Update the write flow in the
affected store method to use a cross-platform replace/atomic overwrite approach
when promoting temporary_index_path(&self.index_path) to self.index_path, and
keep the cleanup of the temp file for failure cases.

@qdaxb
qdaxb merged commit 11ab12e into main Jun 30, 2026
25 of 27 checks passed
@qdaxb
qdaxb deleted the fix/codex-runtime-title branch June 30, 2026 08:30
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