aKode 0.2.0: protezione dai loop, errori del server chiari, pulizia
- Protezione dai loop: se il modello ripete lo stesso comando con lo stesso errore 3 volte di fila il turno si ferma con un messaggio chiaro (e un suggerimento su /permissions per i blocchi della sandbox); configurabile con [agent] max_repeated_failures (0 = disattivata). - Errori dello stream: si mostra il messaggio del server invece di "stream closed before response.completed"; il contesto superato (llama.cpp, vLLM) diventa un messaggio in italiano; avviso una volta se il prompt iniziale supera la finestra del modello. - Pulizia: tolta la logica morta per le chiavi OpenAI nel credential broker (prefisso "sk-", watermark, prefissi ignorati); link alla documentazione OpenAI nella TUI sostituiti con il README del repository; test dello snapshot del broker adattato al token GitHub. - Versione 0.2.0 e sezione Novità nel README. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -711,6 +711,22 @@ pub(crate) async fn run_turn(
|
||||
);
|
||||
}
|
||||
|
||||
if needs_follow_up
|
||||
&& let Some(message) = super::loop_guard::repeated_failure_message(
|
||||
sess.clone_history().await.raw_items(),
|
||||
turn_context.config.max_repeated_failures,
|
||||
)
|
||||
{
|
||||
let event = EventMsg::Error(ErrorEvent {
|
||||
misalignment: None,
|
||||
message,
|
||||
codex_error_info: Some(CodexErrorInfo::Other),
|
||||
rejected_audio_file_ids: Vec::new(),
|
||||
});
|
||||
sess.send_event(&turn_context, event).await;
|
||||
break;
|
||||
}
|
||||
|
||||
let candidate = if needs_follow_up {
|
||||
super::async_compaction::take_ready(&sess, &turn_context).await
|
||||
} else {
|
||||
@@ -1622,6 +1638,41 @@ pub(crate) fn build_prompt(
|
||||
}
|
||||
}
|
||||
|
||||
/// Warns once per session when the estimated prompt already exceeds the model window, so a
|
||||
/// later server error about the context size is not a surprise.
|
||||
async fn warn_if_prompt_exceeds_context_window(
|
||||
sess: &Session,
|
||||
turn_context: &TurnContext,
|
||||
history: &crate::context_manager::ContextManager,
|
||||
) {
|
||||
let Some(window) = turn_context.model_info().resolved_context_window() else {
|
||||
return;
|
||||
};
|
||||
let Some(estimated) = history.estimate_token_count(turn_context) else {
|
||||
return;
|
||||
};
|
||||
let Some(message) = prompt_over_context_message(estimated, window) else {
|
||||
return;
|
||||
};
|
||||
{
|
||||
let mut state = sess.state.lock().await;
|
||||
if state.prompt_over_context_warned {
|
||||
return;
|
||||
}
|
||||
state.prompt_over_context_warned = true;
|
||||
}
|
||||
sess.send_event(turn_context, EventMsg::Warning(WarningEvent { message }))
|
||||
.await;
|
||||
}
|
||||
|
||||
pub(crate) fn prompt_over_context_message(estimated: i64, window: i64) -> Option<String> {
|
||||
(window > 0 && estimated > window).then(|| {
|
||||
format!(
|
||||
"Il prompt iniziale (~{estimated} token) supera la finestra del modello ({window})."
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
#[allow(deprecated)]
|
||||
#[instrument(level = "trace",
|
||||
@@ -1685,6 +1736,9 @@ async fn run_sampling_request(
|
||||
sess.clone_history().await
|
||||
};
|
||||
let input_item_count = history.raw_items().len();
|
||||
if first_attempt {
|
||||
warn_if_prompt_exceeds_context_window(&sess, &turn_context, &history).await;
|
||||
}
|
||||
let sampling_step_context = Arc::new(StepContext {
|
||||
sampled_through_sequence: Some(history.input_sequence()),
|
||||
..step_context.as_ref().clone()
|
||||
|
||||
Reference in New Issue
Block a user