Skip to content

[codex] Preserve Codex runtime session IDs - #1614

Merged
qdaxb merged 2 commits into
mainfrom
codex/fix-runtime-session-id
Jun 29, 2026
Merged

qdaxb merged 2 commits into
mainfrom
codex/fix-runtime-session-id

Conversation

@qdaxb

@qdaxb qdaxb commented Jun 29, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Cache the real Codex app-server thread id as soon as thread/started is observed.
  • Preserve runtimeHandle.threadId through Wework local runtime task normalization and task address reconciliation.
  • Resume follow-up sends with the real provider session id instead of the visible localTaskId, including after cancellation and nested address sends.

Why

Follow-up Wework sends could fall back to localTaskId when the real Codex thread id was not available in the request path. Codex expects UUID-like thread ids, so visible local task ids could trigger invalid session errors.

Validation

  • cargo test --manifest-path executor/Cargo.toml --test app_runtime_work_send_contract
  • cargo fmt --manifest-path executor/Cargo.toml -- --check
  • pnpm --dir wework exec vitest run src/api/local/localServices.test.ts src/features/workbench/workbenchReducer.test.ts src/features/workbench/workbenchRuntimeHelpers.test.ts
  • pnpm --dir wework exec tsc -b
  • pnpm --dir wework exec prettier --check src/api/local/localServices.ts src/api/local/localServices.test.ts src/features/workbench/workbenchReducer.ts src/features/workbench/workbenchReducer.test.ts src/features/workbench/workbenchRuntimeHelpers.ts src/features/workbench/workbenchRuntimeHelpers.test.ts
  • pre-push hook with AI_VERIFIED=1: Wework full test suite, executor cargo fmt --check, cargo test --all-features, and cargo clippy passed; docs were checked and already cover the runtimeHandle/threadId contract.

Summary by CodeRabbit

  • New Features

    • Runtime task addresses now preserve and display the active runtime thread information more reliably.
    • Local task listings and workbench views now include refreshed runtime handle details when available.
  • Bug Fixes

    • Sending a runtime task now correctly targets the active runtime session/thread instead of falling back to an unrelated task id.
    • Nested runtime connection details are now recognized in task addresses and requests, improving resume behavior after cancellation.

@coderabbitai

coderabbitai Bot commented Jun 29, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 8e07ea4d-a974-4952-9e42-a539bae3433b

📥 Commits

Reviewing files that changed from the base of the PR and between bdb053d and 05355f6.

📒 Files selected for processing (10)
  • executor/src/agents/codex.rs
  • executor/src/runtime_work/handler.rs
  • executor/src/runtime_work/runtime_handle_messages.rs
  • executor/tests/app_runtime_work_send_contract.rs
  • wework/src/api/local/localServices.test.ts
  • wework/src/api/local/localServices.ts
  • wework/src/features/workbench/workbenchReducer.test.ts
  • wework/src/features/workbench/workbenchReducer.ts
  • wework/src/features/workbench/workbenchRuntimeHelpers.test.ts
  • wework/src/features/workbench/workbenchRuntimeHelpers.ts

📝 Walkthrough

Walkthrough

Adds end-to-end runtimeHandle/threadId tracking: the Codex agent emits a thread/started notification that the executor caches into the task store; send_message is tightened to require a runtime session id (extracted from nested address fields) and rejects requests without one. The frontend normalizes and propagates runtimeHandle.threadId through runtime task summaries and workbench address helpers.

Changes

Thread ID propagation through runtime task send flow

Layer / File(s) Summary
Codex agent emits thread/started
executor/src/agents/codex.rs
After resolving thread_id, conditionally sends a thread/started JSON-RPC notification to the notifications channel.
Cache thread id from notification
executor/src/runtime_work/runtime_handle_messages.rs
New cache_runtime_thread_id helper parses thread id from multiple param shapes and persists it in RuntimeWorkStore; new match arm routes thread/started to it.
send_message routing and session extraction
executor/src/runtime_work/handler.rs
send_message requires a runtime session id from payload or cached link, returning missing_runtime_session on failure. runtime_session_id_from_payload additionally reads nested address.runtimeHandle and providerSessionId fields.
Executor integration tests
executor/tests/app_runtime_work_send_contract.rs
Adds idle-wait steps to existing tests; two new tests verify thread resumption after cancel and via nested runtimeHandle address; adds write_fake_codex_slow_first_turn, wait_for_method_count, and wait_until_task_idle.
Frontend normalization of runtimeHandle
wework/src/api/local/localServices.ts, wework/src/api/local/localServices.test.ts
normalizeRuntimeTaskSummary extracts and spreads runtimeHandle into LocalTaskSummary; test verifies threadId is preserved through normalization.
Workbench address helpers
wework/src/features/workbench/workbenchRuntimeHelpers.ts, workbenchRuntimeHelpers.test.ts, workbenchReducer.ts, workbenchReducer.test.ts
runtimeTaskAddressFromWorkspace helper adds workspacePath and runtimeHandle to task addresses; findRuntimeTaskAddressByLocalTaskId updated likewise; tests updated and added for both.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • wecode-ai/Wegent#1585: Directly modifies CodexNotificationCacheMapper::map notification routing in the same file, establishing the pattern this PR extends with thread/started.

Poem

🐇 A thread is born, a message sent,
The rabbit watched each notification went.
thread/started cached with care,
runtimeHandle floats through the air—
No session? Rejected! Rules are clear.
Hop along, the thread id's here! 🎉

✨ 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 codex/fix-runtime-session-id

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.

…sion-id

# Conflicts:
#	wework/src/api/local/localServices.ts
@qdaxb
qdaxb marked this pull request as ready for review June 29, 2026 17:13
@qdaxb
qdaxb merged commit da32ed2 into main Jun 29, 2026
26 of 28 checks passed
@qdaxb
qdaxb deleted the codex/fix-runtime-session-id branch June 29, 2026 17:13
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