Add configurable Responses context projection - #42
maiphucgiang wants to merge 2 commits into
Conversation
Reviewer's GuideThis PR replaces fixed Responses context compaction with request-scoped balanced or passthrough projection, preserving protocol payload structure while selectively rewriting recognized harness blocks and safely clipping oversized generated content and JSON arguments. It adds configurable limits across CLI, environment, SQLite, WebUI, and Compose, exposes the selected mode in responses, records non-sensitive counters, validates malformed inputs, offloads projection work from the event loop, and updates regression coverage and documentation. Sequence diagram for configurable Responses projectionsequenceDiagram
participant Client
participant API as Responses API
participant Config as Request config snapshot
participant Projection as Responses projection
participant Upstream
participant Audit
Client->>API: POST /v1/responses
API->>Config: Freeze mode and max bytes
API->>Projection: project_responses_chat_body(body, mode, max_item_bytes)
alt mode is balanced
Projection->>Projection: parse_harness_text(text)
Projection->>Projection: truncate_middle_bytes(text, max_item_bytes)
Projection->>Projection: JSON-validate and clip tool arguments
else mode is passthrough
Projection-->>API: Preserve messages and tools
end
Projection-->>API: Projected body and counters
API->>Audit: observe_responses_projection(stats)
API->>Upstream: Forward converted Chat request
Upstream-->>API: Response stream or JSON
API-->>Client: Response with X-CodeBuddy-Responses-Projection
Flow diagram for Responses projection modes and limitsflowchart TD
A[Responses request] --> B[Freeze mode and max bytes per request]
B --> C{Projection mode}
C -->|passthrough| D[Keep Responses-derived payload unchanged]
C -->|balanced| E[Preserve schemas identity history and images]
E --> F[Rewrite recognized harness blocks]
E --> G[Clip oversized assistant text and tool results]
E --> H[Clip oversized JSON tool arguments]
G --> I[Keep UTF-8 head and tail with byte token and line metadata]
H --> J[Return strict valid JSON with head tail metadata]
D --> K[Protocol conversion and global limits]
I --> K
J --> K
K --> L[Forward upstream and expose selected mode]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
Hey - I've reviewed your changes and they look great!
Sourcery assessment
Needs a human reviewer. The default projection changes the context and tool arguments sent upstream, including truncating tool results and JSON values, so an incorrect transformation could cause an agent to make a wrong downstream decision or tool call before the change is reverted. Reverting restores the prior behavior, but it cannot undo actions or external effects that already occurred.
Changes
responses_projection_mode=balanced|passthrough(defaultbalanced), exposed through--responses-projection-mode,CODEBUDDY2API_RESPONSES_PROJECTION_MODE,.env, the WebUI and SQLite settings. Mode and limits are frozen per request, responses carryX-CodeBuddy-Responses-Projection, and audits record only non-sensitive counters. Client paths, models and payloads are unchanged.apply_patcharguments are no longer omitted wholesale, and arguments already withinresponses_projection_max_bytesare never truncated.responses_projection_max_bytes(default40000;0disables clipping, otherwise256..33554432) with the existing precedence, source locking and hot updates.passthroughdisables Responses-specific projection while keeping protocol conversion, image policy, the 64 MiB inbound / 32 MiB processed-request budgets and output collection limits.legacycompatibility mode remains. Reject non-stringfunction_call.argumentsand text that cannot be encoded as UTF-8 with 400, keep projected arguments valid strict JSON, and run projection off the event loop..env.example, concise English/Chinese advanced, client and deployment documentation, and the README FAQ. No dependency, database-schema or version changes (1.2.10).Verification
for script in tests/test_*.py; do python -B "$script"; done).vp checkreports 52 formatted files and no lint/type errors in 47 files, 133 unit tests pass,vp buildsucceeds, and Playwright passes 14 isolated plus 2 real-backend integration tests.compileall,check_version.py,docker compose configandgit diff --checkpass. Independent code reviews closed every reported P1/P2 finding.Summary by Sourcery
Add configurable, loss-conscious Responses context projection with balanced truncation or verbatim passthrough while preserving protocol compatibility.
New Features:
Bug Fixes:
Enhancements:
Deployment:
Documentation:
Tests:
Chores: