mirror of
https://github.com/jasonxu114514/opencode2api.git
synced 2026-12-05 08:02:53 +00:00
performance.attempt_timeout_seconds only maps to http.Transport.ResponseHeaderTimeout, which starts after the request body is written and stops at the response headers. An exit that wedges during dial or request-write hangs with no timer running and can consume the entire request budget on its own; the attempts that follow are then fired against an already-expired context. Wrap every attempt in a context deadline covering dial + request write + response headers + first event. Release it atomically the moment a response is committed so the deadline can never cut an established stream (a stop-the-timer race at the first-event boundary is closed by deciding "deadline fired" vs "commit response" under one lock). Also tag each failed attempt with the phase it died in (dial / write / headers / first_event) so a hung exit is attributable from the request log alone, and classify the attempt timeout as its own leg instead of the generic transport bucket. Adds unit tests for the deadline cut, the release-after-first-event boundary, the phase classification and error unwrapping.