Skip to content

fix(revived-run-tracker): gate background task notifications behind shouldManageSession - #1086

Open
mhenke wants to merge 1 commit into
alvinunreal:masterfrom
mhenke:omos/fix-1079-bg-lifecycle
Open

fix(revived-run-tracker): gate background task notifications behind shouldManageSession#1086
mhenke wants to merge 1 commit into
alvinunreal:masterfrom
mhenke:omos/fix-1079-bg-lifecycle

Conversation

@mhenke

@mhenke mhenke commented Aug 24, 2026

Copy link
Copy Markdown
Collaborator

Fixes #1079

What problem are you solving?

Background task completion notifications inject promptAsync({ agent: 'orchestrator' }) regardless of the parent session's current mode. When a user switches to Plan or Build, the notification still fires and its agent: 'orchestrator' flows through chat.messagesessionMetadata.setAgent() → flips the session metadata back to orchestrator, re-arming all orchestrator machinery (wake scheduler, tool gates, etc.).

What does this change?

Adds shouldManageSession gate to createRevivedRunTracker. Guard in notifyParent checks whether parent session is still in orchestrator mode before injecting the synthetic prompt. 3 lines in source + 1 test case.

Why this approach?

shouldManageSession is already the canonical predicate for orchestrator-mode gating, used 6+ times across the codebase (wake scheduler, task-session-manager, input-wait-tracker, cancel-task, task-revive, wait-for-user). Direct sessionMetadata access inside the tracker would couple it to a module it does not import. The optional callback preserves backward compatibility — callers that do not pass it get the old behavior.

Related work

AI assistance

  • Model / harness: OpenCode (deepseek-v4-flash) orchestrator; 4 @skeptic subagents for code review ran on opencode/x-preview-f-free (primary, with fallbacks opencode-go/qwen3.7-plus and opencode/qwen3.7-plus per oh-my-opencode-slim.jsonc skeptic preset).
  • Human reviewed the full diff before creating the PR.

Checklist

  • bun run check:ci, bun run typecheck, and bun test pass
  • Docs updated if behavior changed — no doc change needed (internal callback only)
  • One logical change per PR
  • PR targets the master branch

…houldManageSession

- Adds shouldManageSession option to createRevivedRunTracker
- Guards notifyParent with shouldManageSession check
- Wires from src/index.ts using sessionMetadata.getAgent
- Adds test: skips parent notification when shouldManageSession returns false

Fixes alvinunreal#1079
Copilot AI lite review requested due to automatic review settings August 24, 2026 23:42

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@greptile-apps

greptile-apps Bot commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR gates revived-run terminal prompts on the parent session's recorded orchestrator mode to avoid restoring orchestration after a deliberate mode switch.

  • Adds an optional shouldManageSession callback to the revived-run tracker.
  • Wires the callback to session metadata in plugin initialization.
  • Adds coverage for suppressing a terminal prompt when the predicate returns false.

Confidence Score: 4/5

The PR should not merge until the gate distinguishes a genuine mode switch from missing session metadata, which currently drops valid revived-task results.

An idle orchestrator's bounded metadata entry can be evicted while its task runs, after which the new strict gate permanently suppresses the task's terminal notification; suppressed runs are also retained in tracker state.

Files Needing Attention: src/hooks/task-session-manager/revived-run-tracker.ts, src/index.ts

Important Files Changed

Filename Overview
src/hooks/task-session-manager/revived-run-tracker.ts Adds the notification gate, but conflates missing metadata with a mode switch and retains suppressed terminal runs.
src/index.ts Wires the gate to an evictable metadata lookup without the stale-mapping recovery used by sibling subsystems.
src/hooks/task-session-manager/revived-run-tracker.test.ts Covers explicit false suppression but not metadata eviction or cleanup of the suppressed run.

Reviews (1): Last reviewed commit: "fix(revived-run-tracker): gate backgroun..." | Re-trigger Greptile

Comment on lines +234 to +238
if (
options.shouldManageSession &&
!options.shouldManageSession(run.parentSessionID)
)
return;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 Missing metadata drops notifications

When an idle orchestrator parent is evicted from the bounded session-metadata store while its task runs, shouldManageSession returns false and this new gate permanently drops the task's terminal completion or error notification. Missing metadata is recoverable rather than an authoritative mode switch, as sibling orchestrator gates restore stale mappings through registerSessionAsOrchestrator.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Comment on lines +234 to +238
if (
options.shouldManageSession &&
!options.shouldManageSession(run.parentSessionID)
)
return;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Suppressed runs remain tracked

When this gate suppresses a terminal notification, it returns without discarding the completed run, retaining its RevivedRun entry until replacement or plugin disposal and causing unnecessary lifetime memory growth.

Suggested change
if (
options.shouldManageSession &&
!options.shouldManageSession(run.parentSessionID)
)
return;
if (
options.shouldManageSession &&
!options.shouldManageSession(run.parentSessionID)
) {
discardRun(run);
return;
}

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 task lifecycle forces Orchestrator after switching parent to Plan or Build

2 participants