Skip to content

fix: archive_learning prefix by UUID range; 0-row PATCH not durable (GIT-119) - #54

Merged
1 commit merged into
mainfrom
bugfix/GIT-119-archive-and-patch-rows
Sep 23, 2026
Merged

1 commit merged into
mainfrom
bugfix/GIT-119-archive-and-patch-rows

Conversation

@nTEG-dev

Copy link
Copy Markdown
Member

GIT-119: archive_learning prefix resolution; a 0-row PATCH is not durable

Just upgrade the package. Nothing to change on your database. Works on the v1.8.0 schema.

What was wrong

  • archive_learning resolved an id prefix with id=like.<prefix>%. The column is uuid, and Postgres has no LIKE for it (42883 "operator does not exist"), so prefix archiving failed on every store.
  • A full UUID skipped resolution. PostgREST answers 200 [] when a PATCH matches nothing, so archiving a nonexistent id reported "Archived" and durable: true.
  • The same blind spot applied to all 8 directPatch callers.

Fix

  • The prefix resolves from the warm local index first. When cold, it asks the store for the UUID range the prefix spans (and=(id.gte.<prefix>000…,id.lte.<prefix>fff…)). UUIDs order bytewise, so the range is exact. The PATCH is id=eq.<uuid>.
  • directPatch returns { count, rows }. Every caller treats count 0 as not durable:
Caller On 0 rows
archive_learning success:false, durable:false, "nothing was archived"
session_close embedding (saveSessionEmbedding, extracted) throws inside the tracked effect
session_start superseded mark (markSessionSuperseded, exported) throws, caught and logged
resolveThreadInSupabase returns false
touchThreadsInSupabase throws per thread, caught and logged
archiveDormantThreads not counted as archived
updateRelevanceData throws, tracked as a relevance_update failure
saveTranscript patch_warning

Evidence

Unit, parameterized over all 8 callers (tests/unit/services/directpatch-zero-rows.test.ts), fetch stubbed so every PATCH returns 200 []:

  • Branch: 9/9 pass.
  • Main: 8 fail. Six fail on behaviour (archive durable true, resolve true, no touch error, dormant counted 1, no relevance failure, no transcript warning). Two fail with "not a function" because the embedding and superseded writes were inline on main; they were extracted so the test can reach them.

Venue flow on v1.8.0 (vujndhcumgroztfkkdus). The driver inserts a learning after the server loaded its index, archives it by 8-char prefix, then archives a nonexistent full UUID.

  • Main, exit 1:
GET /rest/v1/gitmem_learnings?select=id&id=like.0ca41922%25&limit=2 -> 404  (operator does not exist)
archive_learning of a nonexistent id claimed success: Archived learning 00000000-0000-4000-8000-00000000d119.
  • Branch, exit 0: Archived learning 5e394eee → 5e394eee-642c-…, row is_active=false; the ghost id returns "No learning … in the store — nothing was archived".

Suite: tsc clean. Unit 1369 on the branch vs 1357 on main (+12: 9 parameterized, 3 archive).

Old-behaviour tests changed

  • archive-learning.test.ts: two tests asserted the like. filter. They now assert the UUID range filter. The directPatch mock default now returns {count:1, rows}, the new shape.

Stacking note

thread-supabase.ts overlaps GIT-117 (#52), which reads patched.length. At release/D those lines become patched.count.

🤖 Generated with Claude Code

… not durable (GIT-119)

archive_learning sent id=like.<prefix>% against a uuid column, which Postgres
rejects (42883), so prefix archiving failed on every store. The prefix now
resolves from the local index, or from the store as a UUID range when cold.

directPatch returns { count, rows }. PostgREST answers 200 [] when a PATCH
matched nothing; all 8 callers now treat count 0 as not durable (archive of a
nonexistent id, session embedding, superseded mark, thread resolve/touch/
auto-archive, relevance update, transcript path).

Tests: +12 (9 parameterized zero-row cases, 3 archive). Venue driver gains a
prefix archive of a row the index has not seen, and a nonexistent full UUID.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@nTEG-dev nTEG-dev closed this pull request by merging all changes into main in 60a990e Sep 23, 2026
@nTEG-dev
nTEG-dev deleted the bugfix/GIT-119-archive-and-patch-rows branch September 23, 2026 05:34
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