Skip to content

fix: handle undefined sessionStatus in pollRunningTasks (#2387)#2388

Merged
code-yeongyu merged 1 commit intodevfrom
fix/background-output-undefined-status-2387
Mar 8, 2026
Merged

fix: handle undefined sessionStatus in pollRunningTasks (#2387)#2388
code-yeongyu merged 1 commit intodevfrom
fix/background-output-undefined-status-2387

Conversation

@code-yeongyu
Copy link
Copy Markdown
Owner

@code-yeongyu code-yeongyu commented Mar 8, 2026

Summary

  • Fix pollRunningTasks() in BackgroundManager to handle undefined sessionStatus (when completed sessions are no longer in the status response)
  • Match the sync-session-poller pattern: only skip completion check when status EXISTS and is not idle; when undefined, fall through to completion detection
  • Add 3 tests covering undefined, idle, and busy sessionStatus scenarios

Root Cause

When session.status() stops returning a completed session, allStatuses[sessionID] is undefined. The old code only handled idle explicitly, treating undefined as "still running" — which left the task stuck in running status forever.

Fix

Restructured the control flow in pollRunningTasks():

  1. Check retry first (preserve existing retry handling)
  2. Use inverse logic: if (sessionStatus && sessionStatus.type !== "idle") { continue } — only continue if status exists AND is not idle
  3. Fall through to validateSessionHasOutput + checkSessionTodos + tryCompleteTask for both idle AND undefined cases

This matches the pattern already used in sync-session-poller.ts:75.

Closes #2387


Summary by cubic

Fixes background task polling so a missing session status no longer leaves tasks stuck in "running". Matches sync-session-poller behavior and adds tests for undefined, idle, and busy states.

  • Bug Fixes
    • Update pollRunningTasks() in BackgroundManager to handle undefined sessionStatus by running completion checks (validate output, check todos, then complete).
    • Only skip completion when status exists and is not idle; keep retry handling and improve logs.
    • Add tests covering undefined, idle, and busy session status scenarios.

Written for commit dc370f7. Summary will update on new commits.

When a completed session is no longer returned by session.status(),
allStatuses[sessionID] is undefined. Previously this fell through to
a 'still running' log, leaving the task stuck as running forever.

Match the sync-session-poller pattern: only continue (skip completion
check) when sessionStatus EXISTS and is not idle. When undefined,
fall through to validateSessionHasOutput + checkSessionTodos +
tryCompleteTask, same as idle.
@code-yeongyu
Copy link
Copy Markdown
Owner Author

@cubicdev please review

Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 2 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Auto-approved: Fixes a bug where tasks got stuck by treating undefined session status as potentially completed, with safety checks and tests included. Matches existing poller patterns.

@code-yeongyu code-yeongyu merged commit beb89fa into dev Mar 8, 2026
8 checks passed
@code-yeongyu code-yeongyu deleted the fix/background-output-undefined-status-2387 branch March 8, 2026 14:55
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.

background_output can report completed background tasks as running while session_info/session_read show finished results

1 participant