Repository navigation
fix: retry rejected previous-model compaction with selected model #30319
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
2bc5800
Retry retired model compaction with current model
celia-oai b65b5de
Clarify current-model compaction fallback
celia-oai 64fed66
Use invalid request for compaction fallback
celia-oai 5e2acb5
Fix remote compaction clippy failures
celia-oai 01c3ab5
Test legacy remote compaction model fallback
celia-oai 34aec86
Record compaction fallback model in traces
celia-oai d2b96df
Revert "Record compaction fallback model in traces"
celia-oai 8186426
Trace compaction fallback with selected model
celia-oai File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| use codex_analytics::CompactionImplementation; | ||
| use codex_analytics::CompactionReason; | ||
| use codex_otel::SessionTelemetry; | ||
| use codex_protocol::error::CodexErr; | ||
| use tracing::warn; | ||
|
|
||
| pub(crate) fn record_model_fallback( | ||
| session_telemetry: &SessionTelemetry, | ||
| previous_model: &str, | ||
| current_model: &str, | ||
| reason: CompactionReason, | ||
| implementation: CompactionImplementation, | ||
| fallback_error: Option<&CodexErr>, | ||
| ) { | ||
| let reason_tag = match reason { | ||
| CompactionReason::UserRequested => "user_requested", | ||
| CompactionReason::ContextLimit => "context_limit", | ||
| CompactionReason::ModelDownshift => "model_downshift", | ||
| CompactionReason::CompHashChanged => "comp_hash_changed", | ||
| }; | ||
| let implementation_tag = match implementation { | ||
| CompactionImplementation::Responses => "responses", | ||
| CompactionImplementation::ResponsesCompactionV2 => "responses_compaction_v2", | ||
| CompactionImplementation::ResponsesCompact => "responses_compact", | ||
| }; | ||
| let outcome = if fallback_error.is_none() { | ||
| "succeeded" | ||
| } else { | ||
| "failed" | ||
| }; | ||
| session_telemetry.counter( | ||
| "codex.compaction.model_fallback", | ||
| /*inc*/ 1, | ||
| &[ | ||
| ("reason", reason_tag), | ||
| ("implementation", implementation_tag), | ||
| ("outcome", outcome), | ||
| ], | ||
| ); | ||
| warn!( | ||
| previous_model, | ||
| current_model, | ||
| ?reason, | ||
| ?implementation, | ||
| outcome, | ||
| ?fallback_error, | ||
| "previous-model compaction failed; retried with current model" | ||
| ); | ||
| } |
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the previous-model attempt fails after local prompt trimming,
run_remote_compact_attempthas already mutatedanalytics_details.active_context_tokens_beforebased on a cloned history that never becomes the successful compaction input. Passing that same mutable details object into the selected-model retry means fallback scenarios with oversized function-call outputs can subtract the failed attempt's estimated deletions from the single tracked compaction event, and then subtract again (or keep a subtraction the fallback did not need), underreporting the pre-compaction token count; snapshot the details before the first attempt or only apply trimming deltas from the attempt that succeeds.Useful? React with 👍 / 👎.