Repository navigation
fix(openai): unify server-side compaction gates and harden compaction recovery - #123397
Conversation
…nt through runtime facade
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed August 13, 2026, 11:17 PM ET / August 14, 2026, 03:17 UTC. ClawSweeper reviewWhat this changesThis PR centralizes eligibility and threshold calculation for OpenAI Responses server-side compaction, while adding recovery fixes and regression tests for related compaction failures. Merge readinessKeep open for maintainer handling: the item carries the protected Priority: P2 Review scores
Verification
How this fits togetherThe agent runner decides when to compact local conversation history before a provider call. OpenAI Responses routes can request provider-side compaction instead, so preflight and transport payload construction need the same route and threshold decision. flowchart LR
A[Agent session] --> B[Local preflight gate]
B --> C[Shared compaction plan]
C --> D[Responses payload policy]
D --> E[OpenAI or Azure route]
E --> F[Compacted response]
F --> G[Replay and recovery]
Decision needed
Why: The PR intentionally changes when existing routes defer local compaction, and protected maintainer handling requires an explicit merge decision after route validation. Before merge
Agent review detailsSecurityNone. PR surfaceSource +39, Tests +358, Docs +6, Config +8, Other +7. Total +418 across 34 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Validate exact-head fresh and upgraded configurations across direct OpenAI, Azure, ChatGPT OAuth, custom-proxy, and Do we have a high-confidence way to reproduce the issue? Unclear: the PR describes focused live and test reproductions, but the review environment could not inspect the implementation or execute the supplied paths. Is this the best way to solve the issue? Unclear: centralizing the two gates is plausible, but the required owner-boundary, caller, sibling-route, and upgrade review could not be completed locally. AGENTS.md: unclear because the file could not be read completely. Codex review notes: model internal, reasoning high; reviewed against 502bdb2bb789. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (1 earlier review cycle)
|
|
Merged via squash.
|
… recovery (openclaw#123397) * fix(openai): unify server compaction policy * fix(openai): preserve managed responses aliases * fix(compaction): harden bounded recovery * refactor(compaction): simplify orphan output classifier * fix(compaction): unanchor overflow classifiers and route image constant through runtime facade * test(openai): use provider input config in compaction parity * test(openai): model default compaction route accurately * fix(openai): isolate responses payload policy imports * fix(ai): remove unused responses api re-export * fix(plugins): resolve responses policy source alias
What Problem This Solves
Two disagreeing definitions of "OpenAI server-side compaction is enabled" existed. The host gate (
resolveResponsesServerCompactionThresholdinsrc/auto-reply/reply/memory-flush.ts) decided from theresponsesServerCompactionparam alone (default-on for provideropenai) and raised/delayed the client-side preflight compaction threshold whenresponsesCompactThresholdwas set. The transport gate (packages/ai/src/transports/openai-responses-payload-policy.ts) additionally requires a store-capable native route, which excludesopenai-chatgpt-responses(OAuth), non-native base URLs, Azurecognitiveserviceshosts, andsupportsStore: falsemodels.Failure mode: a ChatGPT-OAuth session with
responsesCompactThresholdconfigured delayed client compaction while the transport never injectedcontext_management— neither side compacted until hard overflow. Separately, the transport auto-injected a defaultcompact_threshold(70% of context window) the host never learned, so client and server compaction raced blindly.A compaction review sweep also surfaced bounded adjacent bugs fixed here (see below).
Why This Change Was Made
resolveOpenAIResponsesServerCompactionPlan(payload policy). The transport policy consumes it internally; the host resolver consumes it with catalog-resolved model facts. A 10-route parity table test asserts host-gate enablement === transport-gatecontext_managementinjection (OpenAI default/native, OAuth, Azure both host families, casing,supportsStore:false, proxy, explicit on/off).OPENAI_RESPONSES_APISalias set (now includingopenclaw-azure-openai-responses-transport) is exported once fromopenai-responses-contracts.tsand consumed by the payload policy, transcript redaction, and the transport alias map — previously the proxy/TLS transport rewrite silently disabled store forcing andcontext_managementfor Azure routes.cognitiveservices.azure.com,services.ai.azure.com, andapi.cognitive.microsoft.comhosts as Azure OpenAI (matching the Azure provider's supported hosts).input length and `max_tokens` exceed context limit: N + M > K) is now classified as assistant-error overflow (compact-and-retry instead of failover), unanchored so wrappedHTTP 400: {json}transport errors match; the observed-token extractor parses the colon-sum form.shouldCompactrejects non-positive/non-finite context windows (previouslycontextWindow: 0compacted after every turn).function_call_outputrejection (call_id inside the encrypted compaction blob) now routes to the compaction-stripped full-history retry instead of failing the turn.baseUrlHashnow logs at debug level.partialSummarynon-null assertion; clarified the diagnostic-only prompt-pressure precheck comment.Known limitation (no regression): the host resolver reads config/catalog-resolved routes; an OAuth auth-profile that later selects the ChatGPT backend at runtime is not observable pre-turn. That case previously mis-raised the threshold; now it behaves the same as before at worst.
Deliberately out of scope (companion work in flight): WebSocket-transport compaction fallback, Anthropic server-side compaction (
compact_20260112) adoption. Named follow-ups: persisting the compaction-suppression tombstone when the retried turn fails;replayIndexcontent-identity guard (blocked on the closed worker-admission schema); CodextokensAfterrefresh after native compaction.User Impact
supportsStore: falsesessions no longer get their client-side compaction delayed by a server threshold that never applies.request.proxy/request.tlsregain store forcing and server-side compaction.max_tokenscontext-limit error now auto-compact instead of failing over or surfacing the error.Evidence
src/agents/openai-responses-payload-policy.test.ts; host-gate tests insrc/auto-reply/reply/memory-flush.test.ts.pnpm tsgogreen.POST api.openai.com/v1/responseswithstore: true+context_management: [{type:"compaction", compact_threshold: 1000}]returned HTTP 200 with encryptedcompactionoutput items (2,380 encrypted bytes).OPENCLAW_LIVE_TEST=1 OPENCLAW_LIVE_OPENAI_COMPACTION=1 pnpm test:live src/agents/sessions/agent-session.openai-compaction.live.test.ts— passed; server compactions observed at turns 3 and 5 with prompt tokens dropping 56,854 → 38,346 after compaction.../codexsource:codex-rs/model-provider/src/provider.rs:30(V1/v1/responses/compact, V2compaction_trigger),codex-rs/core/src/tasks/compact.rs:41(provider capability gate),codex-rs/core/src/compact_remote_v2.rs:396(exactly-one compaction output contract).