Skip to content

fix: prune missing task sessions#6

Open
jackjinke wants to merge 2 commits into
prevalentWare:mainfrom
jackjinke:main
Open

fix: prune missing task sessions#6
jackjinke wants to merge 2 commits into
prevalentWare:mainfrom
jackjinke:main

Conversation

@jackjinke

@jackjinke jackjinke commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Summary

  • retry briefly when a known running child task disappears from live session status
  • prune still-missing child tasks as unobservable so they no longer block goal continuation
  • write continuation debug logs as per-session JSONL files behind the debug_log option, which is disabled by default

Why

Goal continuation defers while child tasks are active so the parent session does not continue before background agents finish. That is correct while a child task is visibly running, but it can deadlock when OpenCode can no longer observe that child session.

A child task can disappear from status after an interrupt, terminating/restarting OpenCode, moving the session to a different folder, or other session-lifecycle edge cases. In that state the plugin only remembers an old running task record, while live status returns missing/null. Since there is no terminal event to reconcile, the old task can block continuation forever.

I hit this during development: a background agent hung, I restarted OpenCode, then asked for goal continuation. The plugin did not recognize that the task had already completed or was gone, so continuation stayed blocked by the stale child task.

This change treats missing live status as unknown/unobservable: wait a short grace period, then prune the stale task record without requiring parent reconciliation.

Manual test

  • Tested this version against a session that did not trigger goal continuation; goal continuation worked

Validation

  • bun run typecheck
  • bun test
  • bun run lint
  • bun run build

@jackjinke

jackjinke commented Jul 2, 2026

Copy link
Copy Markdown
Contributor Author

Note: a continuation alone may not be enough here.

Agents can be constrained by event-driven background-task handling: they may wait for completion events rather than polling running tasks. If a child task dies or disappears, that event may never arrive, and since continuation prompt itself is untouched in this change, main agent may still think it can wait for task-status to come back and stops, which would trigger continuation again until turn threshold is reached.

A potential fix to this would be add information of dead tasks in the continuation prompt, however I'm not sure if this is desirable.

@jackjinke jackjinke marked this pull request as ready for review July 2, 2026 06:27
@danyel117

Copy link
Copy Markdown
Contributor

Thanks, this is a useful fix direction and the local gates pass.

I found one blocker before merge: the stale-task pruning only handles a known child that is still returned by session.children() but has missing/null live status. If an already tracked running task disappears from session.children() entirely, refreshLiveChildren() returns without marking it missing, so the old running task remains in tasks and hasBlockingTasks() can keep blocking continuation forever.

Could you also handle tracked running child task IDs that are absent from the live children list, and add a regression test for:

  • task is observed as running
  • later session.children() returns []
  • after the grace period, continuation is no longer blocked

Optional: if debug_log is intended as a public plugin option, please document it in README; otherwise I’m fine treating it as internal diagnostics.

@jackjinke

jackjinke commented Jul 3, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the detailed review! Updated and pushed the fix:

  • Rebased on latest upstream/main.
  • Handled tracked running child tasks disappearing from session.children().
  • Added regression coverage for running → children=[] → unblocked after grace.
  • Re-ran local gates: lint, typecheck, tests, build, pack dry-run.

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