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

fix: keep Codex compaction_trigger final when injecting the compress nudge#283
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

📦 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.

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