Skip to content

fix: prevent premature compaction on cold gateway resume - #1546

Merged
JAORMX merged 2 commits into
mainfrom
fix/1541-cold-gateway-compaction
Sep 15, 2026
Merged

JAORMX merged 2 commits into
mainfrom
fix/1541-cold-gateway-compaction

Conversation

@JAORMX

@JAORMX JAORMX commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #1541.

Prevent the first prompt after a gateway-session restart from compacting history against the provisional 128k context-window fallback while live model discovery is still pending.

  • Gate prompt runs, failed-step retries, and restored approval continuations on bounded context-window discovery before entering the engine.
  • Preserve known catalog/live windows and explicit overrides without waiting.
  • Return actionable context_window_unavailable (HTTP 503 / gRPC Unavailable) when discovery fails or returns an empty inventory without establishing the selected window; a later prompt retry can refresh and recover.
  • Publish context metadata and admission evidence in one atomic snapshot, closing the concurrent recovery race as well as the initial cold-start race.
  • Preserve established no-lister and successful non-empty passthrough behavior, session-lifetime leases, and required interrupted-history repair.
  • Update user documentation, error-code references, and a narrowly superseding ADR. No changes to the generic engine API.

Regression evidence

The committed integration test runs under the existing internal/app CI test suite; no live gateway/model credentials are required.

It uses two real app.Build instances, durable JSONL session recovery, offline TLS model discovery, and mock inference. With stacklok-gateway/gpt-5.6-sol (1,050,000 tokens) and ~150k tokens of history:

Case Before fix With fix
Warm / refresh-ready resume No compaction No compaction
First resumed prompt while discovery is held Compacts at 128k Waits, then uses 1,050,000 without compaction
Failed/empty discovery Could use speculative fallback Rejects before new prompt/inference; healthy retry succeeds

Additional tests cover atomic publication, caller cancellation, the operation-wide recovery deadline, known-window/override bypasses, effective plan-model identity, failed-step retry preservation, and awaiting approval preservation.

The integration test observes the real Build-wired admission callback and completes the same cold-admitted prompt after releasing metadata. A disposable Go-overlay mutation removing that callback makes the test fail.

Verification

Passed locally:

  • Focused regression under -race -count=3.
  • Full internal/app and internal/adapter/server package tests (race runs also performed during development).
  • task lint.
  • task docs.
  • task site:build.
  • go run ./cmd/mecademo.
  • git diff --check.

Full task test was green earlier in implementation. Subsequent full runs encountered resource/time limits and intermittent failures in unchanged tests. The latest run hit TestHeadlessCredentialStorage_Scenario1_HelperFailuresFailClosed; its isolated rerun on this branch passed, and isolated baseline repetitions passed. Root cause of that full-suite-only failure remains unconfirmed.

Final CI verification: head de5fe7bf845abfc42f3adce85dc722072a32a6a8 has 32 passing checks, 4 intentionally skipped, and no failures or pending checks. This includes all race partitions (the committed internal/app regression runs here), build, analysis, docs/site, SDK checks, module/API compatibility, performance gate, and kind e2e. The branch incorporates current main through a merge commit and is mergeable.

Review and workflow

Independent spec, standards, test-adequacy, architecture, security, reuse, and API/UX reviews were performed. Correctness blockers were repaired and re-reviewed. The existing generic TUI error presentation remains; the new server error and docs supply recovery instructions rather than adding a separate retry UI in this bug fix.

The directing user explicitly waived the acceptance-plan spine for #1541: “we should just do the fix and fix the docs instead.” This is the single test + fix + documentation PR. Human merge remains required.

Prevent provisional 128k fallback compaction while model discovery is pending. Add cold-restart integration, failure recovery, and admission publication regressions.

Co-Authored-By: OpenAI <[email protected]>

@jhrozek jhrozek left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Panel review complete across four axes (spec, standards, test-adequacy, domain: architecture/security/reuse/duplication). No blockers on any axis.

  • Spec: all three compaction-driving entry points gated; bounded-wait, override-preservation, and honest-unknown-model requirements verified and test-pinned.
  • Standards: composition-only wiring confirmed (engine/agent untouched), ADR 0342 well-formed and correctly indexed, generated SDK artifacts consistent.
  • Test adequacy: all 7 ACs covered; mutation-resistance to dropping the admission callback holds structurally.
  • Domain: no Critical/High findings. A handful of Low/advisory polish items (variadic-as-optional-param, a 3x repeated resolveWindowCore call, a small tolerated duplication) — none blocking.

Approving.

Preserve updated gateway documentation alongside context-window admission and retry guidance.

Co-Authored-By: OpenAI <[email protected]>
@JAORMX
JAORMX merged commit 28eb283 into main Sep 15, 2026
36 checks passed
@JAORMX
JAORMX deleted the fix/1541-cold-gateway-compaction branch September 15, 2026 11:10

This branch was successfully deployed

1 active deployment
Preview — de5fe7bf Deployed Sep 15, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: cold gateway metadata triggers premature compaction on resumed prompts

2 participants