{"record":{"id":"2e7df6807e2c0194","repo":"Hmbown/CodeWhale","slug":"needle-matches-notes-refusing-to-guess-whi","errorCode":null,"errorMessage":"`{needle}` matches {} notes; refusing to guess which to edit","messagePattern":"`(.+?)` matches (.+?) notes; refusing to guess which to edit","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/native_memory.rs","lineNumber":856,"sourceCode":"\n/// Find the single bullet whose text matches `needle`, comparing on the\n/// note body rather than the raw line so `- note` and indentation don't\n/// have to be reproduced by the caller.\n///\n/// Ambiguity fails closed. If a model asks to revise a note that appears\n/// twice, editing either one is a guess, and a wrong guess silently rewrites\n/// durable context.\nfn locate_note(body: &str, needle: &str) -> Result<usize> {\n    let matches: Vec<usize> = body\n        .lines()\n        .enumerate()\n        .filter(|(_, line)| bullet_text(line).is_some_and(|text| text == needle))\n        .map(|(index, _)| index)\n        .collect();\n    match matches.as_slice() {\n        [only] => Ok(*only),\n        [] => bail!(\"no memory note matches `{needle}`\"),\n        several => bail!(\n            \"`{needle}` matches {} notes; refusing to guess which to edit\",\n            several.len()\n        ),\n    }\n}\n\n/// The note body of a Markdown bullet, if the line is one.\nfn bullet_text(line: &str) -> Option<&str> {\n    let trimmed = line.trim();\n    trimmed\n        .strip_prefix(\"- \")\n        .or_else(|| trimmed.strip_prefix(\"* \"))\n        .map(str::trim)\n}\n\n/// Evidence is required on every in-place edit and held to the same bounds\n/// as a note. An unexplained rewrite of durable context is the thing the\n/// journal exists to prevent.","sourceCodeStart":838,"sourceCodeEnd":874,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/0c42157ee52f9d55af2b506d71b46249910f77d3/crates/tui/src/native_memory.rs#L838-L874","documentation":"locate_note found more than one bullet with identical text. Ambiguity fails closed: guessing which duplicate to edit could silently rewrite the wrong piece of durable context, so the caller must disambiguate by retiring one copy first or revising the wording.","triggerScenarios":"Thrown at crates/tui/src/native_memory.rs:856 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Retire one of the duplicate notes first","Or reword one so the needle is unique","Then retry the revise/retire"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"0c42157ee52f9d55af2b506d71b46249910f77d3","analyzedAt":"2026-08-20T21:50:45.477Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}