Skip to content

Context window exhaustion returns status 'failed' instead of 'exhausted' #977

@pmella

Description

@pmella

Environment

  • @github/copilot-sdk: 0.1.32
  • @github/copilot (CLI): 1.0.6

Description

The OrchestratorResult type defines an 'exhausted' status, but when the Anthropic API returns "prompt is too long: N tokens > 200000 maximum", the GHCP orchestrator maps this to status: 'failed' with the raw API error string. There's no way to distinguish context exhaustion from other failures without parsing the error message.

Impact

Consumers must use fragile regex matching on result.error to detect context exhaustion, instead of checking result.status === 'exhausted'. This is error-prone and breaks if the API error message format changes.

Expected behavior

When the API returns a context window / token limit error (HTTP 400 with invalid_request_error containing "prompt is too long" or similar), the SDK should set status: 'exhausted' on the result.

Current workaround

Regex matching:

const isContextExhausted = result.error
    ? /\b(prompt\s+is\s+too\s+long|input\s+tokens\s+exceed|context\s+limit)\b/i.test(result.error)
    : false;

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions