Files
opencode2api/internal
mcheiyue 5076226ac2 fix: bound each upstream attempt by the full attempt deadline
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.
2026-10-11 19:42:51 +08:00
..