Skip to content

fix(wework): stop Codex tasks during startup - #2290

Merged
qdaxb merged 2 commits into
mainfrom
fix/wework-stop-task-cancellation
Jul 29, 2026
Merged

qdaxb merged 2 commits into
mainfrom
fix/wework-stop-task-cancellation

Conversation

@qdaxb

@qdaxb qdaxb commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

What changed

  • use Codex's thread-level startup interrupt when cancellation arrives before the first turn progress event
  • retain turn-ID-scoped interruption after the turn becomes active
  • add an executor contract test that reproduces the no active turn to interrupt race
  • strengthen the Wework desktop resilience E2E so a late upstream completion cannot resume or append to a stopped task
  • document the shared app-server startup cancellation invariant in Chinese and English

Why

turn/start can return a turn ID before Codex app-server publishes the first progress event and registers that turn in its active-turn index. If Wework stops the task in that window, an interrupt using the concrete turn ID can fail with no active turn to interrupt. The executor would mark the local task cancelled while the newly starting Codex turn continued running and emitting content.

During that startup window, Codex defines an empty turnId as the thread-level startup interrupt. Using it closes the race without changing cancellation behavior for established active turns.

User impact

Stopping a Wework task now reliably terminates the Codex turn even when the stop action races with turn startup. Delayed upstream output cannot make the task resume or append content after the stopped notice appears.

Validation

  • cargo test --manifest-path executor/Cargo.toml --test app_runtime_work_send_contract runtime_tasks_cancel_ -- --nocapture
  • cargo test --manifest-path executor/Cargo.toml --test codex_cancellation_contract -- --nocapture
  • cargo fmt --manifest-path executor/Cargo.toml -- --check
  • pnpm --filter wework e2e:desktop -- --segment resilience
  • pnpm --filter wework exec prettier --check e2e/desktop/task-flow.e2e.mjs
  • node --check wework/e2e/desktop/task-flow.e2e.mjs
  • pre-push Wework ESLint, TypeScript, and unit tests
  • pre-push Executor library tests and Clippy
  • isolated real-Tauri verification: stopped state remained stable with no resumed output

Summary by CodeRabbit

  • Bug Fixes
    • Improved task cancellation during the startup phase by sending an interrupt before the first progress event (including an empty turnId), then using the concrete turnId once available.
    • Prevented cancelled tasks from resuming/retrying or replaying cancelled input while the previous operation is still stopping.
  • Documentation
    • Clarified Codex turn cancellation timing for shared app-server scenarios in both English and Chinese architecture guides.
  • Tests
    • Added coverage to verify the startup interrupt behavior and updated desktop E2E flows to wait for cancellation completion before asserting final outcomes.

@coderabbitai

coderabbitai Bot commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 4640f668-998c-4cdf-bd98-7a78e70a7e9a

📥 Commits

Reviewing files that changed from the base of the PR and between 68fd156 and 8ac30eb.

📒 Files selected for processing (2)
  • executor/tests/app_runtime_work_send_contract.rs
  • wework/e2e/desktop/task-flow.e2e.mjs
🚧 Files skipped from review as they are similar to previous changes (2)
  • executor/tests/app_runtime_work_send_contract.rs
  • wework/e2e/desktop/task-flow.e2e.mjs

📝 Walkthrough

Walkthrough

Codex shared app-server cancellation now sends a thread-level interrupt with an empty turn ID during the startup window. Runtime tests cover this behavior, while desktop E2E tests defer completion events and verify cancelled tasks remain stopped.

Changes

Codex cancellation flow

Layer / File(s) Summary
Startup-window interrupt behavior
executor/src/agents/codex.rs, executor/tests/app_runtime_work_send_contract.rs, docs/{en,zh}/wegent/developer-guide/architecture.md
Cancellation uses an empty turnId before initial progress, with runtime coverage, fake Codex responses, and updated architecture documentation.
Cancellation completion synchronization
wework/e2e/desktop/task-flow.e2e.mjs
The cancellation stream waits for an explicit release before final completion events, and resilience checks confirm the task remains stopped afterward.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant RuntimeTask
  participant CodexExecutor
  participant CodexAppServer
  participant DesktopE2EServer
  RuntimeTask->>CodexExecutor: request cancellation
  CodexExecutor->>CodexAppServer: turn/interrupt with empty turnId during startup
  CodexAppServer-->>CodexExecutor: interruption confirmation
  CodexExecutor-->>RuntimeTask: report cancellation
  DesktopE2EServer->>DesktopE2EServer: wait for cancellation completion release
  DesktopE2EServer-->>RuntimeTask: emit deferred completion events
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 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: stopping Codex tasks during startup in Wework.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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/wework-stop-task-cancellation

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 29, 2026 05:03

@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

🤖 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 `@wework/e2e/desktop/task-flow.e2e.mjs`:
- Around line 9781-9809: The delayed-completion assertions should await an
explicit completion-observed promise instead of the fixed one-second sleep. In
the cancellation flow around cancellationSnapshotAfterUpstreamCompletion, expose
and await the test server’s completion-observed promise using
DEFAULT_STEP_TIMEOUT_MS, then retain the existing stopped-state assertions.
🪄 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 Plus

Run ID: 45fd173d-8edd-41da-8b36-0ef024d863fc

📥 Commits

Reviewing files that changed from the base of the PR and between 0948d72 and 68fd156.

📒 Files selected for processing (5)
  • docs/en/wegent/developer-guide/architecture.md
  • docs/zh/wegent/developer-guide/architecture.md
  • executor/src/agents/codex.rs
  • executor/tests/app_runtime_work_send_contract.rs
  • wework/e2e/desktop/task-flow.e2e.mjs

Comment thread wework/e2e/desktop/task-flow.e2e.mjs Resolved
@qdaxb
qdaxb enabled auto-merge July 29, 2026 11:02
@qdaxb
qdaxb added this pull request to the merge queue Jul 29, 2026
Merged via the queue into main with commit 3c7ad94 Jul 29, 2026
38 checks passed
@qdaxb
qdaxb deleted the fix/wework-stop-task-cancellation branch July 29, 2026 11:48
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