stage: retry pre-admission harness reach failures and widen repair deadline
Treat a failure to reach the harness before any prompt or tool call is admitted (connecting or creating the session) as a distinct retryable reach failure, so a transport blip at the first stage no longer ends a mutating run; keep post-admission readback/poll/agent failures retried only on an explicit read-only stage and never replay admitted tool work. Preserve the true cause when the context is already done (join ctx.Err with the typed transport error) and report a sanitized unknown provider error name/status instead of a blanket summary. Make the isolated format-repair deadline proportional to the stage timeout (floored, capped and clamped to remaining minus a margin) so a slow-but-repairable result is recovered without ever extending the stage deadline; the bounded ladder, value guard, deny-all formatter session, cumulative usage accounting and no-tool-replay rule are unchanged. Update docs/model-results.md, docs/pipeline-performance-review.md and the packaged skill references; add stage, opencode and server fixtures.
This commit is contained in:
+40
-9
@@ -27,15 +27,42 @@ const (
|
||||
// diagnostics. It states the retained side effects and the cost of a full retry.
|
||||
const finalResultGuidance = "completed edits and tool side effects are retained and not undone; a full retry repeats work"
|
||||
|
||||
// harnessTransportFailure is the single classifier shared by both transport
|
||||
// sentinels and the typed OpenCode error: a request, poll or readback failure
|
||||
// that reports as the fixed HARNESS TRANSPORT category. A bare context deadline
|
||||
// is classified separately so a genuine stage overrun is never relabeled as a
|
||||
// transport failure.
|
||||
func harnessTransportFailure(err error) bool {
|
||||
var openCode *openCodeError
|
||||
return errors.Is(err, ErrHarnessUnreachable) || errors.Is(err, ErrHarnessTransport) || errors.As(err, &openCode)
|
||||
}
|
||||
|
||||
// harnessReachFailure reports whether err is a pre-admission harness reach
|
||||
// failure. It is distinct from a post-admission ErrHarnessTransport failure: no
|
||||
// session or prompt was admitted, so the retry replays no work.
|
||||
func harnessReachFailure(err error) bool {
|
||||
return errors.Is(err, ErrHarnessUnreachable)
|
||||
}
|
||||
|
||||
// admittedWorker is implemented by a client that can admit tool work before its
|
||||
// final result is read, so the retry loop can refuse to replay it without a
|
||||
// per-client type switch.
|
||||
type admittedWorker interface{ workAdmitted() bool }
|
||||
|
||||
// workAdmitted reports whether the client admitted any prompt or tool call, so
|
||||
// the retry loop may retry a transport failure on any stage only when it is
|
||||
// false, and only a read-only stage otherwise.
|
||||
func (c *AgentClient) workAdmitted() bool { return c.WorkStarted }
|
||||
func (c *PiClient) workAdmitted() bool { return c.WorkStarted }
|
||||
|
||||
// modelFailureCategory classifies a stage failure using error identity only, so
|
||||
// the label stays sanitized and bounded. Validation is checked first: a
|
||||
// structured-output failure is never reported as a transport failure and vice versa.
|
||||
func modelFailureCategory(err error) string {
|
||||
var openCode *openCodeError
|
||||
switch {
|
||||
case errors.Is(err, ErrInvalidModelResult):
|
||||
return finalResultValidation
|
||||
case errors.Is(err, ErrHarnessTransport), errors.As(err, &openCode), errors.Is(err, context.DeadlineExceeded):
|
||||
case harnessTransportFailure(err), errors.Is(err, context.DeadlineExceeded):
|
||||
return harnessTransport
|
||||
default:
|
||||
return ""
|
||||
@@ -294,15 +321,19 @@ func (m ModelStage) Run(ctx context.Context, def Definition, input Values) (Resu
|
||||
break
|
||||
}
|
||||
replayPostAdmission = safeToReplay(def) && replayablePostAdmission(err)
|
||||
// Never blindly replay admitted tool work: only a read-only stage may
|
||||
// retry a post-admission deadline or transport failure.
|
||||
if agent, ok := client.(*AgentClient); ok && agent.WorkStarted && !replayPostAdmission {
|
||||
// A reach failure observed before any work was admitted replays
|
||||
// nothing, so it is retryable within the existing budget for any
|
||||
// stage. After admission, only an explicit read-only stage may
|
||||
// retry; admitted tool work is never replayed.
|
||||
workStarted := false
|
||||
if worker, ok := client.(admittedWorker); ok {
|
||||
workStarted = worker.workAdmitted()
|
||||
}
|
||||
if workStarted && !replayPostAdmission {
|
||||
break
|
||||
}
|
||||
if pi, ok := client.(*PiClient); ok && pi.WorkStarted && !replayPostAdmission {
|
||||
break
|
||||
}
|
||||
if attempt == spec.Config.Retries || (!retryableModelError(err) && !errors.Is(err, context.DeadlineExceeded) && !replayPostAdmission) {
|
||||
preAdmissionReach := !workStarted && harnessReachFailure(err)
|
||||
if attempt == spec.Config.Retries || (!retryableModelError(err) && !errors.Is(err, context.DeadlineExceeded) && !replayPostAdmission && !preAdmissionReach) {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user