[schemas] enhanced-thoughts: sync RPCs with current ExoCortex behavior#37
[schemas] enhanced-thoughts: sync RPCs with current ExoCortex behavior#37alanshurafa wants to merge 1 commit into
Conversation
Existing installs ran older upsert/search RPCs than the reference brain. This brings them current without breaking the v1 contracts. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8e2b89072c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| WHERE jsonb_typeof(t.metadata->'original_fingerprints') = 'array' | ||
| AND t.metadata->'original_fingerprints' ? v_fingerprint |
There was a problem hiding this comment.
Do not let stale imports overwrite corrected embeddings
When this fallback matches, v_id belongs to the corrected row even though p_content is the old text. The existing capture flow I checked in integrations/open-brain-rest/index.ts:409-439 uses the returned id to write a newly computed embedding and metadata for p_content; reimporting an original fingerprint therefore overwrites the corrected row's embedding/metadata with stale data instead of leaving the correction untouched. This only occurs for rows with metadata.original_fingerprints, but it breaks the main dedup-correction scenario this path is adding.
Useful? React with 👍 / 👎.
| AND (NOT v_exclude_restricted | ||
| OR coalesce(t.sensitivity_tier, 'standard') <> 'restricted') |
There was a problem hiding this comment.
Honor metadata sensitivity when excluding restricted rows
When callers pass exclude_restricted=true, this condition only checks the promoted sensitivity_tier column. Rows captured before this schema, or by stock/canonical flows that store the tier in metadata (for example schemas/provenance-chains/schema.sql reads metadata->>'sensitivity_tier' for that reason), get the column default standard and are not backfilled here, so restricted metadata rows still come back from the new filtered search. Use the metadata tier as a fallback or backfill it before relying on this filter for lower-trust surfaces.
Useful? React with 👍 / 👎.
What this does
The
enhanced-thoughtsschema shipped an older generation of theupsert_thoughtandsearch_thoughts_textRPCs than the reference brain has been running. This PR closes that gap. Everything is additive and idempotent — re-runningschema.sqlon a v1 install is a no-op, and the v1 return contract ({id, fingerprint}) plus thestatus/status_updated_athandling thatworkflow-statusdepends on are left exactly as they were.Changes
search_thoughts_textlearns date and tier filters.p_filternow reads three reserved control keys —start_date,end_date(ISO 8601), andexclude_restricted(boolean) — and applies them at the data layer. They are peeled off before themetadata @> filtercontainment check, so any other key keeps its old behavior.upsert_thoughtgets two dedup/merge guards.metadata.original_fingerprints[]array, the reimport now lands on the corrected row instead.metadata.user_editsare treated as human-owned and stripped from an incoming automated patch, so a reimport can't clobber a human correction. Guards metadata keys only.ON CONFLICT. The unique-index race thatON CONFLICThandled for free is caught explicitly and folded back into the merge path.New opt-in
match_thoughts_superseded_aware. Same shape as the corematch_thoughtsplus asuperseded_bycolumn. Thoughts that have been replaced (the target of asupersedesedge inthought_edges) take a 0.8x ranking penalty so fresh thoughts surface above their stale predecessors, without ever being excluded. The corematch_thoughtsis untouched; callers opt in by name, matching therecency-boosted-match-thoughtspattern. Installed only whenschemas/typed-reasoning-edges/is present; otherwise it's skipped with a NOTICE and the rest of the migration still applies.ID contract
All ported references use
UUIDagainstpublic.thoughts(id). The superseded-aware RPC returnssuperseded_by UUIDand readsthought_edgeswherefrom_thought_idis the newer replacement andto_thought_idis the stale thought — the directional semantics OB1'styped-reasoning-edgesalready documents.Importance scale
ExoCortex widened its own importance to 0-6. Open Brain's upsert already accepts a wider 0-100 range, so it never clipped 0-6 values — switching to 0-6 here would retroactively rescale every existing row, which is a breaking data change, not an additive one. The 0-100 clamp stays; the README documents 0-6 as a subset for cross-system parity.
Testing
Applied against a throwaway PostgreSQL instance with stub
thoughts+thought_edgestables:{id, fingerprint}; re-insert dedupes to the same row.titleagainst a robot overwrite.start_dateandexclude_restrictedfilters return the expected subset.match_thoughts_superseded_awarereturns the stale row at 0.8x withsuperseded_byset, fresh row at full similarity.schema.sqlis clean; droppingthought_edgestriggers the documented skip-with-NOTICE.Compatibility
Preserves the workflow-status dependency documented in NateBJones-Projects#328 —
upsert_thoughtstill writesstatus/status_updated_at, and the README's Prerequisites now call outworkflow-statusexplicitly.