fix(acp): use last_token_usage for codex context window fill#386
Merged
fix(acp): use last_token_usage for codex context window fill#386
Conversation
## Summary 🤖 Generated with [Nori](https://www.npmjs.com/package/nori-ai) - Replaces `agent-client-protocol` v0.9 connection layer (`AcpConnection` + dedicated worker thread) with `sacp` v10 `SacpConnection` that runs directly on the main tokio runtime, eliminating ~266 lines of complexity - Adds `WriteTextFileRequest` and `ReadTextFileRequest` handlers as chained `.on_receive_request()` calls with the same workspace security boundaries as the old `ClientDelegate` - Preserves process group isolation, parent death signal, environment stripping, and all existing behavioral contracts — 373 unit tests + 69/70 E2E tests pass (1 pre-existing failure in `test_startup_error_for_unregistered_model`) ### Architecture Changes - **No more worker thread**: SACP v10's `ClientToAgent` is `Send + Sync`, so all operations run on the main tokio runtime - **Builder-based handler registration**: Uses `ClientToAgent::builder().on_receive_request()` chains instead of a `Client` trait implementation - **Dynamic update routing**: `Arc<Mutex<Option<Sender<SessionUpdate>>>>` swaps between prompt-active and persistent channels - **Non-blocking drop**: `SacpConnection::drop()` aborts tasks and kills the process group without `spawn_blocking` ### Files - **New**: `sacp_connection.rs` (connection impl), `sacp_connection_tests.rs` (7 integration tests) - **Deleted**: `client_delegate.rs`, `public_api.rs`, `worker.rs`, `tests.rs` (old connection layer) - **Modified**: `backend/*.rs` (AcpConnection→SacpConnection), `translator.rs`, `lib.rs`, `Cargo.toml`, `docs.md` ## Test Plan - [x] 373 codex-acp unit tests pass - [x] 7 new SACP connection integration tests pass - [x] 69/70 E2E tests pass (1 pre-existing failure: `test_startup_error_for_unregistered_model`) - [x] Clippy clean, formatted - [x] Manual smoke test with a real ACP agent (claude-code or gemini) Share Nori with your team: https://www.npmjs.com/package/nori-skillsets Co-authored-by: Nori <contact@tilework.tech>
) ## Summary Generated with [Nori](https://www.npmjs.com/package/nori-ai) - Update Claude Code default context window size from 200K to 1M tokens to reflect Claude Opus 4.6's actual context window - Update doc comment in `AgentKind::context_window_size()` - Add regression test `test_claude_code_context_window_is_1m` ## Test Plan - [x] `cargo test -p codex-acp` — all 372 unit tests + 16 integration tests + 3 doc tests pass - [x] `cargo test -p nori-tui` — all 905 tests pass (no snapshot or percentage breakage) - [x] `just fix -p codex-acp` — clippy clean - [x] `just fmt` — formatting clean Share Nori with your team: https://www.npmjs.com/package/nori-skillsets
The codex transcript parser was using total_token_usage (cumulative billing counter) for context window percentage, producing nonsensical values like Context: 1M (388%) for a 258K window. Now extracts last_token_usage.input_tokens as last_context_tokens, which represents the actual context fill for the most recent API call.
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.
Summary
🤖 Generated with Nori
last_token_usage.input_tokensaslast_context_tokensfor accurate context window percentage displaytotal_token_usage(cumulative billing counter), which produced nonsensical values like "Context: 1M (388%)" for a 258K windowTest Plan
Share Nori with your team: https://www.npmjs.com/package/nori-skillsets