fix(imagine,krea,leonardo): poll for the full genCtx budget instead of a short hardcoded cap
imagine/krea capped polling at 4min and leonardo at 5min while the caller's genCtx budget is 8min, so slow-but-valid generations were killed early with 'generation timed out'. Now the poll deadline tracks ctx.Deadline() minus 60s download headroom (fallback to the old fixed cap if ctx has no deadline). chatgpt already ties its budget to the deadline (pollBudget) and runway/grok honor ctx, so no change needed there.
This commit is contained in:
@@ -252,8 +252,13 @@ func (c *Client) pollImage(ctx context.Context, accessToken, genID string) (stri
|
||||
|
||||
ticker := time.NewTicker(3 * time.Second)
|
||||
defer ticker.Stop()
|
||||
// Cap the wait independent of the parent deadline so a stuck job can't hang.
|
||||
// Poll for the full generation budget (caller's genCtx), leaving headroom for
|
||||
// the download, instead of a shorter hardcoded cap that killed slow jobs early.
|
||||
// ctx already bounds the wait, so a stuck job still can't hang indefinitely.
|
||||
deadline := time.Now().Add(5 * time.Minute)
|
||||
if dl, ok := ctx.Deadline(); ok {
|
||||
deadline = dl.Add(-60 * time.Second)
|
||||
}
|
||||
|
||||
for {
|
||||
body, status, err := c.graphqlP(ctx, accessToken, payload, false)
|
||||
|
||||
Reference in New Issue
Block a user