requirements.authoring.concurrency
Requirements index · View definition
Requirement
Each named authoring configuration MUST accept an optional positive integer
concurrencyin its configuration table. When omitted, the maximum number of simultaneous assessments MUST default to the number of available logical CPUs for Bedrock and OpenAI, falling back to one when that count is unavailable, and to one for Ollama. A configured value MUST override the default for each backend; zero MUST be rejected as invalid configuration.Batch authoring MUST use asynchronous tasks on a runtime with a fixed worker thread pool. The number of assessments running at once MUST NOT exceed the selected concurrency. Each assessment MUST retain its own model conversation and usage record. Transient provider failures, including throttling, MUST be retried within the affected assessment under
; every other provider error MUST be reported through the ordinary assessment-failure path.
Rationale
The tests cover each testable obligation of requirements.authoring.concurrency. I judged against the requirement text only.
Configuration (tests/configuration.rs)
- Optional positive
concurrencyper named configuration, and the defaults:authoring_concurrency_defaults_overrides_and_invalid_valuesloops over bedrock, ollama and openai.- Without a value,
resolved.concurrencyisNone, andeffective_concurrency()equals available parallelism (falling back to 1) for bedrock and openai, and 1 for ollama. - With
concurrency = 7, the value overrides the default for every backend, and the config round-trips through TOML. - The invalid values
0,-1,1.5and'2'are each rejected with an error that namesconcurrencyand the config path. Zero rejection is covered.
- Without a value,
workspace_configurations_accept_validate_and_override_concurrencyrepeats the checks for workspace configs. It covers override, omitted value, each backend, and the same invalid values, both throughWorkspaceConfig::parseand throughload_workspace_config.- The expected default in these tests is computed with the same formula the code uses. The CPU-unavailable fallback to 1 cannot be forced from a test. This is an acceptable limitation.
Batch behaviour (tests/authoring_batch.rs)
- Maximum simultaneous assessments.
batch_fills_evidence_preserves_current_records_and_reauthors_only_changed_inputsruns with concurrency 2. It assertspeak == 2and that a second assessment started before the first model response, so the limit is both reached and not exceeded.ollama_batches_are_serial_by_defaultassertspeak == 1with no configured value, which exercises the Ollama default in a real batch.interrupted_terminal_progress_keeps_unstarted_work_incompleteruns both concurrency 2 and concurrency 1.a_denied_mandatory_input_aborts_only_its_assessmentruns with concurrency 1.
- Own conversation and usage record.
concurrent_assessments_keep_their_own_continuing_historiesruns at concurrency 4. For each subject it asserts that the second request extends the first request’s messages exactly and adds only that subject’s own tool call and tool result.- The usage-record counts and per-subject
request_countassertions in the throttle test and in the first batch test cover the usage record.
- Transient failure retried within the affected assessment.
throttled_assessment_retries_within_itself_while_others_proceedthrottles one subject once. It asserts:- 7 requests in total, with 2 for alpha;
peak <= 2;- alpha’s usage record shows
request_count2, with a failed request followed by a completed one; - every other assessment has
request_count1; - all 6 usage records are
completed, and alpha’s evidence is written. - The details of the backoff are delegated to
requirements.authoring.provider_backoff, which is cited here, not reassessed.
- Other provider errors take the ordinary failure path.
failed_assessment_keeps_other_results_and_reports_failurefails one subject. It asserts a non-success exit, no evidence for that subject, evidence for the others, onefailedand fivecompletedusage records, and a diagnostic containing the subject name and the provider message.
Runtime obligation. “Asynchronous tasks on a runtime with a fixed worker thread pool” is satisfied in src/main.rs#fn[main] by passing through tokio::runtime::Runtime::new(). That code has no conditional or transformation of its own. The concurrency bound it feeds is asserted through the peak-in-flight checks above.
I found no unacknowledged gaps.
Inputs
Tests
Input 3: outline tests/authoring_batch.rs impl[Server/Drop]/fn[drop]
- File:
tests/authoring_batch.rs - Selector:
impl[Server/Drop]/fn[drop] - Kind:
fn tests/authoring_batch.rs:118–122
// {test}`requirements.authoring.concurrency`
fn drop(&mut self) {
self.stop.store(true, Ordering::Relaxed);
self.thread.take().unwrap().join().unwrap();
}
Input 4: outline tests/authoring_batch.rs fn[batch_fills_evidence_preserves_current_records_and_reauthors_only_changed_inputs]
- File:
tests/authoring_batch.rs - Selector:
fn[batch_fills_evidence_preserves_current_records_and_reauthors_only_changed_inputs] - Kind:
fn tests/authoring_batch.rs:531–686
// {test}`requirements.authoring.batch`
// {test}`requirements.authoring.concurrency`
// {test}`requirements.authoring.usage_storage`
// {test}`requirements.ci.determination`
// {test}`requirements.authoring.progress`
// {test}`requirements.configuration.loading`
// {test}`requirements.authoring.configuration`
// {test}`requirements.authoring.refresh`
// {test}`requirements.authoring.persistence`
#[test]
fn batch_fills_evidence_preserves_current_records_and_reauthors_only_changed_inputs() {
let server = Server::start(true, None);
let fixture = Fixture::new(&server.endpoint, Some(2));
let source = fixture.project.join("src/lib.rs");
fs::write(
&source,
format!(
"{}\n// {{test}}`requirements.alpha`\n#[test]\nfn alpha_requirement() {{ assert_eq!(alpha(), 1); }}\n",
fs::read_to_string(&source).unwrap().replace(
"pub fn beta()",
"// :::{fixme} requirements.beta\n// :github: example/app#123\n// Beta has no test yet.\n// :::\npub fn beta()",
)
),
)
.unwrap();
let output = fixture.run(&["author", "--all", "--config", "mock"]);
assert!(
output.status.success(),
"{}",
String::from_utf8_lossy(&output.stderr)
);
assert_eq!(server.subjects().len(), 6);
let report = habeas::validate_repository(&fixture.project).unwrap();
assert!(report.errors.is_empty(), "{:?}", report.errors);
assert!(!fixture.project.join("evidence/rust").exists());
let mut beta = fixture.evidence("requirements.beta");
beta["determination"] = json!({"FIXME":["example/app#123"]});
beta["rationale"] = "The source explicitly acknowledges the missing beta test.".into();
fs::write(
fixture.project.join("evidence/requirements.beta.json"),
serde_json::to_vec_pretty(&beta).unwrap(),
)
.unwrap();
let example = fixture.evidence("requirements.alpha_case");
let gamma = fixture.evidence("requirements.gamma");
let gamma_case = fixture.evidence("requirements.gamma_case");
for (record, name) in [(&example, "alpha_case"), (&gamma_case, "gamma_case")] {
assert!(record.get("requirement").is_none(), "{record}");
assert!(
record["example"]
.as_str()
.unwrap()
.contains(name.split('_').next().unwrap()),
"{record}"
);
}
let usage = fixture.usage();
assert_eq!(usage.len(), 6);
assert!(
usage
.iter()
.all(|run| run["outcome"] == "completed" && run["evidence_written"] == true)
);
{
let requests = server.requests.0.lock().unwrap();
assert_eq!(
requests.peak, 2,
"the configured concurrency bounds in-flight requests"
);
assert!(
requests.first_pair_overlapped,
"a second assessment must start before the first model response"
);
}
fs::write(&fixture.config, "invalid TOML [").unwrap();
let no_op = fixture.run(&["author", "--all"]);
assert!(
no_op.status.success(),
"{}",
String::from_utf8_lossy(&no_op.stderr)
);
fs::remove_file(&fixture.config).unwrap();
let no_config = fixture.run(&["author", "--all"]);
assert!(
no_config.status.success(),
"{}",
String::from_utf8_lossy(&no_config.stderr)
);
#[cfg(unix)]
{
let no_op_terminal = fixture.run_in_pty(false, "xterm-256color");
assert!(
no_op_terminal.status.success(),
"{}",
String::from_utf8_lossy(&no_op_terminal.stderr)
);
assert_eq!(
String::from_utf8_lossy(&no_op_terminal.stdout).trim(),
"0 authored; 6 skipped as current; 0 failed"
);
assert!(!String::from_utf8_lossy(&no_op_terminal.stderr).contains("0/0 finished"));
}
assert_eq!(server.subjects().len(), 6);
assert_eq!(fixture.usage().len(), 6);
fs::write(&fixture.config, &fixture.config_text).unwrap();
let changed = fs::read_to_string(&source)
.unwrap()
.replace("-> u8 { 1 }", "-> u8 { 1_u8 }");
fs::write(&source, changed).unwrap();
let unread_change = fixture.run(&["author", "--all"]);
assert!(unread_change.status.success(), "{unread_change:?}");
assert_eq!(server.subjects().len(), 6);
fs::write(
&source,
fs::read_to_string(&source).unwrap().replace(
"fn alpha_requirement() { assert_eq!(alpha(), 1); }",
"fn alpha_requirement() { assert_eq!(alpha(), 1_u8); }",
),
)
.unwrap();
#[cfg(unix)]
let updated = fixture.run_in_pty(false, "xterm-256color");
#[cfg(not(unix))]
let updated = fixture.run(&["author", "--all"]);
#[cfg(unix)]
{
let escape = regex::Regex::new(r"\x1b\[[0-?]*[ -/]*[@-~]").unwrap();
let raw = String::from_utf8_lossy(&updated.stderr);
let plain = escape.replace_all(&raw, "");
assert!(plain.contains("1/1 finished"), "{plain}");
assert!(!plain.contains("6/6 finished"), "{plain}");
}
assert!(
updated.status.success(),
"{}",
String::from_utf8_lossy(&updated.stderr)
);
assert_eq!(server.subjects().len(), 7);
assert_eq!(
server.subjects().last().unwrap(),
"requirement requirements.alpha"
);
assert_eq!(fixture.usage().len(), 7);
assert_eq!(
String::from_utf8_lossy(&updated.stdout).trim(),
"1 authored; 5 skipped as current; 0 failed; policy once"
);
assert_eq!(fixture.evidence("requirements.beta"), beta);
assert_eq!(fixture.evidence("requirements.alpha_case"), example);
assert_eq!(fixture.evidence("requirements.gamma"), gamma);
assert_eq!(fixture.evidence("requirements.gamma_case"), gamma_case);
let report = habeas::validate_repository(&fixture.project).unwrap();
assert!(report.errors.is_empty(), "{:?}", report.errors);
}
Input 5: outline tests/authoring_batch.rs fn[ollama_batches_are_serial_by_default]
- File:
tests/authoring_batch.rs - Selector:
fn[ollama_batches_are_serial_by_default] - Kind:
fn tests/authoring_batch.rs:688–702
// {test}`requirements.authoring.concurrency`
// {test}`requirements.authoring.batch`
#[test]
fn ollama_batches_are_serial_by_default() {
let server = Server::start(false, None);
let fixture = Fixture::new(&server.endpoint, None);
let output = fixture.run(&["author", "--all"]);
assert!(
output.status.success(),
"{}",
String::from_utf8_lossy(&output.stderr)
);
assert_eq!(server.subjects().len(), 6);
assert_eq!(server.requests.0.lock().unwrap().peak, 1);
}
Input 6: outline tests/authoring_batch.rs fn[concurrent_assessments_keep_their_own_continuing_histories]
- File:
tests/authoring_batch.rs - Selector:
fn[concurrent_assessments_keep_their_own_continuing_histories] - Kind:
fn tests/authoring_batch.rs:704–750
// {test}`requirements.authoring.concurrency`
#[test]
fn concurrent_assessments_keep_their_own_continuing_histories() {
let server = Server::start_with(false, Behavior::ReadEachSubject);
let fixture = Fixture::new(&server.endpoint, Some(4));
let output = fixture.run(&["author", "--all"]);
assert!(
output.status.success(),
"{}",
String::from_utf8_lossy(&output.stderr)
);
let state = server.requests.0.lock().unwrap();
assert_eq!(state.conversations.len(), 12);
for subject in state
.subjects
.iter()
.collect::<std::collections::BTreeSet<_>>()
{
let requests: Vec<_> = state
.conversations
.iter()
.filter(|(s, _)| s == subject)
.map(|(_, r)| &r["messages"])
.collect();
assert_eq!(requests.len(), 2);
let first = requests[0].as_array().unwrap();
let second = requests[1].as_array().unwrap();
assert_eq!(&second[..first.len()], first);
let continuation = &second[first.len()..];
assert_eq!(continuation.len(), 2);
assert_eq!(continuation[0]["role"], "assistant");
let calls = continuation[0]["tool_calls"].as_array().unwrap();
assert_eq!(calls.len(), 1);
let name = subject.rsplit('.').next().unwrap();
assert_eq!(
calls[0]["function"]["arguments"]["item"],
format!("fn[{name}]")
);
assert_eq!(continuation[1]["role"], "tool");
assert!(
continuation[1]["content"]
.as_str()
.unwrap()
.contains(&format!("fn[{name}]"))
);
}
}
Input 7: outline tests/authoring_batch.rs fn[throttled_assessment_retries_within_itself_while_others_proceed]
- File:
tests/authoring_batch.rs - Selector:
fn[throttled_assessment_retries_within_itself_while_others_proceed] - Kind:
fn tests/authoring_batch.rs:752–802
// {test}`requirements.authoring.concurrency`
#[test]
fn throttled_assessment_retries_within_itself_while_others_proceed() {
let server = Server::start_with(
false,
Behavior::ThrottledOnce {
subject: "requirement requirements.alpha",
},
);
let fixture = Fixture::new(&server.endpoint, Some(2));
let output = fixture.run(&["author", "--all"]);
assert!(
output.status.success(),
"{}",
String::from_utf8_lossy(&output.stderr)
);
// Six assessments plus one retried request, never more than two at once.
let subjects = server.subjects();
assert_eq!(subjects.len(), 7, "{subjects:?}");
assert_eq!(
subjects
.iter()
.filter(|subject| *subject == "requirement requirements.alpha")
.count(),
2
);
assert!(server.requests.0.lock().unwrap().peak <= 2);
assert_eq!(
fixture.evidence("requirements.alpha")["determination"],
true
);
// The retry stays inside the throttled assessment's own conversation and
// usage record; no other assessment is restarted or failed.
let usage = fixture.usage();
assert_eq!(usage.len(), 6);
assert!(usage.iter().all(|run| run["outcome"] == "completed"));
let alpha = usage
.iter()
.find(|run| run["subject"] == "requirements.alpha")
.unwrap();
assert_eq!(alpha["request_count"], 2);
assert_eq!(alpha["requests"][0]["outcome"], "failed");
assert_eq!(alpha["requests"][1]["outcome"], "completed");
assert!(
usage
.iter()
.filter(|run| run["subject"] != "requirements.alpha")
.all(|run| run["request_count"] == 1)
);
}
Input 8: outline tests/authoring_batch.rs fn[failed_assessment_keeps_other_results_and_reports_failure]
- File:
tests/authoring_batch.rs - Selector:
fn[failed_assessment_keeps_other_results_and_reports_failure] - Kind:
fn tests/authoring_batch.rs:804–859
// {test}`requirements.authoring.concurrency`
// {test}`requirements.authoring.batch`
// {test}`requirements.authoring.reporting`
// {test}`requirements.authoring.usage_storage`
// {test}`requirements.authoring.progress`
#[test]
fn failed_assessment_keeps_other_results_and_reports_failure() {
let server = Server::start(true, Some("requirement requirements.alpha"));
let fixture = Fixture::new(&server.endpoint, Some(2));
let output = fixture.run(&["author", "--all"]);
assert!(!output.stderr.contains(&b'\x1b'));
assert!(!output.stderr.contains(&b'\r'));
assert!(!output.status.success());
assert_eq!(server.subjects().len(), 6);
assert!(
!fixture
.project
.join("evidence/requirements.alpha.json")
.exists()
);
assert_eq!(fixture.evidence("requirements.beta")["determination"], true);
assert_eq!(
fixture.evidence("requirements.alpha_case")["determination"],
true
);
assert_eq!(
fixture.evidence("requirements.gamma")["determination"],
true
);
let usage = fixture.usage();
assert_eq!(usage.len(), 6);
assert_eq!(
usage
.iter()
.filter(|run| run["outcome"] == "failed")
.count(),
1
);
assert_eq!(
usage
.iter()
.filter(|run| run["outcome"] == "completed")
.count(),
5
);
let diagnostics = format!(
"{}{}",
String::from_utf8_lossy(&output.stdout),
String::from_utf8_lossy(&output.stderr)
);
assert!(diagnostics.contains("requirements.alpha"), "{diagnostics}");
assert!(
diagnostics.contains("fixture model rejected"),
"{diagnostics}"
);
}
Input 9: outline tests/authoring_batch.rs fn[interrupted_terminal_progress_keeps_unstarted_work_incomplete]
- File:
tests/authoring_batch.rs - Selector:
fn[interrupted_terminal_progress_keeps_unstarted_work_incomplete] - Kind:
fn tests/authoring_batch.rs:1066–1078
// {test}`requirements.authoring.progress`
// {test}`requirements.authoring.usage_storage`
// {test}`requirements.authoring.batch`
// {test}`requirements.authoring.concurrency`
// {test}`requirements.references.coverage.report`
#[cfg(unix)]
#[test]
fn interrupted_terminal_progress_keeps_unstarted_work_incomplete() {
// Concurrency one is the Ollama default: only one assessment is running.
for (overlap, concurrency) in [(true, 2), (false, 1)] {
assert_interruption_stops_the_batch(overlap, concurrency);
}
}
Input 10: outline tests/authoring_batch.rs fn[a_denied_mandatory_input_aborts_only_its_assessment]
- File:
tests/authoring_batch.rs - Selector:
fn[a_denied_mandatory_input_aborts_only_its_assessment] - Kind:
fn tests/authoring_batch.rs:1210–1283
// {test}`requirements.authoring.batch`
// {test}`requirements.authoring.concurrency`
// {test}`requirements.authoring.read_denial.mandatory`
// {test}`requirements.authoring.persistence`
// {test}`requirements.authoring.usage_storage`
#[test]
fn a_denied_mandatory_input_aborts_only_its_assessment() {
let server = Server::start_with(
false,
Behavior::Judgments {
failing_subject: None,
},
);
// One at a time, so the assessments after the aborted one were queued.
let fixture = Fixture::new(&server.endpoint, Some(1));
fs::write(fixture.project.join("private.txt"), "private\n").unwrap();
fs::write(
fixture.project.join("habeas.toml"),
"version = 1\n\n[evidence]\ndisallow = [\"private.txt\"]\n",
)
.unwrap();
// The workspace disallows this anchor, a mandatory input of
// `requirements.alpha`.
let chapter = fixture.project.join("md/requirements.md");
let text = fs::read_to_string(&chapter).unwrap();
fs::write(
&chapter,
text.replacen(
":::{req} alpha\n",
":::{req} alpha\n:impl: private.txt\n",
1,
),
)
.unwrap();
let output = fixture.run(&["author", "--all"]);
assert!(!output.status.success(), "{output:?}");
let diagnostic = String::from_utf8_lossy(&output.stderr);
assert!(diagnostic.contains("private.txt"), "{diagnostic}");
assert!(diagnostic.contains("disallowed"), "{diagnostic}");
assert!(diagnostic.contains("habeas.toml rule"), "{diagnostic}");
// It made no request; the others ran and kept their evidence.
let subjects = server.subjects();
assert!(
!subjects
.iter()
.any(|subject| subject == "requirement requirements.alpha"),
"{subjects:?}"
);
assert!(
!fixture
.project
.join("evidence/requirements.alpha.json")
.exists()
);
for name in [
"requirements.alpha_case",
"requirements.beta",
"requirements.gamma",
] {
assert_eq!(fixture.evidence(name)["determination"], true, "{name}");
}
let usage = fixture.usage();
let aborted = usage
.iter()
.find(|run| run["subject"] == "requirements.alpha")
.expect("the aborted assessment has a usage record");
assert_eq!(aborted["outcome"], "failed");
assert_eq!(aborted["request_count"], 0);
assert_eq!(aborted["evidence_written"], false);
// With --stdout it emits no evidence JSON.
let single = fixture.run(&["author", "requirements.alpha", "--stdout"]);
assert!(!single.status.success(), "{single:?}");
assert!(single.stdout.is_empty(), "{single:?}");
}
Input 11: outline tests/configuration.rs fn[backend_configuration_round_trips_without_materializing_defaults]
- File:
tests/configuration.rs - Selector:
fn[backend_configuration_round_trips_without_materializing_defaults] - Kind:
fn tests/configuration.rs:108–158
// {test}`requirements.authoring.configuration_structure`
// {test}`requirements.authoring.configuration_serialization`
// {test}`requirements.authoring.configuration_precedence`
// {test}`requirements.authoring.configuration_storage`
// {test}`requirements.authoring.concurrency`
// {test}`requirements.configuration.serialization`
#[test]
// {test}`requirements.configuration.loading`
fn backend_configuration_round_trips_without_materializing_defaults() {
let source = r#"
version = 1
[authoring]
default = "Cloud"
[authoring.configs.Cloud]
backend = "bedrock"
model = "arn:aws:bedrock:us-west-2:123:inference-profile/exact-id"
aws_profile = "research"
region = "us-west-2"
[authoring.configs.Cloud.options]
temperature = 0.2
max_tokens = 777
enabled = true
labels = ["a", "b"]
[authoring.configs.Cloud.options.custom]
arbitrary = "provider-defined"
[authoring.configs.local]
backend = "ollama"
model = "tiny:latest"
"#;
let path = Path::new("settings.toml");
let config = UserConfig::parse(source, path).unwrap();
let authoring = config.authoring.as_ref().unwrap();
assert!(authoring.projects.is_empty());
let local = &authoring.configs["local"].backend;
let BackendConfig::Ollama(ollama) = local else {
panic!("wrong backend")
};
assert_eq!(ollama.endpoint(), "http://localhost:11434");
assert_eq!(ollama.endpoint, None);
assert!(ollama.options.is_empty());
assert_eq!(local.model_ref().model, "tiny:latest");
assert_eq!(local.model_ref().backend, BackendKind::Ollama);
let json = authoring.configs["Cloud"].backend.options_json().unwrap();
assert_eq!(json["custom"]["arbitrary"], "provider-defined");
assert_eq!(json["max_tokens"], 777);
let serialized = config.to_toml().unwrap();
assert!(!serialized.contains("endpoint"));
assert!(!serialized.contains("http://localhost"));
assert!(!serialized.contains("concurrency"));
assert_eq!(UserConfig::parse(&serialized, path).unwrap(), config);
}
Input 12: outline tests/configuration.rs fn[authoring_concurrency_defaults_overrides_and_invalid_values]
- File:
tests/configuration.rs - Selector:
fn[authoring_concurrency_defaults_overrides_and_invalid_values] - Kind:
fn tests/configuration.rs:160–206
// {test}`requirements.authoring.concurrency`
// {test}`requirements.authoring.configuration_structure`
// {test}`requirements.authoring.configuration_serialization`
// {test}`requirements.authoring.configuration_precedence`
// {test}`requirements.authoring.configuration_storage`
// {test}`requirements.configuration.loading`
// {test}`requirements.configuration.serialization`
#[test]
fn authoring_concurrency_defaults_overrides_and_invalid_values() {
let dir = tempfile::tempdir().unwrap();
let path = dir.path().join("config.toml");
for backend in ["bedrock", "ollama", "openai"] {
let base =
format!("version = 1\n[authoring.configs.model]\nbackend = '{backend}'\nmodel = 'm'\n");
let defaults = UserConfig::parse(&base, &path).unwrap();
let resolved =
resolve_authoring_from(&path, Some(&defaults), dir.path(), Some("model")).unwrap();
assert_eq!(resolved.concurrency, None);
let expected = if backend != "ollama" {
std::thread::available_parallelism()
.map(|n| n.get())
.unwrap_or(1)
} else {
1
};
assert_eq!(resolved.effective_concurrency(), expected);
assert!(!defaults.to_toml().unwrap().contains("concurrency"));
let configured = UserConfig::parse(&format!("{base}concurrency = 7\n"), &path).unwrap();
let resolved =
resolve_authoring_from(&path, Some(&configured), dir.path(), Some("model")).unwrap();
assert_eq!(resolved.concurrency.unwrap().get(), 7);
assert_eq!(resolved.effective_concurrency(), 7);
let serialized = configured.to_toml().unwrap();
assert!(serialized.contains("concurrency = 7"));
assert_eq!(UserConfig::parse(&serialized, &path).unwrap(), configured);
assert!(resolved.backend.options().is_empty());
for invalid in ["0", "-1", "1.5", "'2'"] {
let error = UserConfig::parse(&format!("{base}concurrency = {invalid}\n"), &path)
.unwrap_err()
.to_string();
assert!(error.contains(&path.display().to_string()), "{error}");
assert!(error.contains("concurrency"), "{error}");
}
}
}
Input 13: outline tests/configuration.rs fn[workspace_configurations_accept_validate_and_override_concurrency]
- File:
tests/configuration.rs - Selector:
fn[workspace_configurations_accept_validate_and_override_concurrency] - Kind:
fn tests/configuration.rs:1014–1075
// {test}`requirements.authoring.concurrency`
// {test}`requirements.authoring.configuration_precedence`
#[test]
fn workspace_configurations_accept_validate_and_override_concurrency() {
let temp = tempfile::tempdir().unwrap();
let root = temp.path().canonicalize().unwrap();
let user_path = root.join("user.toml");
let user = UserConfig::parse(
"version = 1\n[authoring.configs.shared]\nbackend = 'bedrock'\nmodel = 'user'\nconcurrency = 5\n",
&user_path,
)
.unwrap();
let path = root.join("habeas.toml");
for (workspace, expected) in [("concurrency = 3\n", Some(3)), ("", None)] {
for backend in ["bedrock", "ollama", "openai"] {
fs::write(
&path,
format!("version = 1\n[authoring.configs.shared]\nbackend = '{backend}'\nmodel = 'local'\n{workspace}"),
)
.unwrap();
let loaded = load_workspace_config(&root).unwrap().unwrap();
let resolved = resolve_authoring_with_workspace_from(
&user_path,
Some(&user),
Some(&loaded),
&root,
Some("shared"),
)
.unwrap();
// The workspace config replaces the user config as a whole,
// including its concurrency.
assert_eq!(resolved.config_path, path);
assert_eq!(resolved.concurrency.map(|value| value.get()), expected);
let default = if backend != "ollama" {
std::thread::available_parallelism()
.map(|n| n.get())
.unwrap_or(1)
} else {
1
};
assert_eq!(
resolved.effective_concurrency(),
expected.unwrap_or(default)
);
let serialized = loaded.config.to_toml().unwrap();
assert_eq!(serialized.contains("concurrency = 3"), expected.is_some());
}
}
for invalid in ["0", "-1", "1.5", "'2'"] {
let text = format!(
"version = 1\n[authoring.configs.shared]\nbackend = 'ollama'\nmodel = 'm'\nconcurrency = {invalid}\n"
);
let error = WorkspaceConfig::parse(&text, &path)
.unwrap_err()
.to_string();
assert!(error.contains("concurrency"), "{error}");
fs::write(&path, text).unwrap();
let error = load_workspace_config(&root).unwrap_err().to_string();
assert!(error.contains(path.to_str().unwrap()), "{error}");
assert!(error.contains("concurrency"), "{error}");
}
}
Referenced definitions
Input 2: requirements selection requirements.authoring.provider_backoff
requirements.authoring.provider_backoff:md/requirements/authoring.md:539–567
:::{req} provider_backoff
When a provider reports a transient failure, the harness MUST wait and retry
the same completion request. Transient failures are throttling, reported
through HTTP 429 or a Bedrock `ThrottlingException`; temporary unavailability,
reported through HTTP 500, 502, 503, or 504 or a Bedrock
`ServiceUnavailableException`, `InternalServerException`, or
`ModelNotReadyException`; and a request with no response after ten minutes,
which the harness MUST abandon. The retry MUST retain its prompt, history,
tools, and pending inputs. It MUST NOT
restart the assessment or repeat already completed tool calls. A permanent
input/context-length error, authentication failure, or invalid request MUST
remain an error; mentioning tokens in an error message alone MUST NOT trigger
retries.
The backoff window MUST start at one second and double after each consecutive
transient failure, up to sixty seconds. Each delay MUST be randomly selected
between half and all of that window to spread parallel retries. An available
provider `Retry-After` value, in seconds or HTTP-date form, MUST be honored as a
minimum delay even when longer than the window. A successful response MUST reset
backoff for the next completion request, and interruption MUST cancel both the
wait and further retries.
Each attempt MUST be recorded under {cite}`requirements.authoring.usage_requests`.
Hidden SDK retries MUST remain disabled so the harness can account for attempts.
Transient retries MUST NOT be reported as finished judgments or terminal
assessment errors while recovery is still in progress. Pending inputs MUST be
recorded as evidence only after the request succeeds.
{cite}`requirements.authoring.provider` {cite}`requirements.authoring.delivered_inputs`
:::
Other sources
Input 1: requirements selection requirements.authoring.concurrency
requirements.authoring.concurrency:md/requirements/authoring.md:1744–1759
:::{req} concurrency
Each named authoring configuration MUST accept an optional positive integer
`concurrency` in its configuration table. When omitted, the maximum number of
simultaneous assessments MUST default to the number of available logical CPUs
for Bedrock and OpenAI, falling back to one when that count is unavailable, and to one for
Ollama. A configured value MUST override the default for each backend; zero
MUST be rejected as invalid configuration.
Batch authoring MUST use asynchronous tasks on a runtime with a fixed worker
thread pool. The number of assessments running at once MUST NOT exceed the
selected concurrency. Each assessment MUST retain its own model conversation and
usage record. Transient provider failures, including throttling, MUST be
retried within the affected assessment under
{cite}`requirements.authoring.provider_backoff`; every other provider error MUST
be reported through the ordinary assessment-failure path.
:::