Stopping duplicate background jobs when a user hits Refresh mid-agent-turn
We've all seen users do this: they submit a complex prompt, the agent takes 12–20 seconds to run three tool calls, and around second 6 they hit browser Refresh (F5).
Because our FastAPI SSE stream lived inside the HTTP request handler:
- Closing the tab didn't always cancel the downstream background work immediately (or worse, it aborted halfway through a DB write).
- On reload, the UI either showed an empty thread or re-submitted the prompt, spawning a second duplicate agent run!
What's the cleanest way to decouple the agent worker from the browser HTTP connection so a page reload just reattaches to the in-progress stream?