Skip to content

fix(import): track restored image references - #1782

Draft
DimitriChrysafis wants to merge 3 commits into
rohitg00:mainfrom
DimitriChrysafis:fix/import-image-refs
Draft

DimitriChrysafis wants to merge 3 commits into
rohitg00:mainfrom
DimitriChrysafis:fix/import-image-refs

Conversation

@DimitriChrysafis

Copy link
Copy Markdown
Contributor

Import restores image-bearing observations and memories without restoring their image reference counts. With fresh state and retained image files, quota cleanup sees those files as unreferenced and can delete them while restored records still point to them.

Register added image references before writing each owner, then release references removed by a successful overwrite. Skipped records leave counts alone. On a failed write, undo the added counts without deleting the retained image files.

Replace imports need one extra step: temporarily pin incoming images before removing old owners. Otherwise replacing a record with one that uses the same image can delete that image between the delete and insert. Pins are released even when import fails.

Memory imports now run under the existing memory mutation lock. Duplicate owner IDs within an import batch are serialized so their reference updates cannot race.

Validation

Adds 14 tests covering capture/export/restore followed by quota cleanup, both merge and replace, shared images, memory owners, repeated imports, skip, same-image replacement, failed reads/writes/deletes, and cleanup during an owner write.

Full suite: 4,945 passed, 7 skipped. Build, skill generation/checks, and docs sync/checks pass. Live integration tests are excluded.

npm test -- test/import-image-refs.test.ts test/export-import.test.ts test/image-ref-release.test.ts

Import remains nontransactional. This change accounts for imported owners; it does not globally rebuild counters already corrupted by an earlier import.

Signed-off-by: dimitri <dimitri.chrysafis@gmail.com>
@vercel

vercel Bot commented Nov 13, 2026

Copy link
Copy Markdown

@DimitriChrysafis is attempting to deploy a commit to the rohitg00's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Signed-off-by: dimitri <dimitri.chrysafis@gmail.com>
Signed-off-by: dimitri <dimitri.chrysafis@gmail.com>

This branch has not been deployed

No deployments
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