Skip to content

fix(tui): make context pressure an agent directive - #5661

Closed
Hmbown wants to merge 1 commit into
mainfrom
grok/v0912-5620-agent-pressure-20260827
Closed

fix(tui): make context pressure an agent directive#5661
Hmbown wants to merge 1 commit into
mainfrom
grok/v0912-5620-agent-pressure-20260827

Conversation

@Hmbown

@Hmbown Hmbown commented Aug 27, 2026

Copy link
Copy Markdown
Owner

Summary

Second slice of #5620. Isabel's display-only sticky warning is already on main (#5629). The remaining failure was that the model-facing line still read like decorative turn metadata, so the agent kept working until the user asked whether the warning existed.

This PR:

  • names the standing reaction in BASE_PROMPT (frozen KV-cache prefix): when turn metadata includes a Context pressure warning or critical line, tell the user immediately, recommend /compact, and reduce scope;
  • makes the live turn_meta line an explicit ACTIONABLE: tell the user now directive;
  • keeps the line byte-stable within each pressure band (no percentages, token counts, or headroom), so ordinary turns do not bust the prefix cache.

Does not close #5620: structured context_pressure fields and prompt-injection economisation remain follow-up.

Credit: report and recovery notes from @ronohara; display slice already landed as #5629 by @wuisabel-gif.

Testing

  • cargo fmt on the touched files
  • git diff --check
  • scripts/dev-test.sh tui context_pressure_message_emits base_prompt_carries_constitutional_core — 2 passed

No provider credentials or network access.

Checklist

  • Updated docs or comments as needed
  • Added or updated tests where relevant
  • Verified TUI behavior manually if UI changes
  • Harvested/co-authored credit uses a GitHub numeric noreply address

Display-only sticky status landed in #5629. This slice makes the
model-facing signal actionable: the constitution names the standing
reaction, and the byte-stable turn_meta line tells the agent to surface
the warning immediately instead of treating it as decorative text.

Co-authored-by: ronohara <4027321+ronohara@users.noreply.github.com>
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@claude

claude Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Claude finished @Hmbown's task in 1m 12s —— View job


Review complete ✅

  • Gather context (PR description, changed files)
  • Read diff against origin/main
  • Review BASE_PROMPT / prompts.rs changes (KV-cache prefix impact)
  • Review engine.rs turn_meta directive change
  • Review tests
  • Post final review

Summary: Small, well-scoped change. It renames the reaction the model takes on context-pressure turn metadata from vague severity labels (ESCALATED/CRITICAL:) to an explicit ACTIONABLE: tell the user now directive, and adds a matching paragraph to BASE_PROMPT naming the standing reaction. No logic paths are touched — only the constant message strings in context_pressure_message (crates/tui/src/core/engine.rs:91-102) and the constitution text (crates/tui/src/prompts/text.rs:71-74).

Verified against repo invariants:

  • KV-cache prefix (docs/CACHE.md): BASE_PROMPT is part of the frozen header, edited intentionally at build time (a normal code change, not runtime drift) — correct. The live turn_meta line (engine.rs:3175-3189, context_pressure_line) is appended per-turn as volatile history, never spliced into the frozen prefix — matches the documented "history only grows" model.
  • Byte-stability claim: both WARNING and CRITICAL strings remain fixed constants per band (no %, token counts, or headroom), and the updated test at crates/tui/src/core/engine/tests.rs:16126-16144 now also asserts both new strings contain "tell the user now" and /compact. Good, cheap regression coverage for a high-risk (prefix-cache-busting) behavior.
  • No duplication with fix(tui): persist context pressure warnings #5629: grepped the sticky-UI-banner code (context_inspector.rs, compaction_flow.rs, ui.rs) — none of it shares this wording, so the model-facing directive and the display-only sticky warning stay cleanly separated as the PR claims.
  • Provider/model/route safety: not applicable — no route/provider/model selection logic touched.
  • Tests: crates/tui/src/prompts.rs:1610-1615 adds three BASE_PROMPT.contains(...) assertions that correctly match the new paragraph text (verified the substrings sit on single physical lines in the raw string, so .contains will match as written).

Minor, non-blocking nit: in .github/AUTHOR_MAP, the new ronohara line is inserted between reidliu41's two identity lines (username mapping and its alt-email mapping), splitting what was previously a grouped pair:

reidliu41 = reidliu41 <...>
+ronohara = ronohara <...>
reid201711@gmail.com = reidliu41 <...>

Confirmed via scripts/check-coauthor-trailers.py that this file is parsed as a flat key = value map — order has no functional effect, so this is purely cosmetic. Not worth a fixup commit unless you're already touching the file.

No correctness bugs, no dead code, no missing test coverage for the new behavior. This is ready to merge as-is.

@Hmbown

Hmbown commented Aug 29, 2026

Copy link
Copy Markdown
Owner Author

Closing as never-merge per the standing boundary in DIRECTION.md / TRUTH_LEDGER: this change touches prompt authority (context pressure as an agent directive), which is a rail-protected surface — the same reason issue #5620 deliberately remains open as roadmap rather than closing on this implementation. Branch preserved; reopen only by founder direction.

@Hmbown Hmbown closed this Aug 29, 2026
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.

Context pressure warning is transient and the agent does not proactively react to it

1 participant