Files
openclaw/packages/ai
大村愛弥 793f602f80 fix: remove bodyless 400/413 from overflow patterns to prevent false compaction (#119596)
* fix: remove bodyless 400/413 from overflow patterns to prevent false compaction

PR #67024 fixed the failover classification path (errors.ts) to not
classify bodyless 400/422 as 'format' errors. However, the compaction
trigger path (isContextOverflow in overflow.ts) still has the pattern
/^4(?:00|13)\s*(?:status code)?\s*\(no body\)/i in OVERFLOW_PATTERNS.

This means a bodyless 400 from any provider triggers compaction via
checkCompaction() -> isContextOverflow(), even though PR #67024
ensured the failover reason is null (not 'format'). The two paths are
independent: failover classification and compaction triggering use
separate functions.

A bodyless 400 cannot be a context overflow — real overflow errors
from all major providers include a descriptive body. A bare 400 with
no body is a transient/malformed error that should surface to the
user, not trigger a compaction loop.

Remove the Cerebras-specific pattern from OVERFLOW_PATTERNS. If
Cerebras returns bodyless 400/413 for actual overflow, it should be
handled with a more specific pattern or NON_OVERFLOW_PATTERNS exclusion.

AI-assisted.

* fix(ai): avoid compacting on bodyless 400 errors

---------

Co-authored-by: lykeion-dev <lykeion-dev@users.noreply.github.com>
Co-authored-by: Patrick Erichsen <patrick.a.erichsen@gmail.com>
2026-08-05 20:53:02 -07:00
..

@openclaw/ai

Reusable model API contracts, provider adapters, and streaming primitives from OpenClaw. The package supports isolated runtime instances; importing it does not register providers globally.

import { createLlmRuntime } from "@openclaw/ai";
import { registerBuiltInApiProviders } from "@openclaw/ai/providers";

const runtime = createLlmRuntime();
registerBuiltInApiProviders(runtime.registry);

Provider-neutral contracts, validation, diagnostics, and event streams are available from the package root and focused subpaths such as @openclaw/ai/event-stream, @openclaw/ai/transports, and @openclaw/ai/validation. No second OpenClaw runtime package is required.

Provider ids, credentials, model catalogs, retries, and failover remain application concerns. OpenClaw supplies those policies around this package. Host policy (request fetch guarding, secret redaction, strict-tool defaults, provider plugin hooks, and diagnostics logging) can be injected with configureAiTransportHost; the defaults are inert.

The explicit @openclaw/ai/internal/anthropic, openai, retry-after, runtime, and shared subpaths exist for the OpenClaw application itself. They carry no semver guarantee and can change or disappear in any release; do not depend on them outside OpenClaw.