fix(storage): drop write-only connects_to and index synapse source_id/target_id - #25
Merged
acidkill merged 1 commit intoJun 22, 2026
Conversation
…/target_id Synapse edges are stored in the document model (source_id/target_id columns), not as graph edges. This makes that consistent (option A from acidkill#15): - Drop the connects_to table. add_synapse issued a RELATE into it and delete_neuron cleaned it up, but nothing traverses ->connects_to-> anywhere in src/. It was write-only, and it never even wrote: the "RELATE neuron:$src -> connects_to -> ..." form does not parse (a parameter in the record-id position) and the call sits in a try/except, so on a live brain connects_to has 0 rows. Removes a dead per-insert round-trip. - Declare source_id/target_id on synapse. They are the fields add_synapse writes and get_synapses filters on, previously absent from the schema. - Repoint idx_synapse_source/idx_synapse_target from out/in (only a RELATION table populates those, so they covered empty columns and lookups full-scanned) to source_id/target_id. Adds tests/unit/test_synapse_document_model.py. The ensure_schema parser that drops comment-prefixed DEFINE TABLE statements (so tables run SCHEMALESS) is left untouched on purpose: it affects every table, not just synapse, and flipping it would activate SCHEMAFULL across ~25 tables at once. Co-Authored-By: Captain Nemo <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.
Summary
This implements option A from #15 (tidy the document model). Three related, backward-compatible changes to the synapse area:
Drop the
connects_toedge table.add_synapseissuedRELATE neuron:$src -> connects_to -> neuron:$tgt(in a try/except) anddelete_neuroncleaned it up, but nothing insrc/ever traverses->connects_to->(grep returns zero). It was write-only. In fact it never even wrote: theneuron:$srcform (a parameter in the record-id position of a record literal) does not parse, the except swallowed the error, and our live brain has 0 connects_to rows after thousands of synapse inserts. So this removes a per-insert round-trip that did nothing.Declare
source_id/target_idonsynapse. These are the fieldsadd_synapsewrites andget_synapsesfilters on, but they were not in the SCHEMAFULL definition. Declaring them makes the schema match what is persisted (1609 synapses in our brain carry them).Point the source/target indexes at the populated columns.
idx_synapse_source/idx_synapse_targetwere defined onout/in, which only a RELATION table fills.synapseis a normal table, so those columns are always empty and the indexes covered nothing: everyWHERE source_id = .../target_id = ...lookup full-scanned. They now indexsource_id/target_id.On the SCHEMAFULL parser (deliberately out of scope)
While here we noticed
ensure_schemasplitsSCHEMA_SQLon;and drops any fragment starting with--. Since everyDEFINE TABLE ... SCHEMAFULLis preceded by a comment, those table-level statements are dropped and tables run SCHEMALESS (confirmed:INFO FOR TABLE synapseshows no source_id/target_id in the field registry, yet they persist). That is the other half of the "two bugs cancelling out" from #15, and it is why the undeclared fields worked. It affects every table, not just synapse, so we did not touch the parser here: fixing it would activate SCHEMAFULL across ~25 tables at once. Declaring source_id/target_id makes synapse correct either way. Happy to raise the parser as its own thread.Changes
storage/surrealdb/schema.py: declaresource_id/target_idon synapse; repointidx_synapse_source/idx_synapse_target; remove theconnects_totable.storage/surrealdb/store.py: remove theconnects_toRELATE inadd_synapseand its cleanup indelete_neuron; fix the class docstring.tests/unit/test_synapse_document_model.py: regression test.Type of Change
Testing
Note for existing deployments
ensure_schemaswallows "index already exists", so on an existing DB the two indexes keep their oldout/indefinition until rebuilt (REMOVE INDEX+ re-run, orREBUILD INDEX). Fresh installs get the corrected indexes directly. Say the word if you would prefer the schema useOVERWRITEfor these two.CHANGELOG (### Fixed)
connects_totable (the RELATE never parsed and nothing traversed it) and persist synapse edges via thesource_id/target_iddocument fields, now declared in the schema and covered by the source/target indexes (previously on the never-populatedout/in, so lookups full-scanned).Context: #15