Skip to content

fix(knowledge): carry per-document ownership through a bundle round-trip - #13448

Merged
iamwhatever merged 2 commits into
mainfrom
fix/bundle-ownership-roundtrip-2670
Sep 28, 2026
Merged

iamwhatever merged 2 commits into
mainfrom
fix/bundle-ownership-roundtrip-2670

Conversation

@chenmingwei23

@chenmingwei23 chenmingwei23 commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: a .knowledge bundle round-trips the ownership of its own content -- imported items arrive owned by the document that exported them, and a store that already holds a bundle's source imports it instead of rolling the whole import back.

A .knowledge bundle moves content without moving the ownership of that content, and on many stores it cannot be imported at all.

export_all ships items, sources, entities, relations, source_locations and mentions. It does not ship the three per-document state tables that say which document owns which items: folder_file_state, artifact_item_state, agent_item_state.

Separately, sources.uri is UNIQUE while each store mints its own source ids. import_bundle inserted each bundle source under the id the EXPORTING store had used, so when the receiving store already held that uri the unique index skipped the row and every item then referenced a source id this store did not have. Measured on main:

remote artifact source id: c6ae5247-...
local artifact source id:  f9d7c598-...
pysqlite3.dbapi2.IntegrityError: FOREIGN KEY constraint failed

The whole import rolls back. That is reachable by re-importing a bundle into the store it came from, and by moving any bundle with an artifact:// or agent:// aggregate between two machines.

Why it matters

Two distinct user-visible failures.

The import simply fails. The user picks a bundle they exported, gets an error, and nothing tells them that the reason is a source they already have.

When the import does land, the knowledge it brings is permanently unmanaged. An item with no state row has no owner, so: nothing claims it for de-duplication, the Sources UI has no per-document group label for it, and a later ingest of the same document adds a second searchable copy instead of replacing the first. The user ends up with two answers to one question and no way to tell which is current.

That second failure is also what blocks the repair for interrupted ingest. Unowned items from a crash and unowned items from an import are indistinguishable, so a sweep that cleans up residue would delete legitimately imported knowledge. #2452 shipped exactly that sweep and had to be reverted for this reason.

Not a goal

What changed

Symptom: importing a bundle fails, or delivers knowledge nothing can manage.

Root cause: values local to the exporting side were treated as portable. A source's id belongs to the store that minted it, mtime belongs to the host the file sits on, and ownership was never in the bundle's vocabulary at all.

A source's cross-store identity is its uri. import_bundle resolves each bundle source by uri and records a map from the bundle's id to the local row's id, then rewrites items.source_id, source_locations.source_id and the state rows through it. Every case has a verdict:

local state before import result
neither the uri nor the id is present the source is created under the bundle's own id
the uri is present under a different id mapped to the local row; this is the rollback case
the id is present with the same uri identity, unchanged
the uri is absent and its id is taken by a different uri the uri is created under a freshly minted id, so no document is dropped and none is filed under the unrelated row
the bundle repeats one id under two uris KnowledgeBundleError, a 400. No export can produce it (sources.id is a PRIMARY KEY), and the later entry would overwrite the earlier one's place in the map
sources.id or sources.uri is not a non-empty string KnowledgeBundleError. Both become dictionary keys during the rewrite, so a list or dict raises an unhashable-type TypeError that no handler arm catches -- a 500 in place of the typed 400
a source id in no bundle source REFUSED as a typed 400, including when this store happens to hold that id. The foreign key cannot see that case -- an id held locally satisfies it, so the content lands under a source the bundle never named -- and it is the only one of the two that loses data

The last row is deliberate, and it is where the declared and undeclared paths had disagreed. The declared path already refuses to file a bundle's content under a local row that merely shares an id: when a bundle source's uri is absent here but its id is held by a different uri, the uri arrives under a freshly minted uuid4 rather than the unrelated row, because reusing that id "would file this bundle's documents under an unrelated source". The undeclared path did not have that rule -- it resolved the bare id against this store's sources and passed it to the insert -- so the foreign key refused exactly the harmless case (an id that exists nowhere) and admitted the harmful one (an id this store holds under a source the bundle never names). _source_fk now refuses any non-null reference absent from source_id_map, which completes the rule rather than adding a second one; a NULL reference is not a reference and imports unchanged. This also makes the plain INSERT in the sources loop defence in depth rather than a hope: were it to fail and leave a uri unmapped, its items are refused instead of misfiled -- the outcome that insert's own comment calls "the worst outcome available".

The withheld account is redacted on the way OUT, because its fields are the ones the inbound loop cannot touch. A withheld entry names what did not arrive in the bundle's own words: the document key, the ids it claimed, and the source they resolved to. Those are exactly the values _BUNDLE_STATE_PLAIN_FIELDS exempts from the handler's inbound _redact() loop, because the store matches them against a PRIMARY KEY and against items.id and so needs them byte-exact -- and a document key carries no length bound. That left the HTTP response as the one path on which bundle-authored text reached a reader unfiltered, since web.json_response returns the account verbatim, while the same handler already routes name and source_uri on those very rows through _redact() and the SEL copy is covered by _redact_and_clip. _WITHHELD_REDACTED_FIELDS is applied after the store has used and stored the real values, so the stored key stays byte-exact and the response carries no bundle-authored credential. Pinned from both sides: the credential does not appear anywhere in the response, and the stored slug is byte-identical.

The identity-column rule is enforced at the writer rather than in the endpoint's validator, matching the invariant this module already holds for sources.properties and entities.aliases: the dashboard endpoint is the store's only production caller today, and enforcing at the writer makes any future one safe by construction.

Ownership travels with the content. export_all ships the three state tables, keyed off the existing _DOC_STATE_TABLES definition so there is no second list to drift, and store.BUNDLE_STATE_KEY_COL is the one name the importer and the dashboard's bundle validator both read. A row owns the items THIS import inserted for it, and those items must have landed under the mapped source; a row written fresh carries that table's own live status (done for folder rows, active for the aggregates, which are not interchangeable vocabularies).

A collision is only a DIFFERENT document holding the key, and no withholding is silent. When the local row's own group overlaps the bundle's, this is that same document coming back. Deleting one chunk of a chunked document through the dashboard's single-item route leaves the group naming the deleted id while a surviving sibling keeps the row live -- so the absolute rule held the whole group back, the deleted chunk included, in the one case where the bundle is the only remaining copy. Its only exit was deleting the document's remaining chunks so the row owned nothing live, which asks the user to destroy content in order to recover content. Such a group is no longer withheld, and the ids that arrive JOIN the live row's group.

The arriving ids join the live row's group, which restores the design rather than changing it. The module already stated this behaviour twice and implemented it nowhere. store.py:3264-3266, in the blocking pass, is explicit that a same-document collision lets the absent ids through "to be merged into that row's group by the accepting pass" — the accepting pass never merged. And _adopt_reassigned_item at store.py:1556-1563 calls the outcome of a row that owns an item it does not name "the strand this whole model exists to prevent", for exactly the reason that matters here: its own delete path consults only item_ids.

Without the merge the gap is reachable by the ordinary restore order. Restore the newest backup, then an older one to recover what the newest had already lost: export_all pruned the newer group to the chunks it still carried, so the older bundle's row names ids the first restore already put down alongside the one it brings. INSERT OR IGNORE skips the present ids, so they never enter inserted_items; the whole row was then dropped while the new chunk was inserted and FTS-indexed. agent_item_state is the one table a bundle restores and nothing reaps it, so remove_document takes the ids its row names and walks past that chunk — which stays searchable, owned by nothing, and removable by no path at all.

Three properties make the merge safe, and each is pinned in both directions:

  • Only the ids this import inserted are taken. An id the bundle names that already existed here was skipped by INSERT OR IGNORE, so the row in the store is local content; adopting it would hand a foreign document the authority to replace or delete it. Unowned residue from an interrupted ingest is the reachable case.
  • The claim check exempts the row's own group and nobody else's. _claimed_item_ids includes the base group, so testing arriving & claimed_ids would refuse the very merge it exists to allow, while testing nothing would put one chunk in two groups.
  • The row's identity columns do not move. A bundle reaching this branch can be OLDER than the local copy, so an INSERT OR REPLACE would leave the row's content_hash and name describing a revision this store no longer holds — a silent data regression inside a data-integrity fix. The merge is an UPDATE item_ids.

One item in two groups is not a shape this schema has, which is why the claim check is sufficient rather than a heuristic: a de-duplication loser holds an empty group plus a source_locations claim by hash, and _adopt_reassigned_item, detach_source_location_by_hash and claimed_ids each refuse the overlap independently.

Where the group already names the returning id — a chunk deleted locally and restored from a bundle of the same revision — nothing has to be added, because no delete path rewrites a group (_delete_item_cascade leaves it alone and _adopt_reassigned_item only appends) and the row becomes accurate again the moment the chunk returns. Withholding that DOES still happen is now named: withheld carries an entry per held-back document or id with its reason, beside the items_withheld count.

A document key this store already holds blocks the bundle's copy of that document entirely. A (source, key) pair IS a document's identity within a source, so two documents cannot share one. A local row whose group is empty or names only deleted items is a marker rather than ownership -- a folder file that lost a de-duplication keeps a deduped row with an empty group, and every pending or failed scan row carries one too -- so the imported row takes the key, and the marker's claim on another source's items is released with it through detach_source_location_by_hash. A local row that DOES own items keeps the key, and _bundle_blocked_items then withholds that document's items from the import: letting them in would leave them permanently unowned, which is the defect this round-trip exists to remove rather than a lesser version of it. A local row's group counts as ownership only for the items filed under that row's OWN source. _adopt_reassigned_item leaves a stale claim by design when a content hash is ambiguous -- it refuses to cross-wire one item into two groups, so the un-adopted row keeps naming items delete_source_cascade moved to the recipient -- and those items are live. Counting a stale claim as ownership hands the key to a row that owns nothing here and withholds the bundle's document, losing its content silently, which is the same rule the accepting pass applies to the group a bundle ships. And the collision is computed for EVERY state table, not only the one whose rows travel: withholding is not reserving items for a claim someone goes on to make, it is the answer to "this store already holds that document", which a folder path and an artifact slug each answer for themselves. Restricting it to the restored table left a local folder file or artifact slug importing a second copy of its own text, unowned and removed by nothing. _bundle_state_restores() governs row restoration alone.

That is the only refusal reason that blocks an item. Every other one rejects a ROW as an untrustworthy statement about items that are themselves legitimate -- an unparsable group, one whose ids another row already owns, one the bundle files under a different source -- and those items arrive unowned exactly as they do from a bundle carrying no state tables at all. An over-claiming group is not among them: the ids the import wrote are owned and the rest are only named in the account.

An exported ownership group names only items that export carries, and only ones filed under that row's own source. The accepting pass keeps only the ids the import wrote, so an id the export omits is named on every restore of that document in the account of what arrived owned by nothing, and the group reaches the other side one id short of what the row claims. That shape is routine rather than exotic: no delete path prunes a state row's group -- _delete_item_cascade and delete_items_batch_in_txn both leave it, by design, because the group is accurate again once the chunk returns -- so a document that lost one chunk has a row naming a dead id, and shipping it verbatim reports content as unowned that nothing is actually missing. export_all prunes each group to the items it carries keyed to the source each is filed under, and drops a row that prunes to empty; this subsumes the namespace-only filter, since a row belonging wholly to another namespace prunes to nothing and that namespace's file_path, name and hashes stay in the machine. A bundle built elsewhere can still name an absent item; that id stays out of the group -- partial ownership would claim items another document holds -- and it is reported in withheld as ownership_row_names_absent_items with the document key and the ids. One id the bundle files under a DIFFERENT source is not a partial statement but an inconsistent one, and refuses the whole row: this store's own export cannot produce that shape.

Parsing a group is linear, and both of its fields are bounded. The membership test used entry not in group against the growing list, so an item_ids array of N unique strings cost O(N^2) -- and this parser runs inside asyncio.to_thread after BEGIN IMMEDIATE, with the import body read at max_bytes=None, so one large array spins a worker thread while holding the knowledge write lock. A set carries the membership test, and the two retained fields are bounded by name: _MAX_ITEM_GROUP_MEMBERS (4096) and _MAX_ITEM_ID_CHARS (128). Both bounds REFUSE rather than trim, in _bundle_group_bounds beside the existing identifier gate, because a trimmed group would under-claim in silence and hand the missing chunks to no one.

The claim exemption names the IDS a bundle's own row claims, not the key. Two independent reviewers found the two directions a key-level exemption fails in. A full export ships empty-group MARKER rows verbatim, so a key carried by such a row would vouch for ids it never claimed and hand them to whatever unrelated local row holds a stale claim -- the next delete of that document then takes the imported item. And a bundle that ships NO state row for a table states no ownership through it at all (the single-item export endpoint, and every bundle written before this change), so judging its items against that table's local claims withholds exactly what a delete removed, with no exemption able to exist because nothing was shipped to carry one. So a table the bundle is silent about is skipped, and within a table only the ids the bundle's own row for that key names are exempt.

An id a local row already claims does not arrive, unless the claiming row is the document this bundle is restoring and holds nothing live. Both halves fail in opposite directions. Without the rule, a stale group belonging to an UNRELATED document captures the item: claims are read before the item loop, so the id does not exist yet, the insert creates it, the claim goes live over content it never owned, and the bundle's own row is skipped as claimed -- leaving the item held only by that row, so deleting that unrelated document destroys imported content. Without the exception the ordinary restore breaks: _delete_item_cascade removes an item and leaves the doc-state group naming it, which is the documented normal shape, so exporting a document, deleting it and re-importing the export would meet the deleter's own stale row and withhold the item -- the one case where the file is gone and the bundle is the only copy. That row is the same (source, key) the bundle restores and owns nothing live, so the accepting pass repoints it; withholding there contradicts that pass instead of guarding it. An id that already exists here is outside both halves: INSERT OR IGNORE leaves the local row alone and the inserted-items rule already refuses to hand it to an imported claim.

One item is never owned by two rows. A group whose ids are already claimed, by a local row of the same source or by an earlier row in the same bundle, is refused. Two rows naming one item is content-destroying rather than untidy: the next document-level delete hands delete_items_batch an item whose only other holder is a state row it does not consult, finds nothing else holding it, and removes it, leaving the second row naming deleted content. _adopt_reassigned_item and detach_source_location_by_hash already refuse the same shape, so this closes a gap in an invariant the module holds elsewhere. The subset rule is not redundant with it: only the subset rule stops a bundle claiming pre-existing UNOWNED local content -- residue -- which it never shipped.

mtime does not travel; the content hashes do. The folder scan skips hashing a live row whose recorded mtime is at or above the file's, so a carried mtime from the exporting host would stop the local file ever being hashed again, silently leaving the imported text indexed in place of the local content with no self-correcting path. The importer writes the most negative FINITE double as the floor -- zero would strand a file dated at the epoch and a pre-epoch file carries a negative mtime, so neither is low enough, and -inf is not valid JSON in a bundle that gets exported again. content_hash and text_hash, which DO travel, are what keep the re-hash cheap by skipping re-extraction on a match.

Ownership covers only what this import inserted. An id the bundle ships that already exists here was skipped by INSERT OR IGNORE, so the row in the store is local content -- residue from an interrupted ingest is exactly the reachable case -- and naming it would hand a foreign document the authority to replace or delete something this store owns. A row must additionally own only items filed under its OWN source, which is a separate case: both sources can be in the bundle and differ.

A withheld document takes its dependent rows with it. Locations, mentions and entity_relations.source_item_id all point at an item by foreign key, so a row naming a withheld item would refuse the whole import -- losing an entire valid bundle over one document this store already has its own copy of. And a colliding row blocks nothing when its group overlaps another bundle row's: the bundle does not agree who owns such an item, so treating one row's collision as a verdict would omit a sibling document's valid content.

A folder row is never restored for a file this host does not have. The folder scan detects deletions by walking every state row and dropping the ones whose path the walk does not find, without consulting status -- so restoring a done row for an absent file is not a stale marker, it is an instruction to delete the items the import just brought. That made this change a data-loss regression in the ordinary "same folder watched on two machines" case, where the two hosts hold different file sets. Leaving the row out costs those items their ownership, which is the state they already had; restoring it costs them their existence. Any error answers "absent", because the failure mode of guessing present is deletion. The aggregate tables are unaffected: an artifact slug is not a path and no scanner reasons from its absence.

A namespace-scoped export ships only the scoped documents' state rows. An out-of-namespace row always fails the import's group test anyway, so shipping it would carry another namespace's file_path, document name and content hashes out of the machine for nothing. Filtered in export_all's namespace arm, exactly as source_locations already is. An unscoped export still ships every row.

Every bundle string that reaches a SQLite bind is UTF-8-validated at the writer. A lone surrogate is a str SQLite cannot encode, and the UnicodeEncodeError sits outside every arm the import endpoint catches, so it surfaces as a 500 instead of the typed 400. The state key is validated in _bundle_blocked_items, which is the first bind it reaches.

Only agent_item_state is restored on import, and the reaper test is why. A state row is a claim that a LOCAL subsystem owns this document, and importing one makes that claim on the subsystem's behalf without its knowledge -- so wherever that subsystem deletes a document because its state row names something the subsystem cannot see, the row is not a stale marker but an order to delete the items the import just brought. Two of the three owners reap exactly that way, and neither is a corner case:

  • folder_file_state -- FolderWatcher._do_scan step 4 walks every state row and drops the ones whose path its walk did not yield, WITHOUT consulting status. What the walk yields depends on the MAPPED source's own live filters (extension allowlist, min_file_bytes, ignore_patterns, confine_to_root, and a root .kiroignore re-read every sweep), so a receiving store that filters the same folder more narrowly than the sender deletes the arriving documents. Checking eligibility at import does not close it: the walk's answer changes afterwards whenever the user edits .kiroignore or narrows the source, so no check made at import stays true, and an exact check would be a second copy of the walk's per-file rules.
  • artifact_item_state -- reconcile_artifacts runs on every ArtifactKnowledgeSync.start, takes known.keys() - live, and removes each provably absent slug's group. A bundle imported on a host whose artifact store does not hold those slugs (any second machine, any restore) loses them on the next start. _known_kinds reads every row regardless of status, so no status value hides the row from that pass.
  • agent_item_state -- nothing reaps it. agent_source.remove_document runs only when a caller explicitly deletes that document; there is no reconcile pass, no inventory comparison and no absence test anywhere on the agent path.

The export still ships all three tables, because a bundle is a faithful record of the store and a future importer that can prove liveness could use them. Items from the two unrestored tables arrive UNOWNED, which is the state a bundle carrying no state tables already leaves them in, and each owning subsystem re-derives its row the next time it sees the document.

A repeated items.id is refused. item_source is keyed on it, so a repeat overwrites the earlier row's mapped source -- and because the withheld set holds the ID rather than the row, a collision resolved against the surviving mapping skips BOTH rows while the import reports success, with only the items_withheld count hinting that anything went missing. items.id is a PRIMARY KEY, so only one of the two could ever land through INSERT OR IGNORE in any case. sources.id is already refused when repeated under two uris, for this same overwrite.

Every row identifier the import tests for membership is validated as text at the writer. items.id, entities.id, relations.source_item_id, source_locations.item_id and mentions.item_id are each tested against a set[str] of withheld items, and set membership hashes the key unconditionally: a JSON array or object raises a TypeError that sits outside every arm the endpoint catches, answering 500 where the typed 400 belongs. A number is worse than the crash -- it hashes cleanly and matches nothing, so a withheld item's dependent row is written as though the item had arrived, and the foreign key then fails. None stays legitimate, because a relation need not name a source item and an absent key reads the same way.

Every source column a bundle supplies is UTF-8-validated at the writer, created_at included. A lone surrogate passes a type-and-emptiness check -- it is a non-empty str -- and is refused only by an encodability gate. sources.id and sources.uri were checked for type and emptiness only, so a lone surrogate -- a str SQLite cannot encode -- reached the bind and raised a UnicodeEncodeError, which is outside every arm the import endpoint catches and so surfaced as a 500 where the typed 400 belongs. The transaction still rolled back atomically, so the residual was a wrong status code rather than corruption, but the check was already there and the gate is the same one every other bundle string takes.

Every NOT NULL column a bundle supplies for a source is validated, and the source insert no longer suppresses its own failures. INSERT OR IGNORE INTO sources silently swallowed a NOT NULL violation, so a bundle source carrying "name": null never landed -- and because the row never landed, the uri stayed absent, nothing mapped that bundle source id, and _source_fk's id fallback then resolved the UNRELATED local source whose id happened to match. The documents were filed under it and granted ownership over, with no error and no recovery path. That is precisely the id/uri collision the remap detects and routes around a few lines earlier, arriving through the fallback instead.

name, source_type and created_at are now validated beside id and uri (a MISSING created_at still falls back to the import clock; only an explicit null is refused), so no bundle-supplied null can reach the constraint and the answer is this module's typed rejection. The insert is a plain INSERT as defence in depth: this branch has already established that the uri is absent and the id is free, so nothing can fire for a legitimate row, and a suppressed failure here is the worst outcome available. Note for anyone extending this: the store's SQLite driver raises an IntegrityError class the endpoint's except arms do not name, so a constraint violation surfaces as a server error rather than the typed 400 -- which is why the validations, not the constraint, are what make the rejection typed.

An entity stranded by a withheld item is dropped rather than left as a graph node no document supports. Mentions and relations both skip a withheld item, so an entity the bundle referenced only from those rows arrives reachable from nothing and inflates entities_created past what is reachable. The prune is scoped three ways -- to entities this import inserted, to ones the bundle actually referenced, and to ones nothing in the store references now -- so a bundle carrying a standalone entity with no mentions keeps it (hand-built bundles do that deliberately), and a pre-existing local orphan is left alone.

The new lists go through the same handler-side treatment as the existing ones: shape validation, and redaction of the display name and the agent document's locator. file_path is deliberately not redacted, because it is half of a PRIMARY KEY matched against a real path on disk and rewriting it would leave the row unable to find its own file.

Three review findings on this branch's own heads, all fixed here rather than overridden. Each was reachable, and each is pinned by a test proven to redden when only that fix is reverted.

  • A merge trusted the blocking pass for its own precondition. That pass never blocks an id two bundle rows both claim -- the bundle does not agree who owns it -- so such an id reached the accepting pass with a live local row on its key whose group shares nothing with the bundle's: a DIFFERENT document by the pass's own rule. The merge extended that row's group anyway, and the local document's next delete took the imported chunk with it, with no pass that reaps the row or reports it. The accepting pass now tests the overlap itself and skips a live disjoint row, naming it in the account as ownership_row_key_held_locally.
  • The claimed-id exemption is keyed on the bundle's own row, and therefore covers every table the bundle states. Scoping it to _BUNDLE_STATE_RESTORED_TABLES looked safer and was not: _delete_item_cascade never prunes a group, so a per-chunk delete on a folder- or artifact-backed document leaves the row naming that chunk while the file or slug is still here, and withholding the id loses it for good -- the scan reaps only a row whose path the walk MISSED and skips a done row whose mtime and hash are unchanged, so nothing re-ingests it. The opposite risk, a row whose document is gone here and not yet reconciled away, needs the owning subsystem's view of whether the document still exists, which is not reachable inside the import transaction; it is left to the reap it belongs to and named in the code.
  • Every IN list on this path is chunked under _MAX_SQL_PARAMS, the ceiling vector_memory already keeps and for the same reason: SQLite binds 32,766 on the bundled build but only 999 on a host still on a pre-3.32 library. The lengths are untrusted bundle input -- a bundle names as many sources as it likes, and one state row's group runs to _MAX_ITEM_GROUP_MEMBERS (4096) -- so both pass 999 on ordinary input and the OperationalError lands mid-transaction, rolling the whole import back and answering 500 where it should have succeeded. Four sites are covered, the two source-keyed reads and the two group-keyed probes; _items_exist already chunked and now shares the one constant.

Tests

Two new files, test/test_knowledge_bundle_ownership.py and test/test_knowledge_bundle_host_backed.py, 161 tests between them, all passing (pytest -n0), covering the round-trip for all three tables, the uri-collision case, re-import idempotence, every row of the case table above, the membership predicate, the owns-live-items collision rule from both sides plus the blocked-items consequence, the double-ownership refusal, the mtime floor, the released claim, the preserved 400 contract, and a legacy bundle with the keys absent. Two further pins live beside the handler they cover, in test/test_knowledge_handlers_coverage.py.

Four existing tests in this PR asserted behaviour these fixes disprove, and all four were inverted deliberately. Each is named here with what it asserted and why that assertion was wrong, because an inverted assertion inside a large test file is indistinguishable, to a reader scanning a diff, from a fix legitimising its own defect:

  1. test_group_is_dropped_when_one_item_lands_under_another_source -> test_an_item_landing_under_another_source_does_not_strand_its_sibling. Asserted ownership_rows_imported == 0 when one id of the group was already present locally. Wrong because that is the strand itself: the sibling this import DID write then has no row naming it, and only the document's own delete could ever have removed it. It now asserts the row is restored owning the sibling alone, that the already-local id keeps its own source and is not named by the row, and that the id left out is reported in withheld.
  2. test_a_bundle_naming_an_absent_item_is_refused_BY_NAME -> test_an_absent_item_is_named_and_left_out_of_the_group. Asserted, in its name and its docstring, that the whole row is refused when it names one absent id. Wrong because refusing the row discards ownership of the ids the import DID write, over an id it never had. The absent id is now named in withheld and left out of the group while the arrived ids are owned; the assertions on the withheld account are unchanged and one was added on the resulting group.
  3. test_item_naming_an_unknown_source_is_refused -- name kept, asserted match="FOREIGN KEY". Wrong because it made the foreign key the whole contract, and the foreign key cannot see the case that loses data: an undeclared id this store DOES hold satisfies the constraint, so the content is filed under an unrelated local source. It now expects the typed KnowledgeBundleError naming items.source_id, and a sibling pin covers the locally-held id the foreign key would have admitted.
  4. test_location_naming_an_unknown_source_is_refused -- the same inversion for source_locations.source_id, for the same reason.
  5. test_a_folder_row_does_not_exempt_a_stale_local_claim -> TestTheSameRowExemptionCoversEveryStatedTable::test_a_folder_rows_own_group_exempts_the_chunk_it_names. Asserted that a folder_file_state row could not exempt a claim on an id it names, because no row of that table is restored. Wrong because the exemption is keyed on the bundle's own row at the same (table, source, key), so what it forgives is this document meeting itself -- and for a file this host still has, that row owns the chunk correctly while nothing re-derives an id withheld there. A sibling pin now covers the rule the exemption is carved out of: a claim at a DIFFERENT key is still contested.

Three fixtures were repaired rather than inverted, listed for the same reason: their assertions are untouched and only the bundles they feed became well-formed.

  • test_agent_source_ownership_durability.py's _imported_item became _imported_bundle (two call sites). It handed import_bundle an item referencing a local source id with no sources entry, as a shortcut for "an independent writer commits mid-ingest". It now declares the aggregate source, which every producer ships, and the item still lands under the same source -- which is what those two pins are actually about.
  • test_bundle_violating_foreign_keys_is_400_not_500 and test_client_error_carries_no_raw_exception_text both reached the foreign key through an UNDECLARED source, an arm the typed refusal now takes first. Their bundles declare the source and let the missing ITEM trip the foreign key, so both keep exercising the sqlite3.IntegrityError -> 400 arm they exist for; confirmed against the store directly.

The reproduction was written and run before the fix existed. Pre-fix the control passed -- items_imported == 1, the older bundle's chunk does arrive -- while 5 assertions in TestASecondBundleOwnsTheChunksItBrings failed: the chunk is owned by nothing, the row names one id, remove_document leaves it alive, it still answers search_items_fts("chunk two"), and one item exists that no ownership row names.

Mutation-verified in BOTH directions, one mutation at a time, restored from a pristine copy held outside the repository and sha256-verified after each round, with no verdict accepted from a run that did not print an explicit pytest count. Baseline 153 passed in the ownership file; 7/7 caught for the original rule, and a further 6/6 for the three findings above -- one substitution site apiece, each verdict carrying an explicit pytest count.

direction behaviour mutated result
revert the whole original rule (whole group required, live row wins, no merge) 9 failed
revert the partial row is dropped again 3 failed
revert the live row is never merged into 5 failed
over-merge ids this import did not write are adopted 5 failed
over-merge another document's claim is ignored 2 failed
over-merge the bundle rewrites the local row's identity columns 5 failed
over-merge a different document on the same key is merged into 11 failed

The full revert reddens 5 of the 6 reproduction pins rather than all 6. The sixth is the control and stays green by design: the chunk still arrives either way, which is what makes the other five diagnostic instead of merely red.

Earlier rounds, with their pins still passing on this head:

Red on base, measured with a script driving the real ingest path rather than the unit fixtures:

base 96f4a157a1 this branch
import into a store holding the same uri IntegrityError: FOREIGN KEY constraint failed items_imported: 1, ownership_rows_imported: 1
items left pointing at an absent source row the import is lost none
bundle keys six, no state tables nine

Mutation-verified, one mutation at a time with an exact restore after each; all twenty-six reddened their own pin and none another's:

behaviour removed result
the source remap (insert by bundle id, item keeps the bundle's source_id) 3 failed
the state pass never runs 5 failed
a row that owns live items no longer wins the key 1 failed
a stale claim on another source's item wins the key 1 failed
only the restored table's collisions are computed 2 failed
created_at is not encodability-checked 2 failed
membership identifiers are not validated as text 12 failed
a repeated items.id is accepted 2 failed
entities.id is left out of the identifier gate 3 failed
a stale claim may capture an id the bundle ships 1 failed
a same-document stale claim blocks its own restore 1 failed
a live sibling withholds its own deleted chunk 1 failed
the claim arm stops exempting a restored key 2 failed
a withheld document is not named in the result 1 failed
a NEW liveness gate appears unconsidered 1 failed
the exemption covers a whole key, not its ids 1 failed
a table the bundle is silent about is judged anyway 1 failed
the export ships a group verbatim 2 failed
an unbacked ownership row is dropped silently 1 failed
the group parser rescans the list it builds 1 failed
the group bound trims instead of refusing 2 failed
ownership is not scoped to items this import inserted 3 failed
a row may own items filed under another source 1 failed
a local row wins the key even when it owns nothing 3 failed
a displaced marker keeps its claim 1 failed
colliding items are imported anyway 4 failed
a colliding row blocks a sibling row's items too 1 failed
dependent rows do not follow the withheld item 2 failed
one item may be owned by two rows 2 failed
identity columns are not required to be text 11 failed
a duplicate source id is accepted 1 failed
mtime travels from the exporting host 3 failed
the mtime floor is zero, so an epoch-dated file is stranded 1 failed
a scoped export ships every namespace's state rows 3 failed
the import does not report what it withheld 2 failed
a colliding row blocks an id the bundle files under another source 1 failed
state text is not UTF-8 validated 3 failed
an artifact row is restored onto this host 2 failed
a stranded entity is kept and counted 1 failed
source identity is not UTF-8 validated 2 failed
a null NOT NULL source column is not validated 2 failed
a null created_at is not validated 1 failed
the prune also takes an entity the bundle carries alone 1 failed
a folder row is restored for a file this host does not have 3 failed

Three pins were weak on an earlier pass and were rewritten rather than accepted, which is worth recording because each hid a different mistake. The local-presence pin's scenario tripped the subset rule instead, so it stayed green under that mutation; it now puts an already-present item id under an unrelated local source, the only way a bundle item legitimately fails to land under the mapped source. The collision pin covered only the case where the local row owns items, so the empty-row side is now pinned separately from both directions. And once the double-ownership check went in, the subset pin went green under its own mutation because the new check caught its cases too -- the case only the subset rule catches is a bundle claiming pre-existing unowned local content, which is now what that pin asserts.

Existing suites, narrow selections on the files that reference this diff: test_knowledge.py test_knowledge_handlers_coverage.py test_knowledge_embedding_space.py test_agent_source_ownership_durability.py -k "import or export or bundle or TestImportedFolderSourcesWaitForConfirmation", 103 passed. No existing test file is modified.

Gates: flake8, isort, mypy, black (the new file is black-clean; the ratchet's baseline covers only pre-existing files), comment-history with its selftest, sync-io-in-async, brand and docs-lint all clean.

One red in Backend Tests (Windows) is not from this diff: test_crew_log_crew_emitter.py::test_a_worker_report_through_the_route_records_the_answer asserts {'from': 3} == {'from': 1}. That file was added by 61c08b1f71 and this branch does not touch it; src/kiro_crew/knowledge/store.py has zero references to crew_log, CrewLog or emit, so nothing here can write the session-log watermark it reads. It passes in isolation and the whole file passes alone (33 passed) behind its own autouse KIROCREW_HOME fixture, so the leak is cross-file: another file in the same xdist worker advances the watermark without emit.reset_caches(). Adding a test file changes whole-file shard composition, so this PR co-scheduled it rather than caused it.

Pattern harvest

Rule candidate: review-prompt

Pattern: a record crossing a store or host boundary carries a column that describes the SENDING side, and the receiving side reads it as a statement about itself. Both blocking findings on the first head of this PR were instances: mtime describes a file on the exporting host and gates hashing on the importing one, and sources.id describes the exporting store's own row and was used to file items in the receiving store. The check is per column, not per record: when a table becomes part of an export format, every column has to be classified as travelling (a statement about content, like a content hash) or sender-local (a statement about one machine's filesystem or one store's ids), and a sender-local column must be re-derived or floored on import, never carried. folder_file_state is the worked example -- content_hash and text_hash travel, mtime and attempts do not.

Second candidate, from the review round after that: an identity column that becomes a dictionary key needs a type gate at the writer, not only a column type. sources.id and sources.uri are TEXT in SQLite and therefore trusted as strings, but a JSON bundle can carry a list there, and the TypeError surfaces as a 500 rather than the endpoint's typed 400.

Any other suggestions on the work

The decision to split, and the options rejected, are recorded on the issue. The short version: half 1's stated root cause is already closed on main (ingest_artifact writes the ownership row inside the pipeline's finalize hop via on_committed), so only residue repair remains, and residue repair is unsafe until imported items arrive owned. Rejected: both halves in one PR, which re-creates the shape that was reverted and puts a deletion sweep beside an import fix; residue repair first, already reverted for this reason; and splitting the remap into its own PR ahead of this one, which cannot work because the state tables are keyed on source_id.

One finding for the follow-up PR, so it does not have to be re-derived: the remaining orphan window is narrower than #2670 describes but not closed. The item chunks, the old group's delete_items_batch, and the state-row write are three separate commits on an autocommit connection, so a hard kill between them still leaves committed items with no row naming them. A cancellation cannot land there any more; a process kill can.

One residual of the same class is deliberately left in place rather than widened into: the same-source check is still all-or-nothing, so a bundle that files one group id under a different source refuses the whole row and leaves the row's other arriving ids owned by nothing. This store's own export_all cannot produce that shape -- it prunes each group to ids filed under the row's own source -- and test_a_row_cannot_own_an_item_filed_under_a_different_source encodes the refusal with its own reasoning, so partially trusting a bundle that contradicts itself about who owns an id is a separate decision from the strand fixed here.

The scoped-export disclosure that Design Review and First Principles both raised is fixed in this PR rather than deferred: shipping rows the importer is guaranteed to drop is not a conservative choice, it is a new per-document disclosure in an artifact whose purpose is to leave the machine.

Refs #2670

@chenmingwei23
chenmingwei23 requested review from a team and CrysisDeu September 24, 2026 18:04
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Sep 24, 2026
@github-actions

github-actions Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Fable 5) — ✅ PASS

Design-level review of 785c72d9534d5f414cd5d91fd5552d01eeb7993f — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

Design-Verdict: PASS

Follow-up sweep for #2670 must stay scoped to agent-owned residue: folder/artifact bundle imports still arrive unowned, so crash-vs-import indistinguishability persists for those tables.

[DESIGN-REVIEWED] 785c72d

@github-actions

github-actions Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Fable 5) — ✅ PASS

Premise-level review of 785c72d9534d5f414cd5d91fd5552d01eeb7993f — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

First-Principles-Verdict: PASS

Verify one premise: no bundle outside this repo hand-builds items naming an undeclared source — that previously-importing shape is now a typed 400 (both in-repo exporters ship sources; verified).

Not justified as shipped

  • Item 7 — rides along: the surrogate/null gates on sources.name, source_type, created_at harden binds whose 500s predate this fix; harm-free, and each names the failure it converts to a typed 400.

What this change ships

Inventory (10 items) — 9 justified

Intent: make importing a .knowledge bundle succeed on a store that already holds its sources, and carry per-document ownership so imported items arrive managed — a FIX (measured FK-rollback repro on main; Refs #2670).

  1. Importing a bundle whose source uri already exists locally now succeeds, items filed under the local source — justified
  2. Export ships the three ownership tables, each group pruned to the items the export carries — justified
  3. Import restores agent-document ownership only; folder and artifact rows deliberately never restored (both owners reap by absence — verified in reconcile_artifacts) — justified
  4. A document a live local row already holds is withheld instead of arriving as an unowned duplicate (on main this case rolled the whole import back) — justified
  5. Import response reports ownership_rows_imported, items_withheld, and a per-reason withheld account — justified
  6. A bundle referencing a source it does not declare is refused as a typed 400 (previously imported under a same-id local source, misfiled) — justified
  7. Malformed bundles (surrogate/non-string ids, null NOT NULL columns, repeated ids, oversize groups) get typed 400s instead of 500s — rides along
  8. Bundle-authored state-row text is redacted inbound and the withheld account redacted in the response — justified
  9. Entities referenced only from withheld rows are dropped and not counted — justified
  10. Bundle-sized IN lists are chunked under a 400-bind ceiling for pre-3.32 sqlite — justified

[FIRST-PRINCIPLES-REVIEWED] 785c72d

@github-actions

github-actions Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

GPT 5.6 Review — ✅ no blocking findings

GPT 5.6 completed its review of 785c72d9534d5f414cd5d91fd5552d01eeb7993f and found no blocking issues.

This comment is updated in place on each push.

Review details

FINDING -- test/test_knowledge_bundle_ownership.py:159 -- "import restores them" contradicts the agent-only restoration behavior -> Fix: state that all three tables export but only agent ownership imports.
[GPT-REVIEWED] 785c72d

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 785c72d9534d5f414cd5d91fd5552d01eeb7993f: <one-sentence reason>

@github-actions

github-actions Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5 Review — ✅ no blocking findings

Reviewed 785c72d9534d5f414cd5d91fd5552d01eeb7993f — this comment is updated in place on each push.

Review details

Nothing blocks.

FINDING — src/kiro_crew/knowledge/store.py:3409 — the document_key_held_locally arm writes "items": str(len(document)), a decimal count, into the same withheld[].items field the two sibling arms fill with ",".join(stranded) / ",".join(absent) id lists (and which test_knowledge_bundle_ownership.py:1015 and :577 pin as ids), so the one reason that actually holds content back is the one whose account cannot say WHICH ids did not arrive → Fix: emit ",".join(sorted(document)) in that arm, or move the count to its own key such as "item_count".

FINDING — src/kiro_crew/knowledge/store.py:722 — the header #: Columns written to a fixed value instead of being carried. sits above _BUNDLE_STATE_REQUIRED_COLS, whose members last_seen/updated_at are both in _BUNDLE_STATE_CARRIED_COLS and are carried verbatim by _import_bundle_state (value = row.get(col), substituted with now only when absent or non-string), and it contradicts the paragraph directly beneath it → Fix: delete that first line.

[OPUS-REVIEWED] 785c72d

Verdict parsed from the review's SHA-scoped output markers for commit 785c72d9534d5f414cd5d91fd5552d01eeb7993f.

False positive or not applicable? A repository writer can comment:
/ai-review override fable 785c72d9534d5f414cd5d91fd5552d01eeb7993f: <one-sentence reason>

@chenmingwei23
chenmingwei23 force-pushed the fix/bundle-ownership-roundtrip-2670 branch from bef7363 to 219bfcf Compare September 24, 2026 18:38
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Sep 24, 2026
@chenmingwei23
chenmingwei23 force-pushed the fix/bundle-ownership-roundtrip-2670 branch 2 times, most recently from cadb9d0 to 25f7f1e Compare September 24, 2026 19:37
@chenmingwei23

chenmingwei23 commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor Author

Attribution for the non-green lanes

None of these come from this diff, which touches the knowledge store, its own test file and one spec file.

Current head 74d3fd6a47. 94 lanes: 77 success, 13 skipped, nothing pending, exactly four red. Both review lanes pass on this head — GPT 5.6 Review and Opus 5 Review each report no blocking findings, and neither published a blocking marker for it. PR Hygiene passes. mergeable is true with no conflict.

All four reds are jobs of one ci.yml run, which is why PR Readiness counts one blocking item rather than four.

Lane Cause Whose
Backend Tests (3.12, 2) test_oneshot_supervisor.py::test_pidfd_fallback_through_ctypes_signals_a_group_member, assert False #14503, bisected to #14229
Frontend Tests (2) src/i18n/style/bnStyle.test.ts:126 counts 9 Bengali-digit violations against a ceiling of 8 #14505
Electron Shell Tests port-vocabulary pins unclaimed by OCCUPANCY_SITES / IDENTITY_SITES on electron source lines 400-402, 422, 736 #14491
Coverage Gate its own annotation: frontend-test=failure -- failing closed dependent on the frontend lane

These are inherited, not local and not flake. The CI run on main itself — run 36337451146, branch=main, head=20ed6a1dc7, conclusion=failure — fails those same four jobs:

gh api repos/kirodotdev/KiroCrew/actions/runs/36337451146/jobs \
  --jq '.jobs[] | select(.conclusion=="failure") | .name'

A caution for anyone else checking this: reading commits/<main sha>/check-runs makes main look clean. On that head the endpoint returns ~955 rows that are almost entirely app lanes (437 Publish readiness signal, 75 Record human judgment, and so on) and the ci.yml job lanes are not among them, so grepping for these four names returns zero — indistinguishable from green. The workflow run's /jobs endpoint is the read that answers it.

Nor is it a shard artefact: Electron Shell Tests carries no shard index at all, and the two genuine test failures are deterministic assertions (a count against a ceiling, an allowlist membership pin), so a re-run reproduces them. #14503 records four of four runs failing on this base while the previous main c203fac29e passed the shard.

Three independent base-side breakages, then, plus one dependent — not one shared cause. Also seen together on #13640, #13727, #13936 and #14095.

Earlier heads of this PR had different reds, all since resolved: two upheld GPT 5.6 Review findings on 19f1c7f1e4 (a shared bundle id reaching a disjoint live ownership row, and the same-row claim exemption's scope), one upheld Opus 5 Review finding on d705a31fa0 (that exemption's scope again, from the opposite side), one unbounded IN list, a PR Hygiene commit-count refusal, and one E2E failure in playwright/member-memory.spec.ts that cleared on re-run. They are listed so a reader scanning this PR's history can match them to the pushes that fixed them rather than to the board above.

@chenmingwei23
chenmingwei23 force-pushed the fix/bundle-ownership-roundtrip-2670 branch from 25f7f1e to dc43317 Compare September 24, 2026 20:38
@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Sep 24, 2026
@chenmingwei23
chenmingwei23 force-pushed the fix/bundle-ownership-roundtrip-2670 branch from dc43317 to 33d3ea9 Compare September 24, 2026 21:37
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 24, 2026
@chenmingwei23
chenmingwei23 force-pushed the fix/bundle-ownership-roundtrip-2670 branch from 33d3ea9 to 832bf79 Compare September 24, 2026 22:39
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Sep 24, 2026
@chenmingwei23
chenmingwei23 force-pushed the fix/bundle-ownership-roundtrip-2670 branch from 832bf79 to 4d0faac Compare September 24, 2026 23:20
@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention labels Sep 24, 2026
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Sep 25, 2026
@chenmingwei23
chenmingwei23 force-pushed the fix/bundle-ownership-roundtrip-2670 branch from cb62692 to f2c00fa Compare September 25, 2026 13:14
@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Sep 25, 2026
@chenmingwei23
chenmingwei23 force-pushed the fix/bundle-ownership-roundtrip-2670 branch from f2c00fa to 017b94d Compare September 25, 2026 13:41
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 25, 2026
@github-actions

github-actions Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Fable 5) — ⏭️ skipped

Revision 785c72d9534d5f414cd5d91fd5552d01eeb7993f touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Advisory — does not block merge.

chenmingwei23 and others added 2 commits September 27, 2026 21:56
export_all ships folder_file_state, artifact_item_state and agent_item_state, and import_bundle resolves every bundle source by uri before rewriting the rows that point at it.
…t do not own it

export_all ships folder_file_state, artifact_item_state and agent_item_state, and import_bundle resolves every bundle source by uri before rewriting the rows that point at it.

A restored ownership row owns the items THIS import inserted, and for a live local row on the same document key the arriving ids join its existing group. The blocking pass already promised this ("its absent ids arrive, to be merged into that row's group by the accepting pass") and the accepting pass never merged, so a newer pruned backup restored before an older complete one left the older bundle's chunk inserted and FTS-indexed with no row naming it: agent_item_state is the one table a bundle restores, nothing reaps it, and remove_document deletes only the ids its row names. The merge takes only ids this import wrote, exempts the row's own group from the claim check without exempting anyone else's, and UPDATEs item_ids alone so an older bundle cannot repoint the local row's hash and name at a revision this store does not hold.

The merge no longer trusts the blocking pass for its own precondition. That pass never blocks an id two bundle rows both claim -- the bundle does not agree who owns it -- so such an id reached the accepting pass with a live local row on its key whose group shares nothing with the bundle's: a different document by the pass's own rule. The merge extended that row's group anyway, and the local document's next delete took the imported chunk with it, with nothing that reaps the row or reports it. The accepting pass now tests the overlap itself and skips a live disjoint row, naming it in the account as ownership_row_key_held_locally.

The claimed-id rule's exemption is keyed on the bundle's own row at the same (table, source, key), which is what makes it this document meeting itself rather than a blanket amnesty -- so it covers every table the bundle states, not only the one whose rows get written. _delete_item_cascade never prunes a group, so a per-chunk delete on a folder- or artifact-backed document leaves the row naming that chunk while the file or slug is still here, and withholding the id loses it for good: FolderWatcher._do_scan step 4 reaps only a row whose path the walk MISSED, and step 5 skips a done row whose mtime and content hash did not change, so nothing re-ingests it. The opposite risk -- a row whose document is gone here and not yet reconciled away -- needs the owning subsystem's view of whether the document still exists, which is not reachable inside the import transaction, so it is named in the code and left to the reap it belongs to.

Every IN list on this path is chunked under _MAX_SQL_PARAMS, the ceiling vector_memory already keeps and for the same reason: sqlite binds 32,766 on the bundled build but only 999 on a host still on a pre-3.32 library. The list lengths are untrusted bundle input -- a bundle names as many sources as it likes, and one state row's group runs to _MAX_ITEM_GROUP_MEMBERS -- so both pass 999 on ordinary input, and the OperationalError lands mid-transaction: the whole import rolls back and the endpoint answers 500 where it should have succeeded. Four sites are covered, the two source-keyed reads and the two group-keyed probes; _items_exist already chunked and now shares the one constant.

A bundle source reference absent from source_id_map is refused as a typed 400 instead of being resolved against this store's own source rows. The declared path already refuses to file a bundle's content under a local row that merely shares an id -- it mints a fresh uuid4 when a bundle uri is absent but its id is held by a different uri -- while the undeclared path resolved the bare id, so the foreign key refused the harmless case (an id that exists nowhere) and admitted the harmful one (an id this store holds under a source the bundle never names).

The import response's withheld account carried bundle-authored text unredacted. Its fields are the ones the handler's inbound loop exempts on purpose, because the store matches them against a PRIMARY KEY and against items.id and needs them byte-exact, and a document key has no length bound. They are redacted after the store has used and stored the real values, so the stored key stays byte-exact.
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.

2 participants