mirror of
https://github.com/instructkr/claude-code.git
synced 2026-05-27 16:06:44 +00:00
Merge pull request #3110 from Yeachan-Heo/fix/issue-693-analog-phase-error
Fix claw-analog bootstrap phase drift errors
This commit is contained in:
@@ -1109,25 +1109,33 @@ enum BlockKind {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const KNOWN_RAG_BOOTSTRAP_PHASES: &[&str] =
|
||||||
|
&["1-sqlite-no-db", "1-sqlite-empty", "1-sqlite", "2-qdrant"];
|
||||||
|
|
||||||
|
fn unknown_bootstrap_phase_error(received_value: Value, message: &str) -> String {
|
||||||
|
json!({
|
||||||
|
"kind": "unknown_bootstrap_phase",
|
||||||
|
"field": "phase",
|
||||||
|
"received_value": received_value,
|
||||||
|
"allowed_values": KNOWN_RAG_BOOTSTRAP_PHASES,
|
||||||
|
"message": message,
|
||||||
|
})
|
||||||
|
.to_string()
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn format_rag_query_json_for_model(body: &str) -> Result<String, String> {
|
pub(crate) fn format_rag_query_json_for_model(body: &str) -> Result<String, String> {
|
||||||
let v: Value = serde_json::from_str(body).map_err(|e| format!("invalid JSON: {e}"))?;
|
let v: Value = serde_json::from_str(body).map_err(|e| format!("invalid JSON: {e}"))?;
|
||||||
let phase = v.get("phase").and_then(|x| x.as_str()).ok_or_else(|| {
|
let phase = v.get("phase").and_then(|x| x.as_str()).ok_or_else(|| {
|
||||||
json!({
|
unknown_bootstrap_phase_error(
|
||||||
"kind": "unknown_bootstrap_phase",
|
v.get("phase").cloned().unwrap_or(Value::Null),
|
||||||
"field": "phase",
|
"RAG response is missing a string phase; refusing to silently render phase as unknown",
|
||||||
"received_value": v.get("phase").cloned().unwrap_or(Value::Null),
|
)
|
||||||
"message": "RAG response is missing a string phase; refusing to silently render phase as unknown"
|
|
||||||
})
|
|
||||||
.to_string()
|
|
||||||
})?;
|
})?;
|
||||||
if phase.trim().is_empty() || phase == "unknown" {
|
if !KNOWN_RAG_BOOTSTRAP_PHASES.contains(&phase) {
|
||||||
return Err(json!({
|
return Err(unknown_bootstrap_phase_error(
|
||||||
"kind": "unknown_bootstrap_phase",
|
Value::String(phase.to_string()),
|
||||||
"field": "phase",
|
"RAG response phase is not a recognized bootstrap phase",
|
||||||
"received_value": phase,
|
));
|
||||||
"message": "RAG response phase must be a concrete phase name"
|
|
||||||
})
|
|
||||||
.to_string());
|
|
||||||
}
|
}
|
||||||
let hits = v
|
let hits = v
|
||||||
.get("hits")
|
.get("hits")
|
||||||
@@ -2586,6 +2594,16 @@ mod tests {
|
|||||||
let err = format_rag_query_json_for_model(r#"{"hits":[],"phase":"unknown"}"#).unwrap_err();
|
let err = format_rag_query_json_for_model(r#"{"hits":[],"phase":"unknown"}"#).unwrap_err();
|
||||||
assert!(err.contains(r#""kind":"unknown_bootstrap_phase""#));
|
assert!(err.contains(r#""kind":"unknown_bootstrap_phase""#));
|
||||||
assert!(err.contains(r#""received_value":"unknown""#));
|
assert!(err.contains(r#""received_value":"unknown""#));
|
||||||
|
assert!(err.contains(r#""field":"phase""#));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn rag_response_unrecognized_phase_returns_typed_error() {
|
||||||
|
let err =
|
||||||
|
format_rag_query_json_for_model(r#"{"hits":[],"phase":"3-drifted"}"#).unwrap_err();
|
||||||
|
assert!(err.contains(r#""kind":"unknown_bootstrap_phase""#));
|
||||||
|
assert!(err.contains(r#""received_value":"3-drifted""#));
|
||||||
|
assert!(err.contains(r#""allowed_values""#));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
Reference in New Issue
Block a user