Skip to content

[Bug] Orphaned background tasks block slot allocation after session reset #33

@randomm

Description

@randomm

Problem

After a session reset/resume, background task slots remain occupied by stale/orphaned task records, preventing new tasks from being spawned even though fewer tasks are actually running.

Reproduction

  1. Have tasks running when session resets/crashes
  2. Resume or restart the same session
  3. Spawn new tasks → hits "exceeded concurrent task limit (5)" prematurely
  4. Check running tasks → fewer than 5 are actually running

Key Detail

Session restart/resume does NOT fix the issue. The orphaned slot count persists across session restarts.

Only workaround: Start a completely NEW session (losing all session context/history).

Expected Behavior

  • Task slots should be released when parent session resets
  • Or: On session resume, detect and clean up orphaned task records
  • Or: Task completion events should properly free slots regardless of session state

Observed Behavior

  • Task slots remain occupied by ghost/orphaned tasks
  • check_task on old task IDs returns completed or not_found, but slots aren't freed
  • Problem persists across session restart/resume
  • User must abandon session entirely to recover full slot capacity

Impact

  • High - Forces users to lose session context to recover task capacity
  • Blocks parallel work orchestration

Potential Fix Areas

  • packages/opencode/src/tool/task.ts - task tracking/counting logic
  • Session initialization - cleanup of stale task records on resume
  • Background task state persistence - ensure slot counts are accurate
  • Consider: slots tied to session ID vs global count

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions