requirements.authoring.adaptive
Requirements index · View definition
Requirement
Adaptive is experimental and requires explicit opt-in. For the OpenAI backend,
model = "adaptive"MUST select models locally rather than sendadaptiveto the API. An assessment with an applicable existing FIXME reference MUST go directly togpt-6.1-sol. Otherwise it MUST begin withgpt-5.4-mini: a true judgment is accepted, while false, FIXME, or a failed conversation/submission MUST trigger one fresh Sol assessment. Sol’s result MUST be final for that assessment, including a false judgment or failure. Provider errors, cancellation, mandatory-input failures, connection failures, and usage-storage failures MUST NOT trigger model escalation.Applicable FIXMEs MUST follow the subject’s existing scope rules: requirement references outside its own distributed sites, or the reviewed site’s own FIXMEs. Citation reviews have no applicable acknowledgments. Matching a literal word inside unrelated text MUST NOT trigger pre-escalation.
Both tiers MUST inherit the selected credentials, endpoint, and inference options. Explicit concrete model IDs MUST bypass adaptive routing. Each actual model attempt MUST have a separate usage record with its real model name; the adaptive record MUST link its attempts and record any routing reason. Escalation MUST NOT persist intermediate mini evidence or pass mini’s rationale to Sol. Under explicit
confirm, each independent assessment MUST use adaptive routing; disagreements MUST be verified by Sol using the existing confirmation selection rules. Adaptive routing MUST NOT perform sampled audits.
Rationale
The reviewed tests cover each obligation in requirements.authoring.adaptive. I found no gap that the criteria define.
Local selection and routing
tests/authoring_cli.rs#fn[adaptive_routes_fresh_assessments_and_records_each_model]configuresmodel = 'adaptive'against a mock OpenAI server. It asserts that every request body carries a concrete model (gpt-5.4-miniorgpt-6.1-sol), neveradaptive.- The same test covers the routing cases:
- A mini
truestays on mini and sends one request. - A mini
falseescalates to Sol. - A mini FIXME escalates to Sol.
- A malformed mini submission escalates to Sol.
- An applicable existing FIXME goes directly to Sol.
- A mini
- In the no-FIXME cases,
src/lib.rscontains the line “A plain FIXME is not an acknowledgment.” Mini is still attempted there, which covers “a literal word in unrelated text MUST NOT trigger pre-escalation”. fn[adaptive_unsubmitted_conversation_escalates_once_with_fresh_input]covers a conversation that never submits. Two empty mini responses are followed by one Sol request. It asserts that Sol’s input has length 1 and contains no “Reminder:”.
Applicable FIXME scope
src/authoring/inputs.rs#mod[tests]/fn[cited_built_ins_contribute_their_text_and_fixmes_in_own_sites_do_not]assertshas_applicable_fixmefor these cases:- A requirement reference outside its own sites is applicable.
- The reviewed site’s own FIXME is applicable.
- A clean site is not applicable.
- A FIXME inside the subject’s own sites does not count for the requirement-level assessment.
- Citation reviews are covered only by a weak check.
src/authoring/mod.rs#mod[tests]/fn[citation_reviews_use_their_prompt_and_record_the_item_and_citations]asserts!has_applicable_fixme, but its item contains no FIXME. The implementation sets the flag to a constantfalseinprepare_citation, which has no conditional. I treated this as covered and not as a gap.
Sol finality and no escalation
fn[adaptive_sol_failure_is_final_and_confirm_uses_sol_verification]covers a Solfalseafter minifalseand a Sol invalid submission after minifalse. Both end the run with exactly[mini, sol]requests and the evidence file unchanged.fn[adaptive_preflight_and_provider_errors_never_attempt_sol]covers credential, mandatory-input, usage-storage, provider and connection failures. It asserts that no Sol request is made, no Sol usage log exists, and the evidence is unchanged.fn[adaptive_cancellation_does_not_escalate_or_replace_evidence]covers cancellation. It asserts no further connection, no Sol log, and unchanged evidence.
Inheritance, bypass and records
- The routing test asserts, for every request on both tiers, the bearer authorization header,
reasoning.effort = mediumandmax_output_tokens = 8192. The endpoint is the mock server. tests/authoring_cli.rs#fn[openai_key_only_profile_defaults_to_sol_and_accepts_overrides]covers explicit concrete model IDs.gpt-6-lunais sent as-is, with one request, and the usage model is recorded asgpt-6-luna.- The routing test checks the usage records:
- Each model attempt has its own record with the real model name,
request_count1 and a distinctrun_id. - The parent
adaptiverecord links each attempt’s{id}.jsonpath. - The parent’s
routing_reasonequals the expected reason (mini_false,mini_fixme,mini_assessment_failed,existing_fixme, or none).
- Each model attempt has its own record with the real model name,
Escalation hygiene
- The routing test asserts that
MINI_ONLY_RATIONALE_SENTINELnever appears in any request body, so mini’s rationale is not passed to Sol. - It also asserts that the final evidence holds the Sol result, so no intermediate mini evidence persists.
Confirm
- The routing test’s confirm case expects
[mini, mini]on agreement and keeps the first rationale.fn[adaptive_sol_failure_is_final_and_confirm_uses_sol_verification]covers a disagreement. In it, mini returnstrueandfalse, thefalseescalates to Sol, and Sol then verifies. The expected sequence is[mini, mini, sol, sol], and the evidence rationale mentions “assessments disagreed”. It also covers minifalsefollowed by Solfalseunder bothonceandconfirm.
No sampled audits
- Every accepted mini
truerun asserts the exact request count and model list: one request under the default policy, two underconfirm. Any extra audit request would fail those assertions.
Inputs
Tests
Input 2: outline src/authoring/inputs.rs mod[tests]/fn[cited_built_ins_contribute_their_text_and_fixmes_in_own_sites_do_not]
- File:
src/authoring/inputs.rs - Selector:
mod[tests]/fn[cited_built_ins_contribute_their_text_and_fixmes_in_own_sites_do_not] - Kind:
fn src/authoring/inputs.rs:1626–1704
// {test}`requirements.references.authoring_inputs`
// {test}`requirements.references.builtin_definitions`
// {test}`requirements.references.site_review`
// {test}`requirements.authoring.adaptive`
// {test}`requirements.authoring.fixme_inputs`
#[test]
fn cited_built_ins_contribute_their_text_and_fixmes_in_own_sites_do_not() {
let project = crate::authoring::tests::citing_site_project();
let root = project.path();
let fixme = |issue: &str| {
format!(
" // :::{{fixme}} requirements.rule\n // :github: o/r#{issue}\n // Panics instead of reporting.\n // :::\n"
)
};
let source = crate::sites::tests::SOURCE
.replace(
"fn check_two() {}",
&format!("fn check_two() {{\n{}}}", fixme("1")),
)
.replace(
"fn other() { panic!(\"y\"); }",
&format!("fn other() {{\n{}}}", fixme("2")),
);
fs::write(root.join("src/lib.rs"), &source).unwrap();
let sources = AssessmentSources::prepare(root, "requirements.rule").unwrap();
assert!(sources.has_applicable_fixme);
let own_site = AssessmentSources::prepare_site(
root,
"requirements.rule",
"src/lib.rs",
"fn[check_two]",
)
.unwrap();
assert!(own_site.has_applicable_fixme);
let clean_site = AssessmentSources::prepare_site(
root,
"requirements.rule",
"src/lib.rs",
"fn[check_one]",
)
.unwrap();
assert!(!clean_site.has_applicable_fixme);
assert!(clean_site.model_acknowledgments().is_empty());
let only_site = source.replace(&fixme("2"), "");
fs::write(root.join("src/lib.rs"), only_site).unwrap();
assert!(
!AssessmentSources::prepare(root, "requirements.rule")
.unwrap()
.has_applicable_fixme
);
fs::write(root.join("src/lib.rs"), &source).unwrap();
let mandatory = sources.mandatory_inputs();
let items = mandatory
.iter()
.filter_map(|input| input["item"].as_str())
.collect::<Vec<_>>();
// Only the acknowledgment outside the subject's own sites belongs to
// this assessment, and it contributes no containing source.
assert!(items.is_empty(), "{mandatory:#?}");
let acknowledgments = sources.model_acknowledgments();
assert_eq!(acknowledgments.len(), 1, "{acknowledgments:#?}");
assert_eq!(acknowledgments[0]["item"], "fn[other]");
assert_eq!(acknowledgments[0]["issues"][0]["reference"], "o/r#2");
// A cited built-in contributes its fixed text once, and a cited
// declaration its own declaration.
assert_eq!(
mandatory
.iter()
.filter(|input| input["builtin"] == "habeas:util")
.collect::<Vec<_>>(),
[&builtin_input("habeas:util")]
);
assert!(
mandatory
.iter()
.any(|input| input["requirements"] == "requirements.other"),
"{mandatory:#?}"
);
}
Input 3: outline src/authoring/mod.rs mod[tests]/fn[citation_reviews_use_their_prompt_and_record_the_item_and_citations]
- File:
src/authoring/mod.rs - Selector:
mod[tests]/fn[citation_reviews_use_their_prompt_and_record_the_item_and_citations] - Kind:
fn src/authoring/mod.rs:4261–4416
// {test}`requirements.authoring.citation_prompt`
// {test}`requirements.references.citation_review`
// {test}`requirements.authoring.mandatory_inputs`
// {test}`requirements.authoring.habeas_background`
// {test}`requirements.authoring.judgment_rules`
// {test}`requirements.authoring.adaptive`
#[tokio::test]
async fn citation_reviews_use_their_prompt_and_record_the_item_and_citations() {
let project = inputs::tests::project();
let cite = "{cite}`requirements.ready`";
fs::write(
project.path().join("src/lib.rs"),
format!(
"// {cite}\n// :::{{cite}} habeas:util\n// Formats output for the caller.\n// :::\nfn helper() {{}}\n"
),
)
.unwrap();
let subject = AuthoringSubject::parse("citations:src/lib.rs#fn[helper]");
assert_eq!(
subject.evidence_path(project.path()),
project
.path()
.join("evidence/citations/src/lib.rs/fn[helper].json")
);
let mut sources = subject.sources(project.path()).unwrap();
assert!(!sources.has_applicable_fixme);
let mandatory = sources.mandatory_inputs().to_vec();
assert_eq!(mandatory[0]["file"], "src/lib.rs");
assert_eq!(mandatory[0]["item"], "fn[helper]");
assert_eq!(mandatory[1]["requirements"], "requirements.ready");
assert_eq!(mandatory[2]["builtin"], "habeas:util");
assert!(
mandatory[2]["text"][0]
.as_str()
.unwrap()
.starts_with("Cite this on an item that serves")
);
let state = tempfile::tempdir().unwrap();
let mut usage = UsageLog::start(state.path(), project.path(), &subject.label()).unwrap();
let provider = RecordingProvider::new(vec![judgment(json!(true), "Both are sensible.")]);
let (_, record) = assess(&provider, &mut sources, &mut usage).await.unwrap();
let prompts = provider.prompts();
let expected: Vec<_> = tool_definitions_with("submit_judgment", false)
.unwrap()
.into_iter()
.map(|tool| tool.name)
.collect();
assert_eq!(prompts[0].1, expected);
let duplicate = json!({"determination":true,"rationale":"Both are sensible."});
let duplicate_provider = ScriptedProvider {
turns: vec![vec![
("submit_judgment", duplicate.clone()),
("submit_judgment", duplicate),
]],
requests: RefCell::default(),
};
let mut duplicate_sources = subject.sources(project.path()).unwrap();
assert!(
assess(&duplicate_provider, &mut duplicate_sources, &mut usage)
.await
.unwrap_err()
.to_string()
.contains("exactly once")
);
let prompt = &prompts[0].0;
assert!(
prompt.contains("Review one source item's citations."),
"{prompt}"
);
assert!(
prompt.contains("Item under review: src/lib.rs fn[helper]"),
"{prompt}"
);
assert!(
prompt.contains("Formats output for the caller."),
"{prompt}"
);
// The initial request carries the complete mandatory set.
assert!(
prompt.contains(mandatory[0]["hash"].as_str().unwrap()),
"{prompt}"
);
assert!(prompt.contains("The project MUST be ready."), "{prompt}");
assert!(
prompt.contains("Cite this on an item that serves"),
"{prompt}"
);
// Prompts are recorded as serialized requests.
for background in [
approved_text("habeas_background", 0),
approved_text("habeas_background", 1),
approved_text("judgment_rules", 0),
] {
let background = serde_json::to_string(background).unwrap();
assert!(prompt.contains(background.trim_matches('"')), "{prompt}");
}
assert!(!prompt.contains("{{"), "{prompt}");
let citations = json!([
{"role": "cite", "name": "requirements.ready", "commentary": ""},
{"role": "cite", "name": "habeas:util", "commentary": "Formats output for the caller."}
]);
let request: Value = serde_json::from_str(prompt).unwrap();
// Compare the actual placeholder payload, rather than text which
// could also appear independently in the mandatory source inputs.
let user = request["chat_history"]
.as_array()
.unwrap()
.iter()
.find(|message| message["role"] == "user")
.unwrap();
let subject_text = user["content"][0]["text"].as_str().unwrap();
let payload = subject_text
.lines()
.find_map(|line| line.strip_prefix("Citations to check: "))
.unwrap();
assert_eq!(serde_json::from_str::<Value>(payload).unwrap(), citations);
assert_eq!(record["file"], "src/lib.rs");
assert_eq!(record["item"], "fn[helper]");
assert_eq!(record["citations"], citations);
assert_eq!(record["determination"], true);
let inputs = record["inputs"].as_array().unwrap();
assert!(inputs.iter().all(|input| input.get("builtin").is_none()));
assert_eq!(inputs.len(), 2, "{inputs:#?}");
// The recorded review satisfies validation for its item.
let path = subject.evidence_path(project.path());
fs::create_dir_all(path.parent().unwrap()).unwrap();
fs::write(&path, record.to_string()).unwrap();
let errors = crate::validate_repository(project.path()).unwrap().errors;
assert!(
!errors
.iter()
.any(|error| error.starts_with("evidence/citations/")),
"{errors:#?}"
);
// A name without a selector reviews the file's root node.
assert!(matches!(
AuthoringSubject::parse("citations:notes.txt"),
AuthoringSubject::Citation { file, item } if file == "notes.txt" && item.is_empty()
));
// The root node's selector is shown as `<root>` in the prompt.
fs::write(project.path().join("notes.txt"), format!("Notes. {cite}\n")).unwrap();
let sources = AuthoringSubject::parse("citations:notes.txt")
.sources(project.path())
.unwrap();
let prompt = initial_prompt(&sources).unwrap().joined();
assert!(
prompt.contains("Item under review: notes.txt <root>"),
"{prompt}"
);
assert!(!prompt.contains("{{"), "{prompt}");
}
Input 4: outline tests/authoring_cli.rs fn[openai_key_only_profile_defaults_to_sol_and_accepts_overrides]
- File:
tests/authoring_cli.rs - Selector:
fn[openai_key_only_profile_defaults_to_sol_and_accepts_overrides] - Kind:
fn tests/authoring_cli.rs:5286–5332
// {test}`requirements.authoring.openai_defaults`
// {test}`requirements.authoring.credentials`
// {test}`requirements.authoring.adaptive`
#[test]
fn openai_key_only_profile_defaults_to_sol_and_accepts_overrides() {
mock_server_waits_for_remaining_request_headers();
for (extra, model, effort, max_tokens) in [
("", "gpt-6.1-sol", "low", 16_384),
("model = 'gpt-6-luna'\n", "gpt-6-luna", "low", 16_384),
(
"model = 'gpt-6-luna'\n[authoring.configs.api.options]\nmax_output_tokens = 8192\n[authoring.configs.api.options.reasoning]\neffort = 'medium'\n",
"gpt-6-luna",
"medium",
8192,
),
] {
let submit = json!({"determination":false,"rationale":"Fixture assessment."});
let server = Server::start(vec![json!({
"id":"resp_submit", "object":"response", "status":"completed",
"model":model, "output":[{
"type":"function_call", "id":"fc_submit", "call_id":"submit",
"name":"submit_judgment", "arguments":submit.to_string(), "status":"completed"
}],
"usage":{"input_tokens":1,"output_tokens":1,"total_tokens":2}
})]);
let fixture = Fixture::new(&server.endpoint);
// Only the endpoint is fixture-specific; policy/concurrency/model are optional.
fs::write(fixture.config.join("habeas/config.toml"), format!(
"version = 1\n[authoring]\ndefault = 'api'\n[authoring.configs.api]\nbackend = 'openai'\napi_key = '{AUTH}'\nendpoint = '{}'\n{extra}", server.endpoint)).unwrap();
let output = fixture.run(&["author", SUBJECT]);
assert!(
output.status.success(),
"{}",
String::from_utf8_lossy(&output.stderr)
);
let requests = server.finish();
assert_eq!(requests.len(), 1);
assert_eq!(requests[0].body["model"], model);
assert_eq!(requests[0].body["reasoning"]["effort"], effort);
assert_eq!(requests[0].body["max_output_tokens"], max_tokens);
assert!(requests[0].headers.contains(&format!("Bearer {AUTH}")));
let usage = fixture.usage();
assert_eq!(usage["model"], model);
assert_eq!(usage["policy"], "once");
assert!(!usage.to_string().contains(AUTH));
}
}
Input 5: outline tests/authoring_cli.rs fn[adaptive_routes_fresh_assessments_and_records_each_model]
- File:
tests/authoring_cli.rs - Selector:
fn[adaptive_routes_fresh_assessments_and_records_each_model] - Kind:
fn tests/authoring_cli.rs:5361–5517
// {test}`requirements.authoring.adaptive`
// {test}`requirements.authoring.openai_defaults`
// {test}`requirements.authoring.policy`
#[test]
// {test}`requirements.authoring.usage_storage`
// {test}`requirements.authoring.confirmation`
fn adaptive_routes_fresh_assessments_and_records_each_model() {
let response = |arguments: Value| {
json!({
"id":"resp_submit", "object":"response", "status":"completed",
"model":"mock", "output":[{
"type":"function_call", "id":"fc_submit", "call_id":"submit",
"name":"submit_judgment", "arguments":arguments.to_string(), "status":"completed"
}], "usage":{"input_tokens":1,"output_tokens":1,"total_tokens":2}
})
};
for (existing_fixme, first, policy, expected_models, reason) in [
(
false,
json!({"determination":true,"rationale":"Good."}),
"",
vec!["gpt-5.4-mini"],
None,
),
(
false,
json!({"determination":false,"rationale":"MINI_ONLY_RATIONALE_SENTINEL"}),
"",
vec!["gpt-5.4-mini", "gpt-6.1-sol"],
Some("mini_false"),
),
(
false,
json!({"determination":{"FIXME":["Gap"]},"rationale":"MINI_ONLY_RATIONALE_SENTINEL"}),
"",
vec!["gpt-5.4-mini", "gpt-6.1-sol"],
Some("mini_fixme"),
),
(
false,
json!({"bad":"submission"}),
"",
vec!["gpt-5.4-mini", "gpt-6.1-sol"],
Some("mini_assessment_failed"),
),
(
true,
json!({"determination":true,"rationale":"Good."}),
"",
vec!["gpt-6.1-sol"],
Some("existing_fixme"),
),
(
false,
json!({"determination":true,"rationale":"FIRST_AGREEMENT_RATIONALE"}),
"policy = 'confirm'\n",
vec!["gpt-5.4-mini", "gpt-5.4-mini"],
None,
),
] {
let mut replies = vec![response(first)];
if expected_models.len() == 2 {
replies.push(response(json!({"determination":true,"rationale":"Good."})));
}
let server = Server::start(replies);
let fixture = Fixture::new(&server.endpoint);
if !existing_fixme {
fs::write(fixture.project.join("src/lib.rs"), "// {impl}`requirements.ready`\npub fn ready() {}\n// {test}`requirements.ready`\nfn ready_test() {}\n// A plain FIXME is not an acknowledgment.\n").unwrap();
}
fs::write(fixture.config.join("habeas/config.toml"), format!(
"version = 1\n[authoring]\ndefault = 'api'\n[authoring.configs.api]\nbackend = 'openai'\nmodel = 'adaptive'\n{policy}endpoint = '{}'\napi_key_env = 'HABEAS_TEST_MODEL_KEY'\n[authoring.configs.api.options]\nmax_output_tokens = 8192\nreasoning = {{ effort = 'medium' }}\n", server.endpoint)).unwrap();
let output = fixture.run(&["author", SUBJECT]);
assert!(
output.status.success(),
"{}",
String::from_utf8_lossy(&output.stderr)
);
let requests = server.finish();
assert_eq!(
requests
.iter()
.map(|r| r.body["model"].as_str().unwrap())
.collect::<Vec<_>>(),
expected_models
);
for request in &requests {
assert!(
request
.headers
.to_lowercase()
.contains(&format!("authorization: bearer {}", AUTH.to_lowercase()))
);
assert!(
!request
.body
.to_string()
.contains("MINI_ONLY_RATIONALE_SENTINEL")
);
assert_eq!(
request.body["input"].as_array().unwrap().len(),
1,
"fresh conversation"
);
assert_eq!(request.body["reasoning"]["effort"], "medium");
assert_eq!(request.body["max_output_tokens"], 8192);
}
let evidence: Value =
serde_json::from_slice(&fs::read(&fixture.evidence).unwrap()).unwrap();
assert_eq!(evidence["determination"], true);
if !policy.is_empty() {
assert_eq!(evidence["rationale"], "FIRST_AGREEMENT_RATIONALE");
}
let logs: Vec<Value> = fs::read_dir(fixture.state.join("habeas/authoring/usage"))
.unwrap()
.map(|entry| serde_json::from_slice(&fs::read(entry.unwrap().path()).unwrap()).unwrap())
.collect();
let expected_policy = if policy.is_empty() { "once" } else { "confirm" };
assert!(
logs.iter().all(|log| log["policy"] == expected_policy),
"{logs:?}"
);
let parent = logs
.iter()
.find(|log| log["subject"] == SUBJECT && log["model"] == "adaptive")
.unwrap();
assert_eq!(parent["routing_reason"].as_str(), reason);
assert!(!parent["attempts"].as_array().unwrap().is_empty());
let actual: Vec<_> = logs
.iter()
.filter(|log| log["model"] != "adaptive")
.collect();
assert_eq!(actual.len(), expected_models.len());
let ids: std::collections::BTreeSet<_> = actual
.iter()
.map(|log| log["run_id"].as_str().unwrap())
.collect();
assert_eq!(ids.len(), actual.len());
let links: Vec<_> = logs
.iter()
.flat_map(|log| log["attempts"].as_array().into_iter().flatten())
.filter_map(Value::as_str)
.collect();
for id in ids {
assert!(
links
.iter()
.any(|path| path.ends_with(&format!("{id}.json")))
);
}
for model in expected_models {
assert!(
logs.iter()
.any(|log| log["model"] == model && log["request_count"] == 1)
);
}
}
}
Input 6: outline tests/authoring_cli.rs fn[adaptive_sol_failure_is_final_and_confirm_uses_sol_verification]
- File:
tests/authoring_cli.rs - Selector:
fn[adaptive_sol_failure_is_final_and_confirm_uses_sol_verification] - Kind:
fn tests/authoring_cli.rs:5519–5639
// {test}`requirements.authoring.adaptive`
// {test}`requirements.authoring.persistence`
// {test}`requirements.authoring.policy`
#[test]
// {test}`requirements.authoring.confirmation`
fn adaptive_sol_failure_is_final_and_confirm_uses_sol_verification() {
let response = |name: &str, arguments: Value| {
json!({
"id":"resp", "object":"response", "status":"completed", "model":"mock",
"output":[{"type":"function_call", "id":"fc", "call_id":"call", "name":name,
"arguments":arguments.to_string(), "status":"completed"}],
"usage":{"input_tokens":1,"output_tokens":1,"total_tokens":2}
})
};
let assert_policy = |fixture: &Fixture, expected: &str| {
for path in fs::read_dir(fixture.state.join("habeas/authoring/usage")).unwrap() {
let log: Value =
serde_json::from_slice(&fs::read(path.unwrap().path()).unwrap()).unwrap();
assert_eq!(log["policy"], expected);
}
};
let good = response(
"submit_judgment",
json!({"determination":true,"rationale":"Good."}),
);
let bad = response(
"submit_judgment",
json!({"determination":false,"rationale":"Gap."}),
);
for confirm in [false, true] {
let replies = if confirm {
vec![
good.clone(),
bad.clone(),
bad.clone(),
response(
"submit_verification",
json!({
"real":false,"acknowledged":false,"acknowledgments":[],"rationale":"No real gap."}),
),
]
} else {
vec![
bad.clone(),
response("submit_judgment", json!({"invalid":true})),
]
};
let server = Server::start(replies);
let fixture = Fixture::new(&server.endpoint);
fs::write(fixture.project.join("src/lib.rs"), "// {impl}`requirements.ready`\npub fn ready() {}\n// {test}`requirements.ready`\nfn ready_test() {}\n").unwrap();
fs::write(fixture.config.join("habeas/config.toml"), format!(
"version = 1\n[authoring]\ndefault = 'api'\n[authoring.configs.api]\nbackend = 'openai'\nmodel = 'adaptive'\nendpoint = '{}'\napi_key_env = 'HABEAS_TEST_MODEL_KEY'\n", server.endpoint)).unwrap();
let output = if confirm {
fixture.run(&["author", SUBJECT, "--policy", "confirm"])
} else {
fixture.run(&["author", SUBJECT])
};
let requests = server.finish();
assert_policy(&fixture, if confirm { "confirm" } else { "once" });
let models: Vec<_> = requests
.iter()
.map(|r| r.body["model"].as_str().unwrap())
.collect();
if confirm {
assert!(
output.status.success(),
"{}",
String::from_utf8_lossy(&output.stderr)
);
assert_eq!(
models,
["gpt-5.4-mini", "gpt-5.4-mini", "gpt-6.1-sol", "gpt-6.1-sol"]
);
let evidence: Value =
serde_json::from_slice(&fs::read(&fixture.evidence).unwrap()).unwrap();
assert_eq!(evidence["determination"], true);
assert!(
evidence["rationale"]
.as_str()
.unwrap()
.contains("assessments disagreed")
);
} else {
assert!(!output.status.success());
assert_eq!(models, ["gpt-5.4-mini", "gpt-6.1-sol"]);
assert_eq!(
fs::read_to_string(&fixture.evidence).unwrap(),
fixture.original
);
}
}
for policy in ["once", "confirm"] {
let server = Server::start(vec![
response(
"submit_judgment",
json!({"determination":false,"rationale":"Mini found a gap."}),
),
response(
"submit_judgment",
json!({"determination":false,"rationale":"Sol confirms the gap."}),
),
]);
let fixture = Fixture::new(&server.endpoint);
configure_adaptive_fixture(&fixture, &server.endpoint);
let output = fixture.run(&["author", SUBJECT, "--policy", policy]);
assert!(output.status.success(), "{output:?}");
assert_policy(&fixture, policy);
let requests = server.finish();
assert_eq!(
requests
.iter()
.map(|request| request.body["model"].as_str().unwrap())
.collect::<Vec<_>>(),
["gpt-5.4-mini", "gpt-6.1-sol"]
);
let evidence: Value =
serde_json::from_slice(&fs::read(&fixture.evidence).unwrap()).unwrap();
assert_eq!(evidence["determination"], false);
assert_eq!(evidence["rationale"], "Sol confirms the gap.");
}
}
Input 7: outline tests/authoring_cli.rs fn[adaptive_preflight_and_provider_errors_never_attempt_sol]
- File:
tests/authoring_cli.rs - Selector:
fn[adaptive_preflight_and_provider_errors_never_attempt_sol] - Kind:
fn tests/authoring_cli.rs:5648–5713
// {test}`requirements.authoring.adaptive`
#[test]
fn adaptive_preflight_and_provider_errors_never_attempt_sol() {
for failure in [
"credential",
"mandatory",
"storage",
"provider",
"connection",
] {
let server = (failure == "provider").then(|| Server::start(vec![json!({
"__http_status":401,"error":{"message":"fixture rejected credential","type":"invalid_request_error","code":"invalid_api_key"}
})]));
let listener = TcpListener::bind(("127.0.0.1", 0)).unwrap();
listener.set_nonblocking(true).unwrap();
let endpoint = server
.as_ref()
.map(|s| s.endpoint.clone())
.unwrap_or_else(|| format!("http://{}", listener.local_addr().unwrap()));
let listener = if failure == "connection" {
drop(listener);
None
} else {
Some(listener)
};
let fixture = Fixture::new(&endpoint);
configure_adaptive_fixture(&fixture, &endpoint);
if failure == "mandatory" {
fs::write(
fixture.project.join("habeas.toml"),
"version = 1\n[evidence]\ndisallow = ['md/requirements.md']\n",
)
.unwrap();
}
if failure == "storage" {
fs::write(&fixture.state, "not a directory").unwrap();
}
let mut command = fixture.command();
if failure == "credential" {
command.env_remove("HABEAS_TEST_MODEL_KEY");
}
let output = command.args(["author", SUBJECT]).output().unwrap();
assert!(!output.status.success(), "{failure}");
assert_eq!(
fs::read_to_string(&fixture.evidence).unwrap(),
fixture.original
);
if let Some(server) = server {
let requests = server.finish();
assert_eq!(requests.len(), 1);
assert_eq!(requests[0].body["model"], "gpt-5.4-mini");
assert!(
String::from_utf8_lossy(&output.stderr).contains("fixture rejected credential")
);
} else if let Some(listener) = listener {
assert!(matches!(listener.accept(),Err(e) if e.kind()==std::io::ErrorKind::WouldBlock));
}
if let Ok(paths) = fs::read_dir(fixture.state.join("habeas/authoring/usage")) {
for path in paths {
let log: Value =
serde_json::from_slice(&fs::read(path.unwrap().path()).unwrap()).unwrap();
assert_ne!(log["model"], "gpt-6.1-sol", "{failure}: {log}");
}
}
}
}
Input 8: outline tests/authoring_cli.rs fn[adaptive_cancellation_does_not_escalate_or_replace_evidence]
- File:
tests/authoring_cli.rs - Selector:
fn[adaptive_cancellation_does_not_escalate_or_replace_evidence] - Kind:
fn tests/authoring_cli.rs:5715–5758
// {test}`requirements.authoring.adaptive`
#[cfg(unix)]
#[test]
fn adaptive_cancellation_does_not_escalate_or_replace_evidence() {
let listener = TcpListener::bind(("127.0.0.1", 0)).unwrap();
listener.set_nonblocking(true).unwrap();
let endpoint = format!("http://{}", listener.local_addr().unwrap());
let fixture = Fixture::new(&endpoint);
configure_adaptive_fixture(&fixture, &endpoint);
let child = fixture
.command()
.args(["author", SUBJECT])
.stdout(std::process::Stdio::piped())
.stderr(std::process::Stdio::piped())
.spawn()
.unwrap();
let deadline = Instant::now() + Duration::from_secs(10);
let _connection = loop {
if let Ok((stream, _)) = listener.accept() {
break stream;
}
assert!(Instant::now() < deadline, "no initial mini request");
thread::sleep(Duration::from_millis(5));
};
assert!(
Command::new("kill")
.args(["-INT", &child.id().to_string()])
.status()
.unwrap()
.success()
);
let output = child.wait_with_output().unwrap();
assert!(!output.status.success());
assert!(String::from_utf8_lossy(&output.stderr).contains("cancel"));
assert_eq!(
fs::read_to_string(&fixture.evidence).unwrap(),
fixture.original
);
assert!(matches!(listener.accept(),Err(e) if e.kind()==std::io::ErrorKind::WouldBlock));
for entry in fs::read_dir(fixture.state.join("habeas/authoring/usage")).unwrap() {
let log: Value = serde_json::from_slice(&fs::read(entry.unwrap().path()).unwrap()).unwrap();
assert_ne!(log["model"], "gpt-6.1-sol");
}
}
Input 9: outline tests/authoring_cli.rs fn[adaptive_unsubmitted_conversation_escalates_once_with_fresh_input]
- File:
tests/authoring_cli.rs - Selector:
fn[adaptive_unsubmitted_conversation_escalates_once_with_fresh_input] - Kind:
fn tests/authoring_cli.rs:5760–5784
// {test}`requirements.authoring.adaptive`
#[test]
fn adaptive_unsubmitted_conversation_escalates_once_with_fresh_input() {
let empty = json!({"id":"resp","object":"response","status":"completed","model":"mock","output":[],"usage":{"input_tokens":1,"output_tokens":1,"total_tokens":2}});
let good = json!({"id":"resp","object":"response","status":"completed","model":"mock","output":[{"type":"function_call","id":"fc","call_id":"call","name":"submit_judgment","arguments":json!({"determination":true,"rationale":"Good."}).to_string(),"status":"completed"}],"usage":{"input_tokens":1,"output_tokens":1,"total_tokens":2}});
let server = Server::start(vec![empty.clone(), empty, good]);
let fixture = Fixture::new(&server.endpoint);
configure_adaptive_fixture(&fixture, &server.endpoint);
let output = fixture.run(&["author", SUBJECT]);
assert!(
output.status.success(),
"{}",
String::from_utf8_lossy(&output.stderr)
);
let requests = server.finish();
assert_eq!(
requests
.iter()
.map(|r| r.body["model"].as_str().unwrap())
.collect::<Vec<_>>(),
["gpt-5.4-mini", "gpt-5.4-mini", "gpt-6.1-sol"]
);
assert_eq!(requests[2].body["input"].as_array().unwrap().len(), 1);
assert!(!requests[2].body.to_string().contains("Reminder:"));
}
Other sources
Input 1: requirements selection requirements.authoring.adaptive
requirements.authoring.adaptive:md/requirements/authoring.md:1705–1729
:::{req} adaptive
Adaptive is experimental and requires explicit opt-in. For the OpenAI backend,
`model = "adaptive"` MUST select models locally rather
than send `adaptive` to the API. An assessment with an applicable existing
FIXME reference MUST go directly to `gpt-6.1-sol`. Otherwise it MUST begin with
`gpt-5.4-mini`: a true judgment is accepted, while false, FIXME, or a failed
conversation/submission MUST trigger one fresh Sol assessment. Sol's result
MUST be final for that assessment, including a false judgment or failure.
Provider errors, cancellation, mandatory-input failures, connection failures,
and usage-storage failures MUST NOT trigger model escalation.
Applicable FIXMEs MUST follow the subject's existing scope rules: requirement
references outside its own distributed sites, or the reviewed site's own FIXMEs.
Citation reviews have no applicable acknowledgments. Matching a literal word
inside unrelated text MUST NOT trigger pre-escalation.
Both tiers MUST inherit the selected credentials, endpoint, and inference
options. Explicit concrete model IDs MUST bypass adaptive routing. Each actual
model attempt MUST have a separate usage record with its real model name;
the adaptive record MUST link its attempts and record any routing reason.
Escalation MUST NOT persist intermediate mini evidence or pass mini's rationale
to Sol. Under explicit `confirm`, each independent assessment MUST use adaptive
routing; disagreements MUST be verified by Sol using the existing confirmation
selection rules. Adaptive routing MUST NOT perform sampled audits.
:::