Repository navigation
chore: sync public mirror from internal #1368
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
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
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
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 |
|---|---|---|
|
|
@@ -42,6 +42,14 @@ | |
| }; | ||
| use crate::sanitize::{DeltaFilter, Sanitizer}; | ||
|
|
||
| /// One capacity recovery per run; restart remains bounded by the durable | ||
| /// step and usage budgets. No failed answer or tool call is replayed. | ||
| enum CapacityRecovery { | ||
| Available, | ||
| Pending(ModelError), | ||
| Attempted, | ||
| } | ||
|
|
||
| /// The engine-owned discovery tool. Always offered to the model. | ||
| pub const TOOLS_SEARCH: &str = "tools.search"; | ||
| /// The engine-owned bounded script tool. | ||
|
|
@@ -413,6 +421,7 @@ | |
| ) -> Result<Exit, Fenced> { | ||
| let started = Instant::now(); | ||
| let mut prefetch = Prefetch::new(); | ||
| let mut capacity_recovery = CapacityRecovery::Available; | ||
| loop { | ||
| self.read_control(ctx).await?; | ||
| match ctx.status() { | ||
|
|
@@ -465,13 +474,29 @@ | |
| return Ok(Exit::Failed); | ||
| } | ||
| let remaining_wall = self.budget.wall.saturating_sub(started.elapsed()); | ||
| let recovery_error = if matches!(capacity_recovery, CapacityRecovery::Pending(_)) { | ||
| match std::mem::replace(&mut capacity_recovery, CapacityRecovery::Attempted) { | ||
| CapacityRecovery::Pending(error) => Some(error), | ||
| _ => unreachable!(), | ||
| } | ||
| } else { | ||
| None | ||
| }; | ||
| let planning = async { | ||
| if recovery_error.is_some() { | ||
| self.compactor.recover(ctx).await | ||
| } else { | ||
| self.compactor.plan(ctx).await | ||
| } | ||
| }; | ||
| let plan = tokio::select! { | ||
| _ = cancel.cancelled() => return self.interrupt(ctx, &prefetch).await, | ||
| result = tokio::time::timeout(remaining_wall, self.compactor.plan(ctx)) => result, | ||
| result = tokio::time::timeout(remaining_wall, planning) => result, | ||
| }; | ||
| let mut compaction_declined = false; | ||
| if let Ok(plan) = plan { | ||
| compaction_declined = plan.declined; | ||
| compaction_declined = | ||
| plan.declined || (recovery_error.is_some() && plan.compaction.is_none()); | ||
| let mut events = Vec::new(); | ||
| if plan.usage != Default::default() { | ||
| events.push(Event::Usage(plan.usage)); | ||
|
|
@@ -511,15 +536,21 @@ | |
| vec![Event::Error { | ||
| class: Some(crate::ErrorClass::ContextCapacity), | ||
| code: ErrorCode::ModelFailed, | ||
| message: "Conversation context could not be reduced safely. History is preserved; start a new conversation with the relevant details if recovery keeps failing.".into(), | ||
| message: recovery_error.map_or_else( | ||
| || "Conversation context could not be reduced safely. History is preserved; start a new conversation with the relevant details if recovery keeps failing.".into(), | ||
| |error| error.message, | ||
| ), | ||
| }], | ||
| ) | ||
| .await?; | ||
| return Ok(Exit::Failed); | ||
| } | ||
| // A step never inherits another step's reads. | ||
| prefetch = Prefetch::new(); | ||
| if let Some(exit) = self.model_step(ctx, cancel, started, &mut prefetch).await? { | ||
| if let Some(exit) = self | ||
| .model_step(ctx, cancel, started, &mut prefetch, &mut capacity_recovery) | ||
| .await? | ||
| { | ||
| return Ok(exit); | ||
| } | ||
| } | ||
|
|
@@ -543,6 +574,7 @@ | |
| cancel: &'e CancellationToken, | ||
| started: Instant, | ||
| prefetch: &mut Prefetch<'e>, | ||
| capacity_recovery: &mut CapacityRecovery, | ||
| ) -> Result<Option<Exit>, Fenced> { | ||
| let step = ctx.step().saturating_add(1); | ||
| self.emit( | ||
|
|
@@ -844,6 +876,20 @@ | |
| } | ||
| let mut events = pending_usage; | ||
| events.push(Event::ModelAttemptAbandoned { step }); | ||
| if error.class() == crate::ErrorClass::ContextCapacity | ||
| && matches!(capacity_recovery, CapacityRecovery::Available) | ||
|
Check failure on line 880 in vendor/dex-loop/src/engine.rs
|
||
| && text.is_empty() | ||
| && calls.is_empty() | ||
| && reasoning.is_none() | ||
| && !cancel.is_cancelled() | ||
| { | ||
| // Close this attempt before planning a safe cut. The next | ||
| // loop checks control and budgets, persists a reducing summary, | ||
| // then rebuilds the complete request through normal admission. | ||
| self.emit(ctx, events).await?; | ||
| *capacity_recovery = CapacityRecovery::Pending(error); | ||
| return Ok(None); | ||
| } | ||
| events.push(Event::Error { | ||
| class: Some(error.class()), | ||
| code: ErrorCode::ModelFailed, | ||
|
|
||
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
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.
This recovery branch is unreachable for actual context-window failures from the production
AiRsModel:packages/ai-rs/src/openai.rsreports both HTTP and streamed context-overflow failures asProviderStreamErrorKind::ProviderDeclaredFailure, whilepackages/dex-host-rs/src/model.rsconverts that kind toErrorClass::Unknown. The newly extendedErrorClass::of_gateway_codehas no production callers (repo-wide search finds only its unit tests), so only the syntheticFakeModelscenarios supplyContextCapacity; real oversized requests still skip compaction and fail immediately. Propagate a typed context-capacity kind/code through the adapter before relying on this equality check.Useful? React with 👍 / 👎.