Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions MEMORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@

## 책임과 개발 범위

2026-11-28 구현·로컬 검증: [Provider 거절 이유 표시](docs/adr/0093-provider-rejection-display.md) (A안, 화면 전용).
4xx 본문을 최대 16 KiB 읽어 type/code/message를 정리해 headless `provider:`·대화형 `Provider said:`·model check에 보인다.
Key·Bearer·긴 token은 지우고 300자에서 자른다. Journal·planning context·model 요청은 그대로다(모델 요청 비교 8/8 일치).
가짜 key 실측: 설계 사례 2곳(DeepSeek·OpenAI)과 설계에 쓰지 않은 9곳에서 모두 이유가 보였다. 처음에는 Mistral(FastAPI `detail`)이 비었고,
OpenAI가 가려서 돌려준 key의 앞부분도 남아 있었다. 둘 다 고쳤다. Compatibility probe의 401/403은 `authentication_rejected`로 바뀌었다.
남은 것: agy 거절은 대상이 아니고, resume 뒤에는 이유가 다시 보이지 않는다. Journal에 남기는 B안은 필요할 때 따로 정한다.
책임: xgen CLI(provider 연결 계층·표시).

2026-11-28 배포 완료: [rc.9](https://github.com/PlateerLab/xgen-cli/releases/tag/v0.1.0-rc.9) 게시. 버전 PR #162(d5bea9c)는
rc.8 이후 #152~#161(agy Rust transport, `xgen tools enrich`와 사용량 저장, agy 자동 업데이트 차단, Run 중 후속 지시)을 담는다.
Main CI 7개, Release run 46141667086의 19개 job(설치 검증 10개 포함)이 재실행 없이 통과했다(약 42분).
Expand Down
184 changes: 171 additions & 13 deletions crates/xgen-cli/src/composition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::env;
use std::fmt;
use std::num::NonZeroU32;
use std::path::{Path, PathBuf};
use std::sync::{Arc, Mutex};
use std::time::Duration;

use serde::Serialize;
Expand Down Expand Up @@ -41,7 +42,7 @@ use xgen_policy::{
use xgen_provider_openai::{
BearerCredential, EvaluationProposalStepLimit, OpenAiCompatibilityCheckFailure,
OpenAiCompatibilityChecker, OpenAiJsonTask, OpenAiModelCheckFailure, OpenAiModelChecker,
OpenAiPlanner, OpenAiPlannerConfig, OpenAiPlannerConfigError,
OpenAiPlanner, OpenAiPlannerConfig, OpenAiPlannerConfigError, ProviderRejection,
};
use xgen_runtime::{
AgentLoop, AgentLoopQuiescence, AgentLoopTick, CapabilityRegistry, DirectExecutor,
Expand Down Expand Up @@ -378,6 +379,9 @@ pub enum LocalCommandResult {
Rejected {
run_id: String,
reason: RejectionReason,
/// The provider's own explanation when it refused the model call with a 4xx. Display
/// only: it is not journaled, so a later inspection of the Run cannot show it.
provider: Option<ProviderRejection>,
},
RecoveryRequired {
run_id: String,
Expand Down Expand Up @@ -415,10 +419,13 @@ pub fn check_openai_model(request: ModelCheckRequest) -> Result<(), ModelCheckEr
let config = OpenAiPlannerConfig::new(&base_url, DEFAULT_PLANNER_ID, &model, &tokenizer)
.and_then(|config| config.with_timeout(MODEL_CHECK_TIMEOUT))
.map_err(map_model_check_config)?;
OpenAiModelChecker::new(config, credential)
.map_err(map_model_check_config)?
.check()
.map_err(map_model_check_failure)
let mut checker =
OpenAiModelChecker::new(config, credential).map_err(map_model_check_config)?;
clear_model_check_rejection();
checker.check().map_err(|error| {
remember_model_check_rejection(checker.take_provider_rejection());
map_model_check_failure(error)
})
}

/// Return the bounded deterministic model catalog without creating Run state.
Expand Down Expand Up @@ -453,10 +460,13 @@ pub fn list_openai_models(request: ModelCheckRequest) -> Result<Vec<String>, Mod
let config = OpenAiPlannerConfig::new(&base_url, DEFAULT_PLANNER_ID, &model, &tokenizer)
.and_then(|config| config.with_timeout(MODEL_CHECK_TIMEOUT))
.map_err(map_model_check_config)?;
OpenAiModelChecker::new(config, credential)
.map_err(map_model_check_config)?
.models()
.map_err(map_model_check_failure)
let mut checker =
OpenAiModelChecker::new(config, credential).map_err(map_model_check_config)?;
clear_model_check_rejection();
checker.models().map_err(|error| {
remember_model_check_rejection(checker.take_provider_rejection());
map_model_check_failure(error)
})
}

/// Send one explicit, host-validated Chat Completions compatibility probe without Run state.
Expand Down Expand Up @@ -506,10 +516,48 @@ pub fn check_openai_compatibility(request: ModelCheckRequest) -> Result<(), Mode
inference_limits,
request_options,
)?;
OpenAiCompatibilityChecker::new(config, credential)
.map_err(map_model_check_config)?
.check()
.map_err(map_compatibility_check_failure)
let mut checker =
OpenAiCompatibilityChecker::new(config, credential).map_err(map_model_check_config)?;
clear_model_check_rejection();
checker.check().map_err(|error| {
let rejection = checker.take_provider_rejection();
// The probe's failure class cannot tell a refused key from a refused request.
let error = if rejection
.as_ref()
.is_some_and(ProviderRejection::is_authentication)
{
ModelCheckError::AuthenticationRejected
} else {
map_compatibility_check_failure(error)
};
remember_model_check_rejection(rejection);
error
})
}

/// The provider's explanation of the last failed model check in this process, for display.
///
/// Model checks return a stable `Copy` class; the bounded text travels beside it instead of
/// widening every caller's error type. A command runs one check sequence at a time.
static MODEL_CHECK_REJECTION: Mutex<Option<ProviderRejection>> = Mutex::new(None);

fn clear_model_check_rejection() {
remember_model_check_rejection(None);
}

fn remember_model_check_rejection(rejection: Option<ProviderRejection>) {
if let Ok(mut slot) = MODEL_CHECK_REJECTION.lock() {
*slot = rejection;
}
}

/// Take what the provider said when the last model check failed with a 4xx, if anything.
#[must_use]
pub fn take_model_check_rejection() -> Option<ProviderRejection> {
MODEL_CHECK_REJECTION
.lock()
.ok()
.and_then(|mut slot| slot.take())
}

/// Build a host JSON task client for the selected model profile, outside any Run.
Expand Down Expand Up @@ -1761,8 +1809,15 @@ fn continue_incomplete(
let command_process = process.map(ProcessTooling::with_fresh_terminal_sessions);
let process = command_process.as_ref();
let model_egress_allowed = planner.is_some();
let provider_rejection = Arc::new(Mutex::new(None));
let mut planner = if let Some(planner) = planner {
let usage_path = material_catalog_path.with_file_name("usage.sqlite3");
let slot = Arc::clone(&provider_rejection);
let planner = planner.with_rejection_observer(move |rejection| {
if let Ok(mut slot) = slot.lock() {
*slot = Some(rejection);
}
});
let planner = if let Ok(mut usage_store) = crate::usage::UsageStore::open(&usage_path) {
planner.with_usage_observer(move |observation| {
if usage_store.record(&observation).is_err() {
Expand Down Expand Up @@ -2033,9 +2088,56 @@ fn continue_incomplete(
return classify_durable_boundary_after_driver_error(store, manifest);
};
let result = map_driver_outcome(manifest.run_id(), outcome)?;
let result = with_provider_rejection(result, &provider_rejection);
Ok(with_blocking_failure_code(result, store))
}

/// Recovery hint matched to a provider refusal. The class alone cannot tell a bad key from an
/// unknown model, so this reads the HTTP status the provider answered with.
#[must_use]
pub const fn provider_rejection_hint(rejection: &ProviderRejection) -> &'static str {
match rejection.status() {
401 | 403 => {
"The provider refused the API key. Run xgen model setup --name PROFILE to enter a new key locally (xgen model list shows profile names); never paste keys into chat."
}
404 => {
"Check that the profile names an exact model ID the endpoint advertises: xgen model check --profile PROFILE."
}
429 => {
"Wait for the provider's rate limit or check quota and billing, then continue the Run."
}
_ => {
"Follow the provider's message above. If it names a parameter or format, check the profile's request options with xgen model setup --help, then run xgen model check --compatibility."
}
}
}

/// Attach what the provider said when a model call ended the Run with a provider-side refusal.
fn with_provider_rejection(
result: LocalCommandResult,
slot: &Arc<Mutex<Option<ProviderRejection>>>,
) -> LocalCommandResult {
let rejection = slot.lock().ok().and_then(|mut slot| slot.take());
match result {
LocalCommandResult::Rejected {
run_id,
reason:
reason @ RejectionReason::ModelRejected(
ModelCallRejectionReason::ProviderRejected
| ModelCallRejectionReason::RequestTooLarge
| ModelCallRejectionReason::RateLimited
| ModelCallRejectionReason::ProviderLimit,
),
provider: None,
} => LocalCommandResult::Rejected {
run_id,
reason,
provider: rejection,
},
other => other,
}
}

/// Attach the failure label of the Step that stopped the Run. Settled failures never stop a Run
/// (ADR-0052, ADR-0055), so the blocking Step is a failed Step that is not settled.
fn with_blocking_failure_code(
Expand All @@ -2045,6 +2147,7 @@ fn with_blocking_failure_code(
let LocalCommandResult::Rejected {
run_id,
reason: RejectionReason::FailedWork(None),
provider,
} = result
else {
return result;
Expand All @@ -2059,6 +2162,7 @@ fn with_blocking_failure_code(
LocalCommandResult::Rejected {
run_id,
reason: RejectionReason::FailedWork(code),
provider,
}
}

Expand Down Expand Up @@ -2632,6 +2736,7 @@ fn map_planner_unavailable(run_id: String, failure: PlannerPortFailure) -> Local
LocalCommandResult::Rejected {
run_id,
reason: RejectionReason::ModelRejected(reason),
provider: None,
}
}

Expand Down Expand Up @@ -2690,6 +2795,7 @@ fn map_driver_outcome(
AgentLoopQuiescence::FailedSteps => LocalCommandResult::Rejected {
run_id,
reason: RejectionReason::FailedWork(None),
provider: None,
},
AgentLoopQuiescence::ManualIntervention => LocalCommandResult::RecoveryRequired {
run_id,
Expand All @@ -2703,18 +2809,22 @@ fn map_driver_outcome(
DriverOutcome::ApprovalDenied { .. } => LocalCommandResult::Rejected {
run_id,
reason: RejectionReason::ApprovalDenied,
provider: None,
},
DriverOutcome::AdmissionNotAuthorized { .. } => LocalCommandResult::Rejected {
run_id,
reason: RejectionReason::AdmissionRejected,
provider: None,
},
DriverOutcome::ProposalRejected(rejection) => LocalCommandResult::Rejected {
run_id,
reason: RejectionReason::ProposalRejected(rejection),
provider: None,
},
DriverOutcome::MaterializerUnavailable(_) => LocalCommandResult::Rejected {
run_id,
reason: RejectionReason::MaterialRejected,
provider: None,
},
DriverOutcome::PlannerUnavailable(failure) => map_planner_unavailable(run_id, failure),
DriverOutcome::ModelCallRecoveryRequired { reason, .. } => {
Expand All @@ -2726,6 +2836,7 @@ fn map_driver_outcome(
DriverOutcome::ModelCallRejected(reason) => LocalCommandResult::Rejected {
run_id,
reason: RejectionReason::ModelRejected(reason),
provider: None,
},
DriverOutcome::ModelEgressRequired => LocalCommandResult::Paused {
run_id: Some(run_id),
Expand Down Expand Up @@ -3960,6 +4071,50 @@ mod tests {
assert_eq!(specs[1].0.metadata.id, graph_discovery::DESCRIBE);
}

#[test]
fn provider_explanation_attaches_only_to_provider_side_refusals() {
let refusal = || {
ProviderRejection::from_response(
401,
br#"{"error":{"message":"bad key","type":"authentication_error"}}"#,
None,
)
};
let rejected = |reason| LocalCommandResult::Rejected {
run_id: "run".to_owned(),
reason,
provider: None,
};
let slot = Arc::new(Mutex::new(Some(refusal())));
let result = with_provider_rejection(
rejected(RejectionReason::ModelRejected(
ModelCallRejectionReason::ProviderRejected,
)),
&slot,
);
assert_eq!(
result,
LocalCommandResult::Rejected {
run_id: "run".to_owned(),
reason: RejectionReason::ModelRejected(ModelCallRejectionReason::ProviderRejected),
provider: Some(refusal()),
}
);
assert!(slot.lock().unwrap().is_none());

// A schema failure is the model's answer, not a provider refusal; a stale note is dropped.
let slot = Arc::new(Mutex::new(Some(refusal())));
let invalid = rejected(RejectionReason::ModelRejected(
ModelCallRejectionReason::PlannerInvalidResponse,
));
assert_eq!(with_provider_rejection(invalid.clone(), &slot), invalid);
assert!(slot.lock().unwrap().is_none());
assert_eq!(
provider_rejection_hint(&refusal()),
"The provider refused the API key. Run xgen model setup --name PROFILE to enter a new key locally (xgen model list shows profile names); never paste keys into chat."
);
}

#[test]
fn http_profile_pins_override_references_and_keeps_default_binding() {
let root = tempdir().unwrap();
Expand Down Expand Up @@ -4291,6 +4446,7 @@ mod tests {
reason: RejectionReason::ModelRejected(
ModelCallRejectionReason::PlannerInvalidResponse
),
provider: None,
}
);
// Un-journaled planner port failures map onto the same durable class names.
Expand All @@ -4303,6 +4459,7 @@ mod tests {
LocalCommandResult::Rejected {
run_id: "run-model-rejection".to_owned(),
reason: RejectionReason::ModelRejected(ModelCallRejectionReason::ProviderRejected),
provider: None,
}
);
for (reason, code) in [
Expand Down Expand Up @@ -4346,6 +4503,7 @@ mod tests {
LocalCommandResult::Rejected {
run_id: "run-proposal-rejection".to_owned(),
reason: RejectionReason::ProposalRejected(ProposalRejection::InvocationInvalid),
provider: None,
}
);
assert_eq!(
Expand Down
1 change: 1 addition & 0 deletions crates/xgen-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pub use manifest::MAX_HOST_MODEL_TURNS;
pub use model_profile::*;
pub use run_layout::StateDirectoryPermissions;
pub use usage::{CostEstimate, TokenPrices, UsageReport, UsdPerMillion, inspect_local_usage};
pub use xgen_provider_openai::ProviderRejection;

#[doc(hidden)]
pub use environment::compatible_environment;
Expand Down
Loading