Repository navigation
fix: route the usage table through getTableName and make setup.sql re-applicable (GIT-84) - #33
Merged
2 commits merged intoSep 21, 2026
Merged
2 commits merged into
2 commits merged into
Conversation
…-applicable (GIT-84)
Scar usage was written to and read from the literal table "scar_usage". That
table does not exist on a customer store (setup.sql creates gitmem_scar_usage),
so every usage write 404'd and the loss went unnoticed. On a blank Supabase,
gitmem_scar_usage stayed at 0 rows after recall, confirm_scars and
session_close.
- record-scar-usage, record-scar-usage-batch, analytics and behavioral-decay now
use getTableName("scar_usage"). The two storage.upsert("scar_usage") sites are
unchanged: the storage layer already applies the prefix.
- Guard test: fails on a bare table-name literal passed to directUpsert,
directQuery, directQueryAll or directPatch, in a `table:` option, or in a
REST URL. It also fails if storage is handed an already-prefixed name.
Literals that setup.sql creates under exactly that name are allowlisted
pending a ruling.
- setup.sql:
- refresh_scar_behavioral_scores() only rewrites rows whose decay_multiplier
actually changes. Otherwise, once usage rows land, it bumps updated_at on
every session_start and invalidates the GIT-98 disk cache.
- Adds the missing DROP POLICY IF EXISTS for gitmem_licenses and
gitmem_license_activations, so a second run no longer fails at statement 72.
- schema/migrations/GIT-84-ntegs-scar-usage-rename.sql: NOT EXECUTED. Needs
human review. nTEG's install (prefix orchestra_) keeps usage in plain
scar_usage; this renames it to orchestra_scar_usage and leaves a
security_invoker compatibility view.
Tests: +8 (4 table-name guard, 4 setup.sql re-apply safety).
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2 tasks
…age (GIT-84) schema/ ships in the npm package, so the nTEG-specific rename migration would have gone to every customer. It now lives in the private orchestra repo (ops/migrations/). nTEG's own upgrade still needs that privately held migration before it runs this release. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Linear: https://linear.app/nteg-labs/issue/GIT-84
What
1. The usage table now goes through
getTableName("scar_usage"). Every customer store hasgitmem_scar_usage, so the literal"scar_usage"404'd on every usage write and read.tools/record-scar-usage.ts:64directUpsert("scar_usage")getTableName("scar_usage")tools/record-scar-usage-batch.ts:164directUpsert("scar_usage")getTableName("scar_usage")services/analytics.ts:204directQueryAll("scar_usage")getTableName("scar_usage")services/behavioral-decay.ts:101/scar_usage/${getTableName("scar_usage")}tools/record-scar-usage.ts:73,tools/session-close.ts:266storage.upsert("scar_usage")getTableName(collection), so changing these would double-prefixThe effect-tracker labels (
track("scar_usage", …)) and the local collection name incommands/migrate-local.tsare not table names and are left alone.2. Guard test (
tests/unit/table-name-literals.test.ts). It fails on a bare table-name literal passed todirectUpsert,directQuery,directQueryAllordirectPatch, in atable:option, or in a REST URL. It also checks the reverse for storage: storage must not be handed a prefixed name orgetTableName(). Againstorigin/mainit flags exactly the four sites above.3.
setup.sql:refresh_scar_behavioral_scores()now only rewrites rows whose value changes:AND l.decay_multiplier IS DISTINCT FROM <same GREATEST(...)>. This has to ship with this PR: once usage rows start landing, the old UPDATE bumpsupdated_aton everysession_startand invalidates PR fix: cache the embedding index on disk so a cold process start costs bytes, not megabytes (GIT-98) #31's disk cache.DROP POLICY IF EXISTSforgitmem_licensesandgitmem_license_activations, sosetup.sqlcan be re-applied. Before this, a second run failed at statement 72.scar_enforcement_variants.activeisn't touched; that's GIT-106.tests/unit/schema-setup-reapply.test.tschecks: every policy and trigger is dropped before it's created, tables and indexes useIF NOT EXISTS, and theIS DISTINCT FROMguard is present. Two of its four tests fail on the oldsetup.sql.Sweep: other string-literal table names (report only, need a ruling)
setup.sqlcreates these under exactly these names, or not at all, so changing only the code would break them. They're allowlisted in the guard test with the reasons below.setup.sql?gitmem_query_metricsservices/metrics.ts:169, :369, :383, :407gitmem_prefixGITMEM_TABLE_PREFIXknowledge_triplesservices/triple-writer.ts:290,services/supabase-client.ts:421,tools/graph-traverse.ts:165, :174, :261scar_enforcement_variantsservices/variant-assignment.ts:69,services/variant-generation.ts:322.activecolumn drift is GIT-106variant_assignmentsservices/variant-assignment.ts:100, :139variant_performance_metricstools/recall.ts:606/rest/v1/gitmem_learnings,/rest/v1/gitmem_${table}commands/check.ts:145, :354, :452checkCLI hard-codesgitmem_; wrong under a custom prefixcommunity_feedbackservices/feedback-remote.ts:9Venue check: blank Supabase (
setup.sqlonly, no edge functions)setup.sqlre-apply: applied the patchedsetup.sqla second time over the existing schema. It succeeded, where it previously failed at statement 72.gitmem_scar_usage= 1 row (was 0 on main). There were zeroscar_usage404s, andhealthshowsscar_usage 1/1 succeeded.session_start#1session_start#2 (no new usage)IS DISTINCT FROMrewrote 0 rowsKnown follow-up (surfaced by this fix, not fixed here)
analytics.ts:204selectsscar_titleandscar_severity, whichgitmem_scar_usagedoesn't have, givingcolumn gitmem_scar_usage.scar_title does not exist. Both reads are non-fatal, but they return nothing. It needs a ruling: add the columns tosetup.sql, or join to learnings.test/GIT-83-blank-supabase-driver) treats this as an unexpected failure and exits 1 on this branch. That's intended: remove the GIT-84 entry fromEXPECTED_FAILURESand ticket the analytics 400 when this merges.Tests
npx tsc --noEmit -p .: no errorsnpm run test:unit(withHOMEset to a temp dir): 76 files / 1221 tests passed. main is 74 / 1213, so this adds +8 tests: 4 table-name guard, 4setup.sqlre-apply safety.No version bump and no publish.
🤖 Generated with Claude Code