Files
Ehsan-hashandJerrettDavis c4ea31b156 fix(memory): resolve partial IDs beyond the first 1000 records (#4389)
## Description

`headroom memory show` tries a full ID first, then searches by prefix.
The fallback only examined the newest 1,000 memories. That could report
an older memory as missing or silently select a newer memory when
another matching ID existed outside that first page.

Use the existing unlimited `MemoryFilter()` query for this fallback.
Exact-ID lookup, literal prefix matching, superseded-memory filtering,
and the existing missing/ambiguous-ID errors stay the same.

## Type of Change

- [x] Bug fix

## Changes Made

- Remove the 1,000-row cap from the partial-ID fallback.
- Add real SQLite CLI regressions for an older unique match and
ambiguity across that boundary.

## Testing

- [x] Focused and affected integration tests pass.
- [x] Lint, format, type, and repository pre-push checks pass.
- [x] Actual CLI behavior verified with a synthetic SQLite database.

- Before the correction, `TestMemoryShow` had 4 passing tests and both
new regressions failed.
- Afterward, all 6 show tests passed.
- All 77 affected CLI, index-sync, query-filter, and SQLite-store tests
passed.
- Whole-project Ruff check and format check passed (1,812 files already
formatted).
- Repository pre-commit checks, including mypy and commitlint, passed.
- The full repository pre-push gate passed under pinned Rust 1.95.0 and
Node 22.20.0: Rust formatting, workspace Clippy/tests, extension
rebuild/import verification, 177 Python tests (4 skipped), and
commitlint. No hooks were bypassed.
- Independent review found no blocking findings.

```text
77 passed, 274 warnings in 2.21s
```

The warnings are existing `datetime.utcnow()` deprecations.

## Real Behavior Proof

- Environment: macOS arm64, Python 3.12.15, Rust 1.95.0, editable
checkout with its native extension built locally. The 77 affected tests
and CLI proof were repeated after the pinned extension rebuild. No
provider/model was used for this proof. All proof data was synthetic,
with offline mode enabled and telemetry disabled.

- Exact command / steps: Create a temporary `SQLiteMemoryStore`, use
`save_batch` to add 1,000 filler memories dated 2022-01-01 and
`target-memory-old` dated 2021-01-01. Run the actual installed CLI
against that database:

```sh
headroom memory show --db-path "$repro_db" target-memory-old --json
headroom memory show --db-path "$repro_db" target- --json
headroom memory show --db-path "$repro_db" absent- --json
```

- Observed result: The unique older prefix resolves, the missing ID is
rejected, and adding a newer match makes the shared prefix ambiguous:

```text
target-memory-old: exit 0, id=target-memory-old
target-:          exit 0, id=target-memory-old
absent-:          exit 1, Error: Memory not found: absent-
```

Then add `target-memory-new` dated 2023-01-01 and repeat the `target-`
command:

```text
exit 1, Error: Ambiguous ID 'target-'. Matches: ['target-m', 'target-m']
```

On the unchanged baseline, the unique older prefix instead returned
`Memory not found`; after adding the newer match, the same prefix
incorrectly exited 0 and selected `target-memory-new`. Full-ID and
missing-ID controls behaved correctly before and after. The temporary
database and all CLI child processes were cleaned up.

- Not tested: The complete Python suite, external providers or embedding
models, Windows, or Linux. The prefix fallback still materializes the
matching store's full query result; full IDs retain the direct lookup
path.

## Runtime Rollout Safety

- Rollout-managed feature(s): None. This is a local SQLite CLI
correction.
- Minimum rollout channel: Not applicable; no rollout-managed feature or
channel changes.
- Stable/default behavior changed: Yes. Partial-ID lookup searches all
eligible memories and rejects ambiguous prefixes across the former
1,000-row boundary.
- Kill switch / disable path: No new switch. Full IDs retain the direct
lookup path.
- Unsafe override required: No.
- Qualification impact: No schema, configuration, dependency, provider,
or rollout-qualification changes.
- Rollback path: Revert commit 017c9a5 to restore the previous behavior.

## Review Readiness

- [x] I have performed a self-review
- [x] This PR is ready for human review

The contributing agent completed self-review and verification; a
separate reviewer checked the complete patch.

## Checklist

- [x] Regression tests fail before the fix and pass afterward.
- [x] Focused and affected integration tests pass.
- [x] No manual changes to `CHANGELOG.md`.

<!-- devin-review-badge-begin -->

---

<a href="https://app.devin.ai/review/headroomlabs-ai/headroom/pull/4389"
target="_blank"><picture><source media="(prefers-color-scheme: dark)"
srcset="https://static.devin.ai/assets/gh-devin-review-dark.svg?v=4"><img
src="https://static.devin.ai/assets/gh-devin-review-light.svg?v=4"
alt="Devin Review"></picture></a>
<!-- devin-review-badge-end -->

Co-authored-by: JerrettDavis <mxjerrett@gmail.com>
2026-10-24 08:44:26 -07:00
..