Skip to content

fix(agents): clean up orphaned sub-agent sessions on parent reset#508

Closed
sytone wants to merge 1 commit into
mainfrom
fix/orphaned-subagent-sessions
Closed

fix(agents): clean up orphaned sub-agent sessions on parent reset#508
sytone wants to merge 1 commit into
mainfrom
fix/orphaned-subagent-sessions

Conversation

@sytone
Copy link
Copy Markdown
Owner

@sytone sytone commented May 22, 2026

Closes #507

Changes

ISubAgentManager (new method)

  • CleanupChildSessionsAsync(SessionId parentSessionId, CancellationToken ct) — kills running sub-agents for a parent session and archives their child sessions

DefaultSubAgentManager (new impl)

  • Iterates all child sub-agents for the given parent session
  • Cancels each running timeout CTS
  • Calls CleanupChildAgentAsync to stop the agent and unregister from registry
  • Updates sub-agent status to Killed if still running
  • Archives each child session in ISessionStore (non-fatal on failure)

GatewayHub.ResetSession (hooked in)

  • Optional ISubAgentManager param added to constructor
  • Calls CleanupChildSessionsAsync after supervisor stop, before memory flush and session archive
  • Non-fatal: reset proceeds even if cleanup throws

NoOpSubAgentManager in SessionsController

  • Added CleanupChildSessionsAsync returning 0 (no-op)

Tests (6 new)

  • CleanupChildSessionsAsync_ReturnsZero_WhenNoChildrenExist
  • CleanupChildSessionsAsync_ArchivesChildSession_WhenChildExists
  • CleanupChildSessionsAsync_IsNonFatal_WhenSessionArchiveFails
  • CleanupChildSessionsAsync_DoesNotCleanOtherParentSessions
  • ResetSession_CallsSubAgentCleanup_WhenManagerProvided
  • ResetSession_ProceedsNormally_WhenNoSubAgentManager

1642/1642 gateway tests + full suite passing.

Add CleanupChildSessionsAsync to ISubAgentManager and DefaultSubAgentManager.
GatewayHub.ResetSession now calls cleanup before archiving the parent session.
NoOpSubAgentManager in SessionsController updated to implement new method.
6 new tests (4 SubAgentCleanupTests + 2 SignalRHubTests).

Closes #507
Copy link
Copy Markdown
Owner Author

@sytone sytone left a comment

Choose a reason for hiding this comment

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

Farnsworth Review — PR #508

CI: ✅ All checks passing (build-and-test, CodeQL, Security Scan)
Merge conflicts: ✅ Clean (MERGEABLE)
Conventional commit title:fix(agents): clean up orphaned sub-agent sessions on parent reset

Test coverage:

  • ✅ CleanupChildSessionsAsync called on ResetSession
  • ✅ Non-fatal error path (exception swallowed, reset continues)
  • ✅ Happy path with multiple child sessions
  • ✅ No-op when no child sessions exist
  • 6 new tests; 1642/1642 pass

Spec completeness vs OpenClaw finding: Correctly addresses orphaned sub-agent session cleanup. Optional DI param keeps it backward-compatible. NoOpSubAgentManager updated appropriately.

LGTM. Ready to merge.

@sytone
Copy link
Copy Markdown
Owner Author

sytone commented May 22, 2026

Closing as part of a planned hard-reset of the in-flight branch set so the new domain-model refactor can land on a clean trunk.

Audit verdict: close

Rationale: Touches the reset path that Phase 3c rewrites canonically. Will be subsumed.

The new plan (in session state) reshapes core types: Citizen (User+Agent union), Vogen-generated value objects, ThreadId removed in favour of composite ChannelAddress, mark-not-delete compaction, centralised SessionContextProjector, single-path routing. Many in-flight branches touch contracts that are about to change — rebasing later would be more work than rebuilding on the new shape.

If this work is still wanted, refile as a new issue/PR against the post-refactor contracts.

@sytone sytone closed this May 22, 2026
@sytone sytone deleted the fix/orphaned-subagent-sessions branch May 22, 2026 18:47
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.

fix(agents): clean up orphaned sub-agent sessions on parent reset

1 participant