Skip to content

fix(background-agent): preserve terminal tasks until notification cleanup#2367

Open
code-yeongyu wants to merge 2 commits intodevfrom
fix/issue-2292
Open

fix(background-agent): preserve terminal tasks until notification cleanup#2367
code-yeongyu wants to merge 2 commits intodevfrom
fix/issue-2292

Conversation

@code-yeongyu
Copy link
Owner

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

Summary

  • keep session.error and session.deleted tasks in memory until the parent notification queue runs, so terminal tasks do not disappear before their result can be surfaced
  • move pending-parent cleanup to notification time so simultaneous completions only emit one final all-complete notification
  • skip terminal tasks during TTL pruning and cover the regressions with background-agent tests

Testing

  • bun test src/features/background-agent/
  • bun run typecheck
  • bun run build

Closes #2292


Summary by cubic

Fixes #2292 by preserving terminal background tasks until the parent notification runs, so results don’t disappear. Cleanup is deferred to notification time and TTL pruning skips terminal tasks.

  • Bug Fixes
    • Keep completed/error/cancelled/interrupt tasks in memory until notifyParentSession runs.
    • Defer pendingByParent cleanup to notification time; coalesce simultaneous completions into one final “all complete” notification.
    • Skip terminal tasks during pruneStaleTasksAndNotifications; add tests to cover this.
    • On session.deleted: cancel descendants, remove toast entries, keep tasks until delayed cleanup, and preserve completion timers.

Written for commit 3b58828. Summary will update on new commits.

Copy link

@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 4 files

Confidence score: 5/5

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

Requires human review: Moving cleanup to async notification paths and removing the TTL pruning safety net for terminal tasks could lead to memory leaks if timers or notifications fail to fire.

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.

BackgroundManager: tasks silently disappear during runtime (4 related bugs in task lifecycle)

1 participant