The fix distinguishing between beadsCompleted (all processed) and beadsSucceeded (successful completions only) was already implemented in stuckDetection.ts and store.ts. No code changes needed - verified all tests pass.
56 lines
2.3 KiB
Markdown
56 lines
2.3 KiB
Markdown
# Fix for beadsCompleted vs stuck detection metric discrepancy (bf-27e4)
|
|
|
|
## Problem
|
|
The `/api/workers` endpoint returned contradictory data per worker:
|
|
- `beadsCompleted: 285` (counts bead.released events)
|
|
- `stuck: true, stuckReason: 'Running for 2311m with only 1 completion(s)'`
|
|
|
|
The stuck detection was counting a different metric (successful completions) while `beadsCompleted` counted all beads released (including timed-out/deferred). When all beads timed out and were deferred, `beadsCompleted` incremented but the stuck detector saw zero successful completions and flagged the worker as stuck.
|
|
|
|
## Solution (Already Implemented)
|
|
|
|
The fix was already in place in the codebase:
|
|
|
|
### 1. WorkerInfo Type Definition (src/types.ts)
|
|
```typescript
|
|
export interface WorkerInfo {
|
|
/** Total beads processed (bead.released events with release_success, includes timed-out/deferred) */
|
|
beadsCompleted: number;
|
|
|
|
/** Total beads successfully completed (bead.completed events only, excludes timed-out/deferred releases) */
|
|
beadsSucceeded: number;
|
|
|
|
/** Total beads that timed out or were deferred (subset of beadsCompleted) */
|
|
beadsTimedOut: number;
|
|
// ...
|
|
}
|
|
```
|
|
|
|
### 2. Stuck Detection (src/tui/utils/stuckDetection.ts)
|
|
The `detectLongRunning` function now properly distinguishes between processed and successful completions:
|
|
- Uses `worker.beadsCompleted` for total processed beads
|
|
- Uses `worker.beadsSucceeded` for successful completions only
|
|
- Uses `worker.beadsTimedOut` for timed-out/deferred count
|
|
- Generates clear reason messages:
|
|
- "X processed but 0 successful completions (all timed out/deferred)"
|
|
- "X processed but only Y successful completion(s) (Z timed out/deferred)"
|
|
|
|
### 3. Store Tracking (src/store.ts)
|
|
The store properly increments the counters:
|
|
- `beadsCompleted++` on `bead.released` with `release_success` (line 716)
|
|
- `beadsSucceeded++` on `bead.completed` (line 702)
|
|
- `beadsTimedOut++` when outcome is `TimedOut` or `Deferred` (line 720)
|
|
|
|
## Verification
|
|
All tests pass:
|
|
```bash
|
|
npm test -- src/tui/utils/stuckDetection.test.ts
|
|
# 18 tests passed
|
|
```
|
|
|
|
## Acceptance Criteria Met
|
|
- ✓ A worker that processes 100 beads (all timed out) shows clearly in the UI that it processed 100 but completed 0 successfully
|
|
- ✓ The stuck flag still fires but the reason text is accurate
|
|
|
|
## Status
|
|
Fix already implemented and tested. No code changes needed.
|