Engineering Blog

Engineering: Mastering AbortController for Orphaned Demands

Why stopping a stream visually implies nothing about network closure, and how to fix it.

The Orphan Stream Reality

When a user clicks "Stop Generation", simply wiping the interface text buffer does not sever the underlying TCP connection to Anthropic or OpenAI. The lab will continue to compute tokens and bill your account in the background.

Implementing AbortController

We strictly mandate the binding of native `AbortController` signals to every single HTTP `fetch()` request generated by Duplex.

Network Abort Method
const controller = new AbortController(); fetch("https://api.openai.com/v1/chat/completions", { method: "POST", signal: controller.signal }); // To stop billing immediately: controller.abort();