Draft
Conversation
vjvarada
added a commit
that referenced
this pull request
Jul 2, 2026
Ships server-side context assembly (module map review #3). C2 grade B- -> A-. The gap: per-turn INPUT context was assembled client-side and trusted verbatim by the gateway. The executor then re-sliced the client-sent messages[] in SIX places with different COUNT caps (12/16/20/50) + char-truncation, all token-blind; the code itself documented the streaming/batch duplication. And a non-chat caller (API/webhook) with a thread_id but no messages[] got NO history because nothing rebuilt it server-side. The token-accounting utilities in acb_llm/context.py existed but were email-only. Fix: one acb_llm.assemble_run_context(system_context, history, current_message, model, history_loader, max_turns): - DB-rebuild-when-empty via an injected history_loader (so acb_llm keeps no gateway dependency) -> non-chat callers get the SAME context a browser would. - Server-side current-turn dedup (the withoutCurrentTurn equivalent). - Two-stage token-budget fit: drop oldest WHOLE history turns until it fits the model window, THEN char-trim the longest survivor. The existing single-message trimmer alone couldn't converge on many-medium-turn chat transcripts (only the email single-huge-body shape). Wired into BOTH executor structured-message sites (_compose_maf_run_input streaming + the Tier-2 batch path) using _active_run_model for the budget, so streaming and batch feed the model identically. agent.py injects a _get_messages-backed loader into the payload for thread_id-carrying callers with no client history. Backward-compatible: browser clients still send messages[], so the loader is a no-op then; the client keeps assembling for the UI context-ring (additive, no longer trusted for correctness). The email path keeps its own string-flatten assembler (app-scoped, out of core C2). Tests: tests/unit/test_context_assembly.py (12), evals/trajectories/test_context_assembly_trajectory.py (4, CI-blocking). Full suite 646 green, zero regressions. Next core module: B6 sandboxing (grade C, top safety lever). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Thanks for asking me to work on this. I will get started on it and keep this PR's description up to date as I form a plan and make progress.