{"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/433685b2024e7bc4c99e1e2e326bcad39b4d9d65/crates/tui/src/native_memory.rs#L838-L874","documentation":"Companion guard to the no-match error: when the needle text matches more than one memory note bullet, `locate_note` refuses to pick one and bails with this message, since editing/retiring the wrong duplicate would be destructive.","triggerScenarios":"Calling `revise` or `retire` with a needle that exactly equals the bullet text of two or more stored notes (duplicate notes were accumulated via repeated `remember` calls with identical text).","commonSituations":"The same fact was remembered multiple times across sessions; near-identical notes exist because of repeated tool runs; deduplication was never run on the store.","solutions":["Deduplicate the store: retire/remove all but one copy, then retry with the unique remaining text.","Edit notes by index rather than by text so each operation targets a specific line.","Revise each duplicate to distinct text before operating on the intended one.","Avoid re-remembering identical notes; check for an existing match first."],"exampleFix":"// before: duplicate notes cause refusal\nstore.revise(\"deploy target is eu-west-1\", new_text).await?;\n// after: dedupe first\nstore.retire(\"deploy target is eu-west-1\").await?; // removes one copy\nstore.retire(\"deploy target is eu-west-1\").await?; // removes other\nstore.remember(\"deploy target is eu-west-1\").await?;\nstore.revise(\"deploy target is eu-west-1\", new_text).await?;","handlingStrategy":"validation","validationCode":"// Refuse to operate on ambiguous needles\nlet count = store.list().await?.iter().filter(|n| n.as_str() == needle).count();\nif count != 1 { bail!(\"needle '{needle}' is ambiguous ({count} matches); dedupe first\"); }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Deduplicate the memory store regularly.","Check for an existing identical note before calling remember.","Make note text unique by appending distinguishing context."],"tags":["memory","ambiguous","duplicate"],"backgroundTag":"ambiguous-match","analyzedSha":"433685b2024e7bc4c99e1e2e326bcad39b4d9d65","analyzedAt":"2026-09-15T12:24:24.634Z","contentChangedAt":"2026-09-15T12:24:24.634Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}