Skip to content

[engine] fix: strict uuid pg_ids, case-insensitive lookups, strict reads on delete paths - #65

Merged
effecet merged 1 commit into
mainfrom
port/pgid-strict-2026-11
Nov 16, 2026
Merged

effecet merged 1 commit into
mainfrom
port/pgid-strict-2026-11

Conversation

@effecet

@effecet effecet commented Nov 16, 2026

Copy link
Copy Markdown
Owner

What

  • Strict uuid filter (validPgIds / valid_pg_ids): only real 8-4-4-4-12 uuids join the thermal batch. One id that passed the old [0-9a-fA-F-]{36} filter but failed Postgres's ::uuid cast failed the whole batch, so every memory fell back to frontmatter ranking. Rejects are counted on stderr (count only).
  • Case-insensitive lookups: both sides of every pg_id comparison are lower-case, so a hand-edited upper-case pg_id resolves instead of ranking as an orphan.
  • Strict reads on delete paths: findFilesByPgId (used by forget and the rename sweep) and memory_dedup.py main() (whose T1/T2 are deleted under --apply) only accept a top-level pg_id inside a real --- block (LF or CRLF). No 800-char fallback, no nested match, no regex built from the id, and an empty id matches nothing. Index ranking stays lenient.

Behaviour changes

  • A file whose only pg_id is in the body, nested under another key, or after an unclosed fence is no longer deleted (memory_dedup reports it as T4_REVIEW).
  • A case variant or quoted value of the same id is now swept with it.
  • In memory_dedup, an upper-case pg_id of a live entity moves from T4 to KEEP/T1/T2 by the usual rules.

Tests

  • vitest 729 passed (+7 skipped), pytest 360 passed; 9 new tests fail on main.
  • Mutation-checked: Python 6/7 killed, TS 3/4 killed; both survivors are equivalent (CRLF is normalised by read_text; ids from Postgres are never padded).

…ads on delete paths

- validPgIds / valid_pg_ids: only real 8-4-4-4-12 uuids join the thermal
  batch, lower-cased. One id that passed the old [0-9a-fA-F-]{36} filter but
  failed Postgres's ::uuid cast failed the whole batch, and every memory fell
  back to frontmatter ranking. Rejects are counted on stderr (count only).
- Lookups compare lower-case on both sides, so a hand-edited upper-case pg_id
  resolves instead of ranking as an orphan.
- findFilesByPgId (which picks the files `forget` and the rename sweep
  DELETE) reads pg_id with readFrontmatterField(..., { strict: true }): a real
  `---` block (LF or CRLF), top-level key only, no 800-char or nested fallback,
  no regex built from the id, and an empty id matches nothing.
- memory_dedup.read_fm gains the same strict mode, used by main(), whose
  T1/T2 results are deleted under --apply. Index ranking stays lenient in both.

Behaviour changes: a file whose only pg_id is in the body, nested, or after
an unclosed fence is no longer deleted (memory_dedup reports it as T4); a
case variant or quoted value of the same id now is. In memory_dedup an
upper-case pg_id of a live entity moves from T4 to KEEP/T1/T2 by the usual
rules.

Tests: vitest 729 passed (+7 skipped), pytest 360 passed. 9 new tests fail on
main. Mutants killed: Python 6/7 (survivor: CRLF opening fence, equivalent
because read_text normalises newlines), TS 3/4 (survivor: trim of the id,
equivalent for ids from Postgres).

Gate: Full, 6 reviewers + disclosure reader, 2 rounds. Fixed: lenient reader
on the dedup delete path, misleading comment, docstrings, `---foo`/quoted/BOM
cases, strict key requiring the colon right after it (as in TS). Declined:
splitting the strict flag into a second function (internal; both twins share
the shape). mypy findings unchanged from main.
@claude

claude Bot commented Nov 16, 2026

Copy link
Copy Markdown

Reviewed the diff in scripts/memory_dedup.py, src/file-sync.ts and both test files. I didn't run the test suite. I found no correctness, security or contract problems.

  • Strict frontmatter reader: it is used only on the delete paths (findFilesByPgId and main() T1/T2). It requires a real --- fence (LF or CRLF, optional BOM) and a top-level key. The TS and Python regexes agree. When a file is ambiguous it is kept, which is the safe direction.
  • Empty-id guard in findFilesByPgId: this closes a real hazard. Without it, an empty id would match every file that has no pg_id.
  • validPgIds / valid_pg_ids: both enforce a strict 8-4-4-4-12 uuid and lower-case the ids. The anchored TS regex and the Python fullmatch are equivalent, and the lookups are lower-cased on both sides.
  • Tests: coverage is good. It includes CRLF, BOM, nested keys, an empty block, ---foo, case differences, prefix ids and the empty id.
  • Docs: the behaviour changes are internal, with no public contract change. I saw no README or diagram updates and none looked necessary.

Verdict: PASS ccebfac

@effecet
effecet merged commit 4380d57 into main Nov 16, 2026
10 checks passed
@effecet
effecet deleted the port/pgid-strict-2026-11 branch November 16, 2026 20:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant