Skip to content

fix(wework): unify authoritative running task state - #2149

Merged
qdaxb merged 4 commits into
mainfrom
fix/wework-authoritative-running-state
Jul 23, 2026
Merged

fix(wework): unify authoritative running task state#2149
qdaxb merged 4 commits into
mainfrom
fix/wework-authoritative-running-state

Conversation

@qdaxb

@qdaxb qdaxb commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

What changed

  • make the executor process's active-task set the only authority for runtime task running state
  • use that executor-provided state consistently in task lists, transcripts, the detail pane, tray state, and related Wework behavior
  • prevent stale Codex thread metadata, frontend optimistic state, or persisted reminder state from keeping tasks marked as running
  • harden the isolated Tauri verifier so wait-for works while the WebView is background-throttled
  • document the running-state invariant in the Chinese and English local-device architecture guides

Root cause

Different surfaces inferred execution state independently. The executor task list could derive running from Codex thread metadata, the transcript used active-turn metadata, the current pane also consulted frontend optimistic state, and the tray could use a persisted reminder snapshot. Those sources settle at different times and could disagree after a turn completed or an executor restarted.

Impact

The sidebar, task detail pane, stop/send controls, system tray, and sleep-related consumers now converge on the same live executor state. Historical thread metadata remains available for display but can no longer claim that a turn is currently executing.

Validation

  • cargo test --manifest-path executor/Cargo.toml --lib — 353 passed, 1 ignored
  • pnpm --filter wework test — 2003 passed
  • cargo test --manifest-path wework/src-tauri/Cargo.toml --lib — 84 passed
  • pre-push ESLint, TypeScript, Wework unit tests, executor fmt/test/clippy — passed
  • isolated real-Tauri flow: idle task → running sleep 30 turn → completed turn
    • running snapshot showed the sidebar running marker, active command block, and stop control together
    • completed snapshot showed all running indicators removed together
  • close-to-tray recovery: a running sleep 20 turn continued after the controlled WebView was destroyed and settled to status=done, running=false in executor logs

Summary by CodeRabbit

  • Bug Fixes

    • Running task indicators now consistently reflect the executor’s current execution state.
    • Prevented stale Codex metadata and reminders from incorrectly showing tasks as running.
    • Task details now correctly display idle and completed statuses after executor restarts.
    • Updated tray menus, tooltips, and sleep-prevention behavior to use the same running-task state.
  • Improvements

    • WebView command delivery now supports long-polling for faster command updates.
    • Added coverage for executor-based task status and stale reminder handling.

@coderabbitai

coderabbitai Bot commented Jul 23, 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: 29 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 Plus

Run ID: d49b952a-2425-45f7-98af-6b5b510348a3

📥 Commits

Reviewing files that changed from the base of the PR and between 379f375 and d810657.

📒 Files selected for processing (2)
  • wework/scripts/ai-verify.mjs
  • wework/scripts/ai-verify.test.mjs
📝 Walkthrough

Walkthrough

The executor now owns the authoritative runtime running state used by task links, transcripts, Workbench, and tray indicators. In parallel, the WebView verification server adds long-polling for command retrieval with timeout, disconnect cleanup, and immediate delivery to waiting requests.

Changes

Executor-authoritative runtime state

Layer / File(s) Summary
Runtime task status contract
executor/src/runtime_work/response.rs
RuntimeTaskLink derives running from executor execution state and normalizes inactive status fields using runtime status values.
Runtime reporting and handler integration
executor/src/runtime_work/handler*, executor/tests/app_runtime_work_native_update_contract.rs
Task links and transcript responses pass executor state through runtime handlers; inactive Codex metadata is normalized to idle/completed states and covered by tests.
Workbench and tray state consistency
wework/src/features/workbench/WorkbenchProvider.tsx, wework/src/pages/WorkbenchPage.tsx, wework/src/tauri/trayMenuState.*, docs/*/wegent/developer-guide/local-device-architecture.md
Workbench and tray indicators use runtime task running, ignoring stale reminder state; English and Chinese architecture documentation describe the same authority rule.

WebView command long-polling

Layer / File(s) Summary
Long-poll command delivery
wework/scripts/ai-verify.mjs
Empty /commands requests remain pending until a command arrives, the connection closes, or the timeout returns HTTP 204; posted commands resolve the oldest pending poll.

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

Sequence Diagram(s)

sequenceDiagram
  participant Executor
  participant Workbench
  participant Tray
  Executor->>Workbench: runtime task running state
  Executor->>Tray: runtime task running state
  Workbench-->>Workbench: render running indicator
  Tray-->>Tray: build running-task menu state
Loading
sequenceDiagram
  participant WebView
  participant AiVerifyServer
  participant CommandPolls
  WebView->>AiVerifyServer: GET /commands
  AiVerifyServer->>CommandPolls: hold pending response
  WebView->>AiVerifyServer: POST /command
  AiVerifyServer->>CommandPolls: resolve pending response
  CommandPolls-->>WebView: command payload
Loading

Possibly related PRs

  • wecode-ai/Wegent#1795: Updates tray running-task state to use runtime task data instead of reminders.
  • wecode-ai/Wegent#1827: Changes runtime task activity derivation in the same executor mapping paths.
  • wecode-ai/Wegent#1896: Introduces the related authenticated /commands flow for the verification session controller.

Suggested reviewers: ficohu

🚥 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 matches the main change: unifying executor-authoritative running task state across Wework.
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 fix/wework-authoritative-running-state

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 23, 2026 06:21

@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/scripts/ai-verify.mjs`:
- Around line 188-195: Update the command dispatch logic around
commandPolls.shift() so stale or disconnected long-poll responses are not
consumed. Check the selected poll’s response state, such as
response.writableEnded or an equivalent close marker, before calling json; if it
is no longer writable, continue looking for a valid poll or enqueue nextCommand
instead. Preserve normal immediate dispatch for active polls.
🪄 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: 7b6dd423-2355-47c8-b5a2-e7c5e85a82ec

📥 Commits

Reviewing files that changed from the base of the PR and between ab7b5ec and 379f375.

📒 Files selected for processing (15)
  • docs/en/wegent/developer-guide/local-device-architecture.md
  • docs/zh/wegent/developer-guide/local-device-architecture.md
  • executor/src/runtime_work/handler.rs
  • executor/src/runtime_work/handler/collection.rs
  • executor/src/runtime_work/handler/helpers/routing.rs
  • executor/src/runtime_work/handler/helpers/transcript.rs
  • executor/src/runtime_work/handler/queries.rs
  • executor/src/runtime_work/handler/tests.rs
  • executor/src/runtime_work/response.rs
  • executor/tests/app_runtime_work_native_update_contract.rs
  • wework/scripts/ai-verify.mjs
  • wework/src/features/workbench/WorkbenchProvider.tsx
  • wework/src/pages/WorkbenchPage.tsx
  • wework/src/tauri/trayMenuState.test.ts
  • wework/src/tauri/trayMenuState.ts
💤 Files with no reviewable changes (1)
  • executor/src/runtime_work/handler/helpers/transcript.rs

Comment thread wework/scripts/ai-verify.mjs
@qdaxb
qdaxb merged commit 20e3210 into main Jul 23, 2026
30 checks passed
@qdaxb
qdaxb deleted the fix/wework-authoritative-running-state branch July 23, 2026 06:58
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