Skip to content

fix: keep Codex compaction_trigger final when injecting the compress nudge - #283

Merged
ranxianglei merged 1 commit into
masterfrom
2026-08-27_compaction-trigger-finality
Aug 27, 2026
Merged

ranxianglei merged 1 commit into
masterfrom
2026-08-27_compaction-trigger-finality

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

refs #280

Background

Codex 0.147.0 performs native server-side compaction by sending a request whose input ends with a compaction_trigger item. The upstream requires that item to be the final input item — anything after it is rejected with:

400 {"error":{"message":"The 'compaction_trigger' item must be the final input item.",...}}

Bili's compress-nudge injection appends a user message at the end of the input. In any nudge-armed session (the issue's log shows INJECT T1 right before the 400), the nudge landed after the trigger, so Codex's own pre-sampling compact failed and the turn died with Error running remote compact task. This only appeared after v0.1.57 because nudge injection shipped in that release.

The 426 Upgrade Required on the WebSocket attempt is separate and by design — bili has no WS support and Codex fast-falls back to HTTP.

Changes

  • src/server.ts (prepareResponses): when the final input item is a compaction_trigger, skip the nudge for that request. The native compact IS the compression, so a client-side nudge is both contract-violating and redundant. The developer-message and tool injections (head of input) are unaffected; the kernel's wire layer already preserves the trigger's final position through projection/rebuild.

Tests

  • New Responses e2e (tests/compaction-trigger-finality.test.ts): nudge-armed session → request ending in compaction_trigger → forwarded input's last item is the trigger and no nudge text is present (200); control request with a normal trailing message still gets the nudge. Verified the test fails on master without the fix.

Full suite: 662/662 pass.

🤖 ework agent

…nudge

refs #280

Codex's native remote-compact request ends with a compaction_trigger
input item that the upstream requires to be the FINAL input item. The
compress nudge injection appended a user message after it, so any
nudge-armed session that hit a native compact got
400 "The 'compaction_trigger' item must be the final input item."
and the pre-sampling compact (and the turn) failed.

Skip the nudge when the final input item is a compaction_trigger —
the native compact IS the compression, and the developer-message /
tool injections (head of input) are unaffected.

Test: Responses e2e — trailing compaction_trigger stays final with no
nudge appended; control request keeps the nudge. Full suite 662/662.
@github-actions

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-08-27_compaction-trigger-finality (598fbdc)

Option A — Install from npm PR tag (recommended)

npm install -g billion-context@pr-283

Each push to this PR publishes a new version under the pr-283 npm tag.

Option B — Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pr283.tgz
npm install -g package

This comment is automatically updated on each push.

@ranxianglei
ranxianglei merged commit 2734fb4 into master Aug 27, 2026
6 checks passed
This was referenced Aug 27, 2026
ranxianglei pushed a commit to joshwapohlmann/billion-context that referenced this pull request Sep 17, 2026
…lei#870, PR ranxianglei#871)

Two CI regressions found while reviewing ranxianglei#871's red test jobs:

1. The degenerate-turn re-issue fired on the native-compaction trigger
   request (the resetAfterSuccess passthrough), appending the continuation
   nudge AFTER compaction_trigger and breaking the wire shape (ranxianglei#283: the
   trigger must stay the last input item). makeContinuationRefetch now
   refuses to re-issue a body whose final input item is a trigger.

2. The new gates retried turns the model left genuinely bare — zero output
   of any kind — double-billing an upstream empty completion. Both plugin
   pipes now require proof of invisible-but-real output (a stripped
   render-tag/marker echo, released markup, or thought/reasoning), matching
   the boundary the compress loop has kept since ranxianglei#732/ranxianglei#821.
ranxianglei pushed a commit that referenced this pull request Sep 27, 2026
…or-wins enforcement (#1421)

Owner-approved design (issue #1421, decision 2026-09-26): adopt carrier
merge (a) with per-wire split on role-alternation-strict wires.

Stamp shape per wire (insertCheckpointCarrier):
- anthropic: merge as an extra trailing text part of the last user message
  (string content normalizes to parts); standalone append only when the body
  does not end in a user message.
- google: merge into the last content's parts when it is not model-role
  (mandatory — mirrors appendGoogleNudge; the append form died inside bili's
  own pipeline because coreToGoogle fuses same-side runs).
- openai: standalone trailing user message (unchanged from step 2).
- responses: standalone trailing user message inserted before any trailing
  compaction_trigger (unchanged; #283 invariant preserved).
Restamping an already-stamped body replaces the trailing carrier instead of
stacking (idempotent re-stamp).

Recognition relaxation (extractChainCarriers), matching each wire's emitted
shape — still whole-part matching, ownership semantics unchanged:
- anthropic: whole-content OR a LAST part that entirely is the tag.
- google: ANY part that entirely is the tag (a later hop's nudge merge can
  push the tag off the end of parts).
- openai/responses: unchanged.
Strip is surgical: part-level removal for merged carriers, whole-slot for
standalone ones; emptied entries are dropped.

Enforcement (server.ts, first-processor-wins):
- valid / recent-mismatch / stale+digest-matched → forward verbatim,
  pipeline skipped (log [chain] info/warn).
- stale without digest match → strip the stale carrier(s), process normally
  (the request leaves re-stamped fresh by this instance).
- invalid → never trusted, process normally + warn.
- new ChainCheckpointContext.selectedMatched splits the stale verdict.
- kill switch: both enforcement and outbound stamping respect
  opts.chainContentDetection !== false (BILI_CHAIN_CONTENT=0).

Outbound stamping (forward()): every request that actually ran the kernel
(prepared with non-empty processedMessages, not side passthrough) leaves with
a <bili-chain> stamp computed over the exact bytes forwarded (placed after
compat roles + output steering so the digest covers them). Best-effort: a
stamp failure logs debug and forwards unstamped. requestId = first 8 hex of
the digest (deterministic, constant-size).

New stampOutbound() export; module header now carries the
identification-contract-freeze warning carried forward from #1397 plus the
#1421 per-wire shape decision. Legacy advisory text updated from 'until
signed chain proof lands' to 'until both sides ship the request checkpoint'.

Tests: new tests/chain-checkpoint-step3.test.ts (per-wire stamp shapes,
restamp idempotency, recognition relaxation, google must-fail regression via
real coreToGoogle fusion, round-trip invariant matrix, integration E1-E7
incl. kill switch and side-request no-stamp). Step-2 test file updated to
step-3 semantics (T1/T2 now assert byte-identical verbatim forward; google
two-part case is now a carrier under the any-part rule). Eight unrelated
test rigs pin exact wire shapes and opt out via chainContentDetection:false.
@ranxianglei
ranxianglei deleted the 2026-08-27_compaction-trigger-finality branch October 15, 2026 05:32
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.

1 participant