OpenProgram Docs

Request repair

Every provider stream passes through it: streaming.stream._metered calls request_repair.prepared before the provider and reads its events through request_repair.repairing.

HookWhenAnswers
before_sending(model, context)Before every requestThe context with earlier lessons applied
after_refusal(model, context, refusal)An attempt ended in an error before saying anythingThe mended context, or None if unknown

REPAIRS: prefill, then body_cap. The first mended request goes again, at most MAX_RESENDS (3) times.

Stream ruleDetail
EventsNever held back; the consumer sees the reply begin once
ResendIts first start is dropped; the refusal is not passed on
After anything beyond startEvents pass through, nothing is resent
CancelRepairingStream.cancel_producer closes the current provider stream, with the same bounded wait
Refusal no repair knowsGoes on to retry and failover

The two repairs

Body capPrefill
RefusalStatus 413, or body, request, payload or entity too large; not a context overflow (utils/failures/overflow.py)"does not support assistant message prefill", "Requests ending with a model turn are not supported", "last message cannot be from the assistant"
Seen onAnthropic's 32 MB request_too_large, relaysAnthropic models behind some gateways, Volcengine Agent Plan, Gemini on Vertex AI
LearnsThe smallest size named below what was sent, else ¾ of what was sentThat this model refuses
Remembered perProvider and base URLProvider, API and model
MendsFits to ¾ of the cap: oldest history images replaced one by one with a noteAdds a user turn Continue.
Leaves aloneThe latest user message's images, all text, a tool result's wordsA conversation ending with a tool call
Gives upEvery earlier image out and still too big: refusal goes on–

The note: [An earlier image was left out: the request was over the provider's size limit.] The ¾ margin lets a conversation grow a few turns before more images go, so its prompt cache is not broken every turn.

Files
FileHolds
models/providers/utils/failures/request_repair.pyprepared, repairing, order
models/providers/utils/failures/body_cap.pySize refusals, caps, fitting
models/providers/utils/failures/prefill.pyPrefill refusals, per-model memory
models/providers/streaming/stream.py_metered

Both memories last for the process; tests/conftest.py clears them after each test. The repairs follow magpie's body cap and prefill memory (yetone/magpie, MIT).

Last updated · 2026-11-25