Skip to content

Cancellation path never drains passive observer tasks, losing the side effects on_loop_cancelled exists to release #4

Description

@zhanghanduo

BaseObserver.on_loop_cancelled exists precisely because "cancellation bypasses on_loop_end". But the drain in notify_observers is keyed on on_loop_end alone:

if method == "on_loop_end":
    await drain_background_observers()

Consequence: on the cancellation path, passive tasks already scheduled — trajectory writes, metric flushes, event-sink appends — are never awaited. When the enclosing task tree is cancelled and the event loop closes, they are dropped: exactly the side effects the hook is meant to release.

Fix direction: drain on on_loop_cancelled too. Interacts with #2 — the drain should become loop-scoped in the same change rather than twice.

Provenance: pre-existing in ApodexHarness/miroharness/core/loop_types.py, ported verbatim by #1 — not introduced by the refactor. ApodexHarness carries the same code and needs the same change until it consumes AgentCore.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions