Skip to content

fix(wework): stop completed Codex block timer - #1393

Merged
qdaxb merged 1 commit into
wecode-ai:mainfrom
icycrystal4:fix/wework-codex-block-duration-clean
Jun 15, 2026
Merged

qdaxb merged 1 commit into
wecode-ai:mainfrom
icycrystal4:fix/wework-codex-block-duration-clean

Conversation

@icycrystal4

@icycrystal4 icycrystal4 commented Jun 15, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Normalize Codex/OpenAPI completed block statuses to the workbench done state
  • Finalize residual processing blocks when assistant turns finish or error
  • Finalize persisted processing blocks when opening terminal subtasks from history after refresh
  • Keep wework/.prettierrc.json so the wework pre-commit hook uses the project style instead of Prettier defaults
  • Add regression coverage for completed incoming blocks and restored terminal history blocks

Tests

  • pnpm --filter @wegent/chat-core test -- src/workbench-message-reducer.test.ts
  • pnpm --dir wework test -- src/features/workbench/WorkbenchProvider.test.tsx src/components/chat/blocks/ToolBlocksDisplay.test.tsx
  • pnpm --dir wework lint
  • pre-push AI quality check

Summary by CodeRabbit

  • Bug Fixes
    • Improved assistant completion/error handling so processing blocks consistently finalize to terminal states.
    • Enhanced block status normalization by trimming/lowercasing and mapping common status aliases to consistent outcomes.
    • Improved timestamp handling with safer fallbacks and finalized terminal subtasks for completed/failed/cancelled states.
    • Extended subtask metadata with an optional completion timestamp.
  • Tests
    • Added coverage for terminal finalization and expanded status-mapping scenarios.
  • Style
    • Updated formatting in tests and standardized Prettier configuration for consistent rendering.

@coderabbitai

coderabbitai Bot commented Jun 15, 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

Run ID: 8cec5ee0-189e-4975-9091-b59e5b25d554

📥 Commits

Reviewing files that changed from the base of the PR and between f1f7f82 and 693c8df.

📒 Files selected for processing (6)
  • packages/chat-core/src/workbench-message-reducer.test.ts
  • packages/chat-core/src/workbench-message-reducer.ts
  • wework/.prettierrc.json
  • wework/src/features/workbench/WorkbenchProvider.test.tsx
  • wework/src/features/workbench/WorkbenchProvider.tsx
  • wework/src/types/api.ts
✅ Files skipped from review due to trivial changes (1)
  • wework/.prettierrc.json
🚧 Files skipped from review as they are similar to previous changes (4)
  • packages/chat-core/src/workbench-message-reducer.test.ts
  • wework/src/types/api.ts
  • packages/chat-core/src/workbench-message-reducer.ts
  • wework/src/features/workbench/WorkbenchProvider.test.tsx

📝 Walkthrough

Walkthrough

Block finalization now accepts an explicit finalStatus parameter to coerce non-terminal blocks on completion or error. Status normalization hardens input handling with alias mappings for success/error variants. WorkbenchProvider adds timestamp parsing and fallback mechanisms so blocks use task-level timestamps when missing. Terminal subtask detection and finalization ensure completed/failed/cancelled subtasks have properly coerced block statuses. Extensive code style refactoring updates type layouts, hook dependencies, and method formatting throughout the provider without changing semantics. Tests and type definitions are updated accordingly.

Changes

Block Finalization and Status Normalization

Layer / File(s) Summary
Status normalization and finalization helpers
packages/chat-core/src/workbench-message-reducer.ts, packages/chat-core/src/workbench-message-reducer.test.ts
normalizeWorkbenchBlockStatus now trims, lowercases, and normalizes whitespace/dashes to underscores before mapping, with aliases: completed/complete/succeeded/success → 'done', failed/failure → 'error', defaulting to 'pending'. finalizeProcessingBlocks accepts a finalStatus parameter (default 'done') and coerces all non-terminal blocks to that value after streaming finalization.
Reducer wiring for terminal block states
packages/chat-core/src/workbench-message-reducer.ts, packages/chat-core/src/workbench-message-reducer.test.ts
assistant_done calls finalizeProcessingBlocks(..., 'done') and assistant_error calls finalizeProcessingBlocks(..., 'error') to coerce pending/streaming blocks to the appropriate terminal state. A new test confirms streaming thinking and pending tool blocks are finalized to 'done' on completion.

Subtask Timestamp Fallback and Terminal Finalization

Layer / File(s) Summary
Timestamp parsing and block timestamp extraction
wework/src/features/workbench/WorkbenchProvider.tsx
Introduces parseTimestampMs to parse timestamps with configurable units; getBlockTimestamp extracts timestamps from blocks with unit scaling and fallback. normalizeProcessingBlocks updated to accept fallbackTimestamp so blocks with missing/invalid timestamps use task-level timestamps.
Terminal subtask status detection and block finalization
wework/src/features/workbench/WorkbenchProvider.tsx
Adds isTerminalSubtaskStatus to detect completed/failed/cancelled subtask states; finalizeBlocksForTerminalSubtask coerces block statuses for terminal subtasks (failed → error, others → done). subtaskToMessage computes blockFallbackTimestamp from completed_at/updated_at/created_at, normalizes blocks with fallback, and applies terminal-subtask finalization.

WorkbenchProvider Type Layouts and Code Style

Layer / File(s) Summary
Type layouts, imports, and stored-model normalization
wework/src/features/workbench/WorkbenchProvider.tsx
Reorders type imports; updates WorkbenchServices type formatting for optional API methods; refactors normalizeStoredModelOptions and imports without semantic changes.
Effect and hook code style refactoring
wework/src/features/workbench/WorkbenchProvider.tsx
Refactors bootstrap, device-list caching, execution-mode preference, upgrade-timer, and Promise.allSettled destructuring with updated formatting and dependency lists. All logic and state dispatch semantics preserved.
Message dispatch, task opening, and action method refactoring
wework/src/features/workbench/WorkbenchProvider.tsx
Refactors WebSocket handling, openTask resolution, sendCurrentInput device logic, retryFailedMessage attachment handling, file-diff and queued-message/guidance flows with adjusted formatting and dependencies. High-level behavior preserved.

Type Additions, Configuration, and Test Updates

Layer / File(s) Summary
Subtask type and Prettier configuration
wework/src/types/api.ts, wework/.prettierrc.json
Subtask gains optional completed_at field for tracking completion timestamps. Prettier configuration defined with rules for quotes, semicolons, trailing commas, indentation, and line width. TurnFileChangesStatus reformatted without semantic changes.
Test probe rendering and assertion updates
wework/src/features/workbench/WorkbenchProvider.test.tsx
Test probes reformatted for compact JSX; assertions updated for new probe output (attachment filenames, task IDs, execution mode, device list, model, running tasks). ToolBlockHistoryProbe now renders output plus status; mocked tool data expanded with timestamp/status fields; expected text updated to include :done suffix. Type annotations reformatted without changing contracts.

Sequence Diagram(s)

sequenceDiagram
  participant Reducer as reduceWorkbenchMessages
  participant FPB as finalizeProcessingBlocks
  participant StatusNorm as normalizeWorkbenchBlockStatus
  participant Blocks as message.blocks

  Reducer->>StatusNorm: normalizeWorkbenchBlockStatus(rawStatus)
  Note over StatusNorm: trim, lowercase, normalize whitespace/dashes
  StatusNorm->>StatusNorm: match canonical or alias<br/>(completed→done, failed→error)
  StatusNorm-->>Reducer: WorkbenchToolBlockStatus

  Reducer->>FPB: assistant_done → finalizeProcessingBlocks(blocks, 'done')
  FPB->>Blocks: finalize streaming thinking → 'done'
  FPB->>Blocks: coerce non-final → 'done'
  FPB-->>Reducer: updated blocks

  Reducer->>FPB: assistant_error → finalizeProcessingBlocks(blocks, 'error')
  FPB->>Blocks: finalize streaming thinking → 'done'
  FPB->>Blocks: coerce non-final → 'error'
  FPB-->>Reducer: updated blocks
Loading
sequenceDiagram
  participant Subtask as Subtask (completed/failed/cancelled)
  participant Provider as subtaskToMessage
  participant Parse as parseTimestampMs
  participant Normalize as normalizeProcessingBlocks
  participant Finalize as finalizeBlocksForTerminalSubtask
  participant Message as WorkbenchMessage

  Subtask->>Provider: completed_at/updated_at/created_at
  Provider->>Parse: extract blockFallbackTimestamp
  Provider->>Normalize: normalizeProcessingBlocks(blocks, fallback)
  Normalize->>Normalize: resolve missing timestamps to fallback
  Provider->>Finalize: finalizeBlocksForTerminalSubtask
  Finalize->>Finalize: map failed→error, others→done
  Finalize-->>Message: finalized message with coerced blocks
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~75 minutes

Suggested reviewers

  • qdaxb

Poem

🐰 The timestamps hop in line,
Blocks finalize by design.
Failed becomes error, done stays true,
Subtasks learn their final hue.
The rabbit refactored all on through! ✨

🚥 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 directly addresses the main fix described in the PR objectives: finalizing Codex block timers when blocks are completed. It references the specific component (Codex block) and the core issue (stopping the timer when completed).
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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 and usage tips.

@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.

🧹 Nitpick comments (1)
packages/chat-core/src/workbench-message-reducer.test.ts (1)

78-113: ⚡ Quick win

Add a companion regression test for assistant_error block coercion.

This test covers the new assistant_done finalization path well, but the paired assistant_error path (wired in reducer changes) is still unasserted in this suite. Add one case asserting non-terminal blocks become error on assistant_error.

🤖 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 `@packages/chat-core/src/workbench-message-reducer.test.ts` around lines 78 -
113, Add a new test case after the existing
test_finalizes_incoming_processing_blocks_on_done test to cover the
`assistant_error` action path. This test should follow the same pattern:
dispatch an `assistant_started` action to initialize state, then dispatch an
`assistant_error` action with blocks in non-terminal states (streaming and
pending), and assert that all blocks are transitioned to error status instead of
done status. This ensures the error coercion path in the reducer is properly
tested alongside the done finalization path.
🤖 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.

Nitpick comments:
In `@packages/chat-core/src/workbench-message-reducer.test.ts`:
- Around line 78-113: Add a new test case after the existing
test_finalizes_incoming_processing_blocks_on_done test to cover the
`assistant_error` action path. This test should follow the same pattern:
dispatch an `assistant_started` action to initialize state, then dispatch an
`assistant_error` action with blocks in non-terminal states (streaming and
pending), and assert that all blocks are transitioned to error status instead of
done status. This ensures the error coercion path in the reducer is properly
tested alongside the done finalization path.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 82ed28b7-5b6c-4b27-a071-4c0d9f027b0e

📥 Commits

Reviewing files that changed from the base of the PR and between 8512730 and a8eebc8.

📒 Files selected for processing (2)
  • packages/chat-core/src/workbench-message-reducer.test.ts
  • packages/chat-core/src/workbench-message-reducer.ts

@icycrystal4
icycrystal4 force-pushed the fix/wework-codex-block-duration-clean branch 2 times, most recently from 6b829e6 to f1f7f82 Compare June 15, 2026 07:55
@icycrystal4
icycrystal4 force-pushed the fix/wework-codex-block-duration-clean branch from f1f7f82 to 693c8df Compare June 15, 2026 08:44
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.

2 participants