Skip to content

feat(rawr): add RAWR post-turn auto-compaction policy and config#29

Draft
mateicanavra wants to merge 11 commits into
codex/integration-upstream-mainfrom
codex/durable-rawr-auto-compaction-port
Draft

feat(rawr): add RAWR post-turn auto-compaction policy and config#29
mateicanavra wants to merge 11 commits into
codex/integration-upstream-mainfrom
codex/durable-rawr-auto-compaction-port

Conversation

@mateicanavra
Copy link
Copy Markdown

External (non-OpenAI) Pull Request Requirements

Before opening this Pull Request, please read the dedicated "Contributing" markdown file or your PR may be closed:
https://github.com/openai/codex/blob/main/docs/contributing.md

RAWR automatic post-turn compaction policy

Adds a new rawr_auto_compaction configuration option and the supporting runtime logic that automatically triggers context compaction after a turn completes when the model's context window is running low.

Feature flag

A new RawrAutoCompaction feature flag (rawr_auto_compaction, stage: UnderDevelopment, off by default) gates all RAWR compaction behavior. Setting rawr_auto_compaction = true in config.toml enables the feature, or a structured [rawr_auto_compaction] table can be used for fine-grained control.

Configuration schema (RawrAutoCompactionToml)

The new config type accepts either a plain boolean or a structured object with the following fields:

  • modetag, suggest, or auto (default auto). In tag/suggest mode a warning event is emitted instead of running compaction.
  • packet_authorwatcher (default) or agent. Controls who writes the post-compaction continuation context packet.
  • scratch_write_enabled – when true, the agent is asked to write a scratchpad file before compaction so research notes survive history rewrite.
  • compaction_model / compaction_reasoning_effort / compaction_verbosity – optional overrides for the compaction call.
  • policy – per-tier thresholds and boundary requirements across four tiers: early, ready, asap, and emergency.

Default percent-remaining thresholds are 85 / 75 / 65 / 15 for early / ready / asap / emergency respectively.

Boundary signals

Each policy tier specifies which RawrAutoCompactionBoundary signals must be observed before compaction fires: commit, plan_checkpoint, plan_update, pr_checkpoint, agent_done, topic_shift, concluding_thought, and turn_complete. Emergency tier always fires unconditionally. Plan boundaries can optionally require a semantic break (plan_boundaries_require_semantic_break) before they count.

Runtime (rawr_auto_compaction.rs / rawr_prompts.rs)

  • rawr_should_compact_at_turn_complete evaluates tier eligibility and boundary satisfaction.
  • rawr_build_watcher_post_compact_packet constructs a structured continuation context packet injected as the first user message of the next turn.
  • rawr_build_agent_continuation_packet_prompt combines scratch-write and packet prompts when packet_author = agent.
  • Prompt templates are read from <codex_home>/auto-compact/auto-compact.md and scratch-write.md, with built-in defaults written on first use.
  • Placeholder expansion ({scratchFile}, {threadId}, etc.) and YAML front-matter stripping are supported.
  • Scratch file paths are derived from the session source or a deterministic name hashed from the thread ID.

Session integration

on_task_finished now accepts a TaskKind parameter. For TaskKind::Regular turns, maybe_run_rawr_post_turn_auto_compaction is called after the turn completes. It computes percent-remaining from total token usage and the configured model_context_window, selects the appropriate inline compact task (local or remote), and queues the handoff message for the next turn. Active-turn cleanup is deferred until after RAWR compaction runs.

Tests

  • Integration test rawr_turn_complete_auto_compaction_emits_started_and_completed_items verifies that enabling the feature with a model_context_window set causes compaction started/completed items to be emitted after a turn that exceeds the threshold.
  • Unit tests cover tier selection, boundary matching, tail truncation, placeholder expansion, and prompt file creation.

Copy link
Copy Markdown
Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@mateicanavra mateicanavra force-pushed the codex/durable-rawr-auto-compaction-port branch 2 times, most recently from e2b0a81 to 466223e Compare April 23, 2026 09:28
@mateicanavra mateicanavra force-pushed the codex/integration-upstream-main branch 4 times, most recently from e1adf10 to 7c6edae Compare April 23, 2026 23:04
@mateicanavra mateicanavra force-pushed the codex/durable-rawr-auto-compaction-port branch from d1a85a9 to 2c13ccb Compare April 24, 2026 03:01
@mateicanavra mateicanavra force-pushed the codex/integration-upstream-main branch from 7c6edae to d891818 Compare April 24, 2026 03:50
@mateicanavra mateicanavra force-pushed the codex/durable-rawr-auto-compaction-port branch from 2c13ccb to e3a041a Compare April 24, 2026 04:53
@mateicanavra mateicanavra force-pushed the codex/integration-upstream-main branch from d891818 to ab69346 Compare April 24, 2026 05:32
@mateicanavra mateicanavra force-pushed the codex/durable-rawr-auto-compaction-port branch from e3a041a to 3ada214 Compare April 24, 2026 05:49
@mateicanavra mateicanavra force-pushed the codex/integration-upstream-main branch from ab69346 to 4a9f998 Compare April 24, 2026 06:28
@mateicanavra mateicanavra force-pushed the codex/durable-rawr-auto-compaction-port branch from 8ce0718 to d854193 Compare April 24, 2026 06:52
@mateicanavra mateicanavra force-pushed the codex/integration-upstream-main branch from 4a9f998 to f0fa7a9 Compare April 24, 2026 17:37
Add the RAWR auto-compaction feature/config surface on the current upstream config and feature crates, including schema regeneration for the new policy shape.

Run post-turn auto-compaction from the current session task lifecycle immediately after TurnComplete, detaching the finished task from active-turn routing before awaiting compaction while keeping its task handle alive until completion bookkeeping finishes.

Preserve the app-server-visible ContextCompaction flow through the existing compact implementations, prepend post-compact handoff context ahead of queued next-turn input, and document the current prompt/runtime semantics.

Add focused RAWR policy/prompt tests plus an app-server v2 parity test covering automatic turn-complete compaction ordering.
Clear Bazel remote downloader settings when BuildBuddy is disabled, and make npm native artifact staging resolve upstream release workflows from openai/codex by default.
Add an idempotent Desktop --ensure patch path for post-update adoption checks, document that hook, and keep Cargo lock package versions aligned with the 0.126.0-alpha.3 fork release.
Stabilize load-sensitive agent-control persistence waits that failed only under the full local gate.
@mateicanavra mateicanavra force-pushed the codex/durable-rawr-auto-compaction-port branch from d854193 to 3f77bef Compare April 24, 2026 20:54
Move PR checks off unavailable OpenAI/internal runner labels in the fork: Bazel macOS jobs now use standard hosted macOS labels, rust-ci argument-comment lint uses hosted Windows, and sdk uses hosted Ubuntu. Format the agent docs that the root CI Prettier gate already flagged.
Avoid false red macOS PR lanes in the fork when BuildBuddy credentials are unavailable. The macOS Bazel and argument-comment lint paths need the authenticated BuildBuddy downloader/cache for the hermetic Apple SDK; without it GitHub-hosted macOS receives a 403 from Apple's CLTools package URL before any Codex code builds.
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