Skip to content

fix(bots): keep model limits for codex bots and budget history - #185

Merged
nixuuu merged 1 commit into
devfrom
fix/bot-context-compaction
Nov 5, 2026
Merged

nixuuu merged 1 commit into
devfrom
fix/bot-context-compaction

Conversation

@nixuuu

@nixuuu nixuuu commented Nov 5, 2026

Copy link
Copy Markdown
Member

Codex bots now keep the model's real context limits, so long bot conversations compact instead of overflowing. Rebuilt bot sessions get a bounded history.

Cause. Codex bots were launched with the minimal catalog written for title generation, codexTextCatalog. Through model_catalog_json it replaced the model's metadata. codex debug models with that catalog reports context_window: null, auto_compact_token_limit: null, a 10 kB truncation policy and the base instructions "Generate only the requested text.". Without a window, Codex has no compaction threshold.

Codex bot catalog (apps/worker/src/bots/codex-catalog.ts)

  • The catalog is built from the model's real entry. The worker reads it with codex debug models, using the bot's executable, environment and CODEX_HOME.
  • It keeps the real window and truncation policy. It keeps the real auto-compact limit; if the entry has none, it sets 90% of the window.
  • It overrides only what adds tools: no shell, no patch, no experimental tools, direct tool mode, no multi-agent, no tool search, no node REPL, no model messages.
  • use_responses_lite is forced off, so tool schemas stay in tools and the isolation capture still sees every one of them.
  • Base instructions are neutral. The bot system prompt still applies.
  • Fallback when the model is not in the catalog: a 128k window and a 100k compaction limit.
  • Title generation is unchanged.

History budget (apps/gateway/src/bots/history-budget.ts)

  • A rebuilt session gets the newest messages that fit in 50% of a 128k window, estimated at 3 characters per token, and a marked note that says how many earlier messages were left out.
  • The current input is never dropped or shortened.
  • The gateway transcript stays complete. Routines and handoffs keep their limits.

Tests

  • tests/integration/bots-harness-context.test.ts (gateway↔worker, scripted Codex CLI):
    • the catalog carries the model's limits without tools;
    • a lost session with a large history rebuilds with the note, the newest messages and the full current input;
    • the transcript stays complete.
  • apps/worker/src/bots/codex-catalog.test.ts: the real codex accepts both the derived catalog and the fallback catalog.
  • isolation.test.ts passes unchanged with the real Claude, Codex and Grok CLIs.
  • check:tmp: 1204 passed, 154 skipped, 0 failed.

Not verified

  • No live run pushes a Codex bot past the compaction threshold.
  • The gateway uses a 128k window for every model, because the worker catalog does not report windows.
  • Claude and Grok bots compact through their harness defaults; that path was not exercised.

Docs: docs/bots-harness.md.

Copy audit: no UI text changed.

Fixes: #97

Codex bots replaced the model metadata with the title-generation
catalog, which has no context_window and no auto_compact_token_limit,
so Codex never auto-compacted long bot conversations. The bot catalog
now starts from the instance's real entry (`codex debug models`) and
overrides only the fields that add local tools, with a conservative
fallback window and compaction limit.

A rebuilt bot session sent the whole transcript as its first input.
The gateway now gives history about half of a default 128k window,
keeps the newest messages that fit with a marked omission note, and
always keeps the current input whole.
@nixuuu
nixuuu merged commit bdc9c36 into dev Nov 5, 2026
9 checks passed
@nixuuu
nixuuu deleted the fix/bot-context-compaction branch November 5, 2026 14:47
nixuuu added a commit that referenced this pull request Nov 18, 2026
The Slack PNG was stored correctly, but the bot catalog declared the
configured Codex model text-only. Codex removed the image block from the
tool result before inference. Keep an advertised image modality and
follow Codex's text-and-image default when modality metadata is absent.
Explicitly text-only models retain their declared limit. Bot tool
isolation remains in force.

## Verification

- The official Codex app-server test runs against a local Responses
endpoint and verifies both a user-uploaded image and an image fetched by
the bot's connector in the outgoing inference requests.
- Catalog and isolation tests passed locally. Worker typecheck and
scoped lint passed.
- Required CI covers the repository gate. The production Slack read will
be verified after the corrected Nightly is installed.

Fixes: #185
Related: #987
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