Repository navigation
fix: add second-chance developer->user compat learn (#583) - #585
Merged
ranxianglei merged 1 commit intoSep 7, 2026
Merged
Conversation
On the Responses path, a mid-list `developer` that a backend rejects can be rewritten to a mid-list `system` by the existing #552 auto-retry, which then 400s again on backends that only accept `system` at index 0 (#377 class). Add a bounded second-chance hop: when the primary developer→system retry fails with a system-placement error (new detectSystemPlacementError), do ONE more controlled retry rewriting the offending role to `user`; on success learn developer→user for the session (position-class learning wins over the generic one). Hard cap stays at original + 2 retries, fixed sequence (never a loop); anything still failing passes the original 400 through verbatim. Notes: - Chat path unaffected: systemToUser(coreToOpenai(...)) already normalizes mid-list system/developer to user before the wire, so the rewrite is a no-op. - Through the normal compression pipeline a rejected developer is HOISTED to index 0 (injectResponsesDeveloperMessage), so the primary retry already suffices; the second-chance covers the cases where a developer survives mid-list to the boundary (non-normalized items / unchanged-body fallbacks). Pre-flight: tsc --noEmit clean; npm run build OK; full suite green except a pre-existing environment-dependent launcher.test.ts case (fails identically on a clean tree when a real `codex` binary is on PATH). New unit test for detectSystemPlacementError plus e2e G (ladder + learn) and H (hard cap / verbatim). Existing #552 E/F regression tests still pass.
Contributor
📦 Built Package ArtifactBranch: Option A — Install from npm PR tag (recommended)npm install -g billion-context@pr-585Each push to this PR publishes a new version under the Option B — Download artifact
tar xzf billion-context-pr585.tgz
npm install -g packageThis comment is automatically updated on each push. |
This was referenced Sep 7, 2026
Merged
ranxianglei
deleted the
2026-09-06_compat-second-chance-developer-user
branch
October 15, 2026 05:32
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a bounded second-chance hop to the #552 learn-on-failure compat auto-fix, closing the edge described in #583.
On the Responses path, if a backend rejects an unknown role (
developer-> 400) and only acceptssystemat index 0 (#377-class placement), the existing single retry rewrites the offending role tosystem. When thatdevelopersits mid-list, the rewrittensystemis also mid-list -> the retry 400s again with a placement error (not a role-name error) -> the original 400 passes through verbatim and the auto-learn never engages.This change adds one more controlled retry for exactly that case:
detectSystemPlacementError(status, bodyText)insrc/compat-roles.ts— a conservative detector for system-placement 400s (Only one 'system' ... at the beginning,Multiple system messages,system ... at index N, ...). It requires a 400 plus the word "system" plus a strong placement/multiplicity marker, so quota / overflow / missing-system / auth 400s never trip it.src/server.tsthe single-retry block becomes a fixed ladder: primarydeveloper->system; if (and only if) that 400s with a placement error, one moredeveloper->user. On success the session learns the winning mapping (developer->userwins over the generic->system). Hard cap stays at original + 2 retries, never a loop; anything still failing passes the original 400 through verbatim.Scope notes (triage finding)
systemToUser(coreToOpenai(...))already normalizes mid-listsystem/developertouserbefore the wire, so the rewrite is a no-op there.developeris hoisted to index 0 by the kernel (injectResponsesDeveloperMessage), so the primary->systemretry already lands at index 0 and succeeds on placement-strict backends. Adeveloperreaches the boundary mid-list only when it is non-normalized (e.g. missingtype) or when the unchanged body is forwarded (transform-failure fallback). Both are covered by the new hop — so this is a defensive safety-net rather than a common-path fix, but it closes the class cleanly.Tests
detectSystemPlacementError(positive placement messages incl. quoted'system'; negative role/quota/overflow/auth; non-400 status).developer-> primarysystemplacement-400 -> second-chanceuser-> transparent 200; the next request on the same session pre-rewrites via the learned map (no round-trip). Asserts the exact 3-hit ladder + no idle-timer leak.role: "developer"messages — request a request-body compat transform hook #552 E/F regression tests still pass (primary hop unchanged; F's constantInvalid role:body does not match the placement detector, so it stays a single retry).Pre-flight
tsc --noEmitcleannpm run buildOK (self-containeddist/index.js)launcher.test.tscase (codex resolve to themselves) that fails identically on a clean tree whenever a realcodexbinary is present on PATH — unrelated to this change.tests/e2e/e2e-codex.test.ts, gated byACP_TEST_E2E=1) not run here (needs a live upstream); CI manual-dispatch covers it.