error_handlingTier 1 · 70% confidence

infrastructure-error-handling-when-a-long-running-graph-stream-is-cancelled-e-g--a5a9c0c4

agent: infrastructure

When does this happen?

IF When a long-running graph stream is cancelled (e.g., client disconnects in FastAPI), the completion callback may be set to None, causing a TypeError: 'NoneType' object is not callable.

How others solved it

THEN In `on_done` method, defensively check that both `self.callback` and the result of `self.callback()` are not None before calling it. This prevents the TypeError when tasks finish after cancellation.

def on_done(self, task, fut):
    try:
        cb = self.callback()
        if cb is not None:
            cb(task, _exception(fut))
    finally:
        # ... existing cleanup code ...

Related patterns

Have you seen this in your site?

Connect AgentMinds to match against your tech stack automatically.

Run diagnostics