requirements.authoring.submission.searches.line_numbers
Requirements index · View definition
Requirement
After validating submission arguments or resolving the UUID resubmission form, the outstanding-search gate MUST precede line-number rejection or acceptance. An outstanding-search rejection MUST NOT consume the line-number resubmission or submission reminder.
Rationale
The three marked tests cover every obligation in requirements.authoring.submission.searches.line_numbers.
Obligations
- Argument validation, or resolving the UUID resubmission form, comes first. Then the outstanding-search gate runs, and only after it does line-number rejection or acceptance.
- A gate rejection must not consume the one line-number rejection or resubmission.
- A gate rejection must not consume the one submission reminder.
Coverage
- Arguments validated before the gate. In
the_search_gate_validates_arguments_first_and_does_not_consume_the_reminder, themalformediteration leaves a search outstanding and submits an empty rationale. The test asserts the error mentions “rationale”, does not mention “outstanding searches”, and ends after 2 requests with no determination recorded. - Gate before line-number rejection. In
search_gate_preserves_line_number_correction_and_uuid_resubmission, a line-number rationale is submitted while a search is outstanding.requests[2]contains “outstanding searches” and does not contain “rationale set to exactly”, so the gate won over line-number rejection.- After
Finish, the same submission gets the line-number rejection:requests[4]contains “rationale set to exactly”. So the gate rejection did not consume that rejection.
- Gate before UUID resubmission and acceptance. In the same test, a new search is opened after the rejection and
RetainRejectedis sent (the UUID resubmission form).requests[6]ends with “outstanding searches”, so the gate takes precedence over acceptance.- After
Finish,RetainRejectedis accepted. The final judgment isJudgment::Falsewith the original rationale preserved.
- Gate before a second line-number rationale.
a_second_line_number_rationale_fails_only_after_searches_are_finishedmakes a first line-number rejection that accompanies a call. It then submits a second line-number rationale while a search is outstanding.requests[3]shows the gate message, not the “after a rejection” failure. AfterFinish, the second submission fails with “after a rejection”. It also asserts no determination was recorded and that the accompanying call did not run. - Reminder not consumed. In the non-malformed iteration of
the_search_gate_validates_arguments_first_and_does_not_consume_the_reminder, a valid submission is rejected by the gate. An empty turn then follows. The implementation inconversefails after a second empty turn, so the test would fail if the gate had setreminded. Insteadrequests[3]contains “Reminder:”, and the final submission is accepted after 5 requests.
Gaps None found. Each clause has at least one test that exercises it and asserts its outcome.
Inputs
Implementation
Input 5: outline src/authoring/mod.rs fn[converse]
- File:
src/authoring/mod.rs - Selector:
fn[converse] - Kind:
fn src/authoring/mod.rs:1325–1589
/// One conversation: sends the prompt with the source tools and the named
/// submission tool, delivers tool results until a submission is accepted,
/// and returns the parsed submission.
// {impl}`requirements.authoring.delivered_inputs`
// {impl}`requirements.authoring.usage_requests`
// {impl}`requirements.authoring.mandatory_inputs`
// {impl}`requirements.authoring.provider_backoff`
// {impl}`requirements.authoring.submission_count`
// {impl}`requirements.authoring.source_tools`
// {impl}`requirements.authoring.file_discovery`
// {impl}`requirements.authoring.text_search`
// {impl}`requirements.definitions.authoring_inputs`
// {impl}`requirements.authoring.prompt_parts`
// {impl}`requirements.authoring.result_pages`
// {impl}`requirements.authoring.output_limit`
// {impl}`requirements.authoring.line_numbers.rejection`
// {impl}`requirements.authoring.line_numbers.resubmission`
// {impl}`requirements.authoring.submission`
// {impl}`requirements.authoring.no_line_numbers`
// {impl}`requirements.authoring.usage_requests.failures`
// {impl}`requirements.authoring.provider_backoff.limit`
// {impl}`requirements.authoring.tool_descriptions.special_cases`
// {impl}`requirements.authoring.cache_checkpoints`
// {impl}`requirements.authoring.submission.searches`
// {impl}`requirements.authoring.submission.searches.recovery`
// {impl}`requirements.authoring.submission.searches.line_numbers`
// {impl}`requirements.authoring.submission.searches.accompanying_calls`
async fn converse<T>(
provider: &impl CompletionProvider,
sources: &mut AssessmentSources,
usage: &mut UsageLog,
prompt: Prompt,
(submit, site): (&str, bool),
parse: impl Fn(&Value) -> io::Result<T>,
) -> io::Result<T> {
let mut request = prompt.request();
request.tools = tool_definitions_with(submit, site)?;
let mut pending = sources.mandatory_inputs().to_vec();
let mut backoff = providers::ProviderBackoff::default();
// Pages are kept only until this assessment finishes.
let mut pages = pages::ResultPages::default();
// Whether the one continuation after a cut-off response has been used.
let mut continued = false;
// The one rejection of a rationale citing line numbers.
let mut rejection = line_numbers::Rejection::default();
// Whether the one reminder to submit has been sent.
let mut reminded = false;
loop {
let index = usage.begin_request()?;
let started = Instant::now();
// An abandoned request is retried like any other transient failure.
let response =
match tokio::time::timeout(REQUEST_TIMEOUT, provider.complete(request.clone())).await {
Ok(response) => response,
Err(_) => Err(io::Error::new(
io::ErrorKind::TimedOut,
"provider request had no response within ten minutes",
)),
};
let failure = response.as_ref().err().map(providers::failure_codes);
usage.end_request(
index,
started.elapsed().as_millis(),
response.as_ref().ok().map(|r| &r.usage),
failure,
)?;
let response = match response {
Ok(response) => response,
// Tokio's clock, so a paused test clock reaches the limit too.
Err(error) => match backoff.retry(error, tokio::time::Instant::now().into_std()) {
providers::Retry::Wait(delay) => {
usage.retried(index)?;
tokio::time::sleep(delay).await;
continue;
}
providers::Retry::Stop(error) => return Err(error),
},
};
backoff = providers::ProviderBackoff::default();
sources.record_inputs(&pending);
pending.clear();
if matches!(response.finish_reason(), Some(FinishReason::Length)) {
// Rig reports a context-window overflow as `Length` too; Bedrock's
// raw reply tells the two apart, and continuing would only grow
// the conversation further.
if response.raw.get("stopReason").and_then(Value::as_str)
== Some("model_context_window_exceeded")
{
return Err(io::Error::other(
"the model's response was incomplete: the conversation exceeded the model's context window",
));
}
if continued {
return Err(io::Error::other(
"the model's response was incomplete: it reached the output limit again after one continuation",
));
}
let limit = provider.output_limit().ok_or_else(|| {
io::Error::other(
"the model's response was incomplete: it reached an output limit the configuration does not set",
)
})?;
continued = true;
request
.chat_history
.extend(cut_off_continuation(&response, limit, usage));
usage.save()?;
continue;
}
if let Some(error) = turn_failure(
&response.choice,
Some(&response.stop()),
response.finish_reason().as_ref(),
) {
return Err(io::Error::other(error));
}
let calls: Vec<_> = response.tool_calls().cloned().collect();
let submissions: Vec<_> = calls
.iter()
.filter(|call| call.function.name.as_str() == submit)
.collect();
if !submissions.is_empty() {
for call in &calls {
if call.function.name.as_str() != submit {
usage.skipped_tool(call.function.name.as_str());
}
}
if submissions.len() != 1 {
for _ in &submissions {
usage.tool(submit, true);
}
return Err(io::Error::other(format!(
"{submit} must be invoked exactly once; multiple submissions received"
)));
}
let arguments = Value::Object(submissions[0].function.arguments.clone());
let resubmitted = rejection.resubmitted(&arguments);
let result = parse(resubmitted.as_ref().unwrap_or(&arguments));
if result.is_err() {
usage.tool(submit, true);
return result;
}
let outstanding = pages.outstanding_searches();
if !outstanding.is_empty() {
usage.tool(submit, true);
let message = format!(
"Submission not accepted: outstanding searches: {}. Call finish_search for every listed search_id, using used:[] when no snippets qualify, then resubmit.",
outstanding.join(", ")
);
request.chat_history.push(
response
.message()
.ok_or_else(|| io::Error::other("model returned an empty response"))?,
);
let results = calls
.iter()
.map(|call| {
let text = if call.function.name.as_str() == submit {
message.clone()
} else {
"not run: the response also made a submission".to_owned()
};
call.error_result(vec![ToolResultContent::text(text)])
})
.collect();
usage.save()?;
request.chat_history.push(Message::tool_results(results));
continue;
}
if resubmitted.is_some() {
usage.tool(submit, false);
return result;
}
match rejection.decide(submit, &arguments, location_guidance()) {
line_numbers::Outcome::Accept => {
usage.tool(submit, false);
return result;
}
line_numbers::Outcome::Fail(error) => {
usage.tool(submit, true);
return Err(io::Error::other(error));
}
line_numbers::Outcome::Reject(message) => {
usage.tool(submit, true);
request.chat_history.push(
response
.message()
.ok_or_else(|| io::Error::other("model returned an empty response"))?,
);
let results = calls
.iter()
.map(|call| {
let text = if call.function.name.as_str() == submit {
message.clone()
} else {
"not run: the response also made a submission".to_owned()
};
call.error_result(vec![ToolResultContent::text(text)])
})
.collect();
usage.save()?;
request.chat_history.push(Message::tool_results(results));
continue;
}
}
}
if calls.is_empty() {
if reminded {
return Err(io::Error::other(format!(
"model finished without invoking {submit}, even after a reminder"
)));
}
reminded = true;
request.chat_history.extend(response.message());
request.chat_history.push(Message::User {
content: vec![UserContent::text(format!(
"Reminder: you MUST submit your result with the {submit} tool."
))],
});
usage.save()?;
continue;
}
request.chat_history.push(
response
.message()
.ok_or_else(|| io::Error::other("model returned an empty response"))?,
);
let mut results = Vec::new();
for call in calls {
match tools::dispatch_paged(
sources,
&mut pages,
call.function.name.as_str(),
&Value::Object(call.function.arguments.clone()),
) {
Ok(delivery) => {
usage.tool(call.function.name.as_str(), false);
if call.function.name.as_str() == "finish_search" {
// These dependencies describe snippets already delivered,
// not a new source read. Record them before acknowledgment.
sources.record_inputs(&delivery.inputs);
} else {
usage.prepared(call.function.name.as_str(), &delivery.inputs);
pending.extend(delivery.inputs);
}
usage.search_result(&delivery.result);
results.push(
call.result(vec![ToolResultContent::text(delivery.result.to_string())]),
);
}
// A denied read is an ordinary tool error the model can see;
// only a denied mandatory input aborts, before any request.
// {impl}`requirements.authoring.read_denial`
Err(error) => {
usage.tool(call.function.name.as_str(), true);
results.push(call.error_result(vec![ToolResultContent::text(
line_numbers::without_source_lines(&error.to_string()),
)]));
}
}
}
usage.save()?;
request.chat_history.push(Message::tool_results(results));
}
}
Tests
Input 2: outline src/authoring/mod.rs mod[tests]/fn[search_gate_preserves_line_number_correction_and_uuid_resubmission]
- File:
src/authoring/mod.rs - Selector:
mod[tests]/fn[search_gate_preserves_line_number_correction_and_uuid_resubmission] - Kind:
fn src/authoring/mod.rs:2984–3029
// {test}`requirements.authoring.submission.searches.line_numbers`
// {test}`requirements.authoring.line_numbers.rejection`
// {test}`requirements.authoring.line_numbers.resubmission`
#[tokio::test]
async fn search_gate_preserves_line_number_correction_and_uuid_resubmission() {
use SearchAction::{Call, Finish, RetainRejected};
let root = inputs::tests::project();
fs::write(root.path().join("src/lib.rs"), "fn helper() {}\n").unwrap();
let mut sources = AssessmentSources::prepare(root.path(), "requirements.ready").unwrap();
let state = tempfile::tempdir().unwrap();
let mut usage = UsageLog::start(state.path(), root.path(), &sources.subject_name).unwrap();
let cited = json!({"determination":false,"rationale":"src/lib.rs:1 needs work."});
let provider = SearchProvider {
submit: "submit_judgment",
turns: vec![
vec![Call("ripgrep", json!({"pattern":"absent"}))],
vec![Call("submit_judgment", cited.clone())],
vec![Finish(0, vec![])],
vec![Call("submit_judgment", cited)],
vec![Call(
"ripgrep",
json!({"pattern":"helper","path":"src/lib.rs"}),
)],
vec![RetainRejected],
vec![Finish(1, vec![])],
vec![RetainRejected],
],
requests: RefCell::default(),
};
let (judgment, evidence) = assess(&provider, &mut sources, &mut usage).await.unwrap();
assert_eq!(judgment, Judgment::False);
assert_eq!(evidence["rationale"], "src/lib.rs:1 needs work.");
let requests = provider.requests.borrow();
assert!(requests[2].to_string().contains("outstanding searches"));
assert!(!requests[2].to_string().contains("rationale set to exactly"));
assert!(requests[4].to_string().contains("rationale set to exactly"));
assert!(
requests[6]
.as_array()
.unwrap()
.last()
.unwrap()
.to_string()
.contains("outstanding searches")
);
}
Input 3: outline src/authoring/mod.rs mod[tests]/fn[a_second_line_number_rationale_fails_only_after_searches_are_finished]
- File:
src/authoring/mod.rs - Selector:
mod[tests]/fn[a_second_line_number_rationale_fails_only_after_searches_are_finished] - Kind:
fn src/authoring/mod.rs:3031–3095
// {test}`requirements.authoring.line_numbers.resubmission`
// {test}`requirements.authoring.submission.searches.line_numbers`
// {test}`requirements.authoring.submission.searches.accompanying_calls`
#[tokio::test]
async fn a_second_line_number_rationale_fails_only_after_searches_are_finished() {
use SearchAction::{Call, Finish};
let root = inputs::tests::project();
fs::write(root.path().join("src/lib.rs"), "fn untouched() {}\n").unwrap();
let mut sources = AssessmentSources::prepare(root.path(), "requirements.ready").unwrap();
let state = tempfile::tempdir().unwrap();
let mut usage = UsageLog::start(state.path(), root.path(), &sources.subject_name).unwrap();
let second = json!({"determination":true,"rationale":"src/lib.rs:2 is fine."});
let provider = SearchProvider {
submit: "submit_judgment",
turns: vec![
vec![
Call(
"habeas",
json!({"file":"src/lib.rs","item":"fn[untouched]"}),
),
Call(
"submit_judgment",
json!({"determination":false,"rationale":"src/lib.rs:1 fails."}),
),
],
vec![Call("ripgrep", json!({"pattern":"absent"}))],
vec![Call("submit_judgment", second.clone())],
vec![Finish(0, vec![])],
vec![Call("submit_judgment", second)],
],
requests: RefCell::default(),
};
let error = assess(&provider, &mut sources, &mut usage)
.await
.unwrap_err()
.to_string();
assert!(error.contains("after a rejection"), "{error}");
let requests = provider.requests.borrow();
assert_eq!(requests.len(), 5);
assert!(
requests[1]
.as_array()
.unwrap()
.last()
.unwrap()
.to_string()
.contains("not run")
);
assert!(
requests[3]
.as_array()
.unwrap()
.last()
.unwrap()
.to_string()
.contains("outstanding searches")
);
assert!(usage.record.determination.is_none());
assert!(
!sources
.recorded_inputs()
.iter()
.any(|input| input["item"] == "fn[untouched]")
);
}
Input 4: outline src/authoring/mod.rs mod[tests]/fn[the_search_gate_validates_arguments_first_and_does_not_consume_the_reminder]
- File:
src/authoring/mod.rs - Selector:
mod[tests]/fn[the_search_gate_validates_arguments_first_and_does_not_consume_the_reminder] - Kind:
fn src/authoring/mod.rs:3097–3151
// {test}`requirements.authoring.submission.searches.line_numbers`
// {test}`requirements.authoring.submission`
#[tokio::test]
async fn the_search_gate_validates_arguments_first_and_does_not_consume_the_reminder() {
use SearchAction::{Call, Finish};
for malformed in [true, false] {
let root = inputs::tests::project();
fs::write(root.path().join("src/lib.rs"), "fn helper() {}\n").unwrap();
let mut sources =
AssessmentSources::prepare(root.path(), "requirements.ready").unwrap();
let state = tempfile::tempdir().unwrap();
let mut usage =
UsageLog::start(state.path(), root.path(), &sources.subject_name).unwrap();
let valid = json!({"determination":true,"rationale":"Complete."});
let mut turns = vec![
vec![Call("ripgrep", json!({"pattern":"absent"}))],
vec![Call(
"submit_judgment",
if malformed {
json!({"determination":true,"rationale":""})
} else {
valid.clone()
},
)],
];
if !malformed {
turns.extend([
vec![],
vec![Finish(0, vec![])],
vec![Call("submit_judgment", valid)],
]);
}
let provider = SearchProvider {
submit: "submit_judgment",
turns,
requests: RefCell::default(),
};
let result = assess(&provider, &mut sources, &mut usage).await;
if malformed {
let error = result.unwrap_err().to_string();
assert!(error.contains("rationale"), "{error}");
assert!(!error.contains("outstanding searches"), "{error}");
assert_eq!(provider.requests.borrow().len(), 2);
assert!(usage.record.determination.is_none());
} else {
assert_eq!(result.unwrap().0, Judgment::True);
assert_eq!(provider.requests.borrow().len(), 5);
assert!(
provider.requests.borrow()[3]
.to_string()
.contains("Reminder:")
);
}
}
}
Other sources
Input 1: requirements selection requirements.authoring.submission.searches.line_numbers
requirements.authoring.submission.searches.line_numbers:md/requirements/authoring.md:1056–1061
:::{req} submission.searches.line_numbers
After validating submission arguments or resolving the UUID resubmission
form, the outstanding-search gate MUST precede line-number rejection or
acceptance. An outstanding-search rejection MUST NOT consume the line-number
resubmission or submission reminder.
:::