Files
cobble/src/harness/harness-error.ts
T
tben 2afe35954c Size runs to the model's own window, and stop a run reading notes instead of answers
The working context was 70% of the model's window, and a model whose
catalog never declared one got 70% of a guessed 131,072: a chat on a
custom provider was told it had 91,750 tokens, then had every tool result
trimmed to a bare note, including a 14-character shell answer, and spent
its remaining steps reading nothing.

- workingContextTokens: the declared window less the room the answer
  needs (max_output_tokens, else a tenth clamped to 8,000-64,000),
  capped by grabContextBudgetTokens when an install sets one.
- An undeclared window is assumed to be 1,000,000, and the guess is not
  silent: the picker marks such a model and the Models page says what a
  run works to. A provider that refuses the prompt for size stops the
  run with its own limit (fatal: no fallback, no rest, no retry).
- fitTranscriptToContext: a result under 2,000 characters is never cut,
  a trimmed one keeps its start and its end, and the newest turn's
  results are cut last. over_budget says whether the static prompt or
  the request is over; the static case stops the run at once instead of
  trimming every turn.
- Built-in tools are deferred by family (groupTools, ToolGroups) on a
  model short of window; load_tools takes a family name or a prefix.
  Wrap-up tools, closing tools and load_tools are never deferred.
- Usage reports what the app's own prompt and tools took before the
  conversation did.
2026-11-22 12:35:17 +01:00

101 lines
2.8 KiB
TypeScript

/**
* - `provider`: the provider refused or failed the call
* - `unavailable`: no model is set up (or left) for the harness
* - `aborted`: the caller cancelled
*/
export type HarnessErrorCode = "provider" | "unavailable" | "aborted";
type Params = {
message: string;
code?: HarnessErrorCode;
status?: number;
retryable?: boolean;
retry_at?: number;
provider_wide?: boolean;
candidate_key?: string;
resting?: boolean;
/**
* The request that failed: a 404 on a provider that has no endpoint at
* that address is only diagnosable with both in the message.
*/
method?: string;
url?: string;
/**
* The model the provider knew the call by. The caller that ran the
* candidate stamps it, so a tool can name the model the setting picked
* instead of leaving the bot to guess one.
*/
model_name?: string;
/**
* No fallback and no retry can help: another model fails the same way
* (or the caller's own prompt is the problem), so the run stops with
* this message rather than spending the next candidate on it.
*/
fatal?: boolean;
};
/**
* A failed harness call. Its message is safe to show the user.
*/
export default class HarnessError extends Error {
code: HarnessErrorCode;
status?: number;
/**
* Worth trying again later (rate limit, outage, timeout). False when
* only a different model or setting can help.
*/
retryable: boolean;
/**
* Unix ms before which the failed candidate shouldn't be tried again.
*/
retry_at?: number;
/**
* The provider's key or account is the problem, so every model on it
* fails the same way.
*/
provider_wide: boolean;
candidate_key?: string;
/**
* No model was tried: every one is cooling down until `retry_at`. A
* queued job waits instead of using up an attempt.
*/
resting: boolean;
method?: string;
url?: string;
model_name?: string;
/**
* Nothing else can be tried: `withCandidates` rethrows it at once,
* without resting the candidate or falling back to another model.
*/
fatal: boolean;
constructor({
message,
code = "provider",
status,
retryable = false,
retry_at,
provider_wide = false,
candidate_key,
resting = false,
method,
url,
model_name,
fatal = false,
}: Params) {
super(message);
this.name = "HarnessError";
this.code = code;
this.status = status;
this.retryable = retryable;
this.retry_at = retry_at;
this.provider_wide = provider_wide;
this.candidate_key = candidate_key;
this.resting = resting;
this.method = method;
this.url = url;
this.model_name = model_name;
this.fatal = fatal;
}
}