Skip to content

fix(desktop): batch ChatGPT/Claude memory-log import writes (#8760) - #8764

Closed
kodjima33 wants to merge 1 commit into
mainfrom
watchdog/issue-8760-batch-memory-log-import
Closed

kodjima33 wants to merge 1 commit into
mainfrom
watchdog/issue-8760-batch-memory-log-import

Conversation

@kodjima33

@kodjima33 kodjima33 commented Jul 1, 2026 •

Copy link
Copy Markdown
Collaborator

Bug (#8760)

ChatGPT/Claude onboarding memory imports could fail partway through after a user pastes an export. The UI reports memories couldn't be created, but the root cause is the write phase: OnboardingMemoryLogImportService looped APIClient.createMemory once per extracted memory (one POST /v3/memories each).

On an import burst this:

  • trips the backend memories:create limiter → bursts of 429s (issue shows 344/435 requests 429'd in one burst), and
  • causes Firestore cross-transaction contention → 503s (Aborted due to cross-transaction contention).

Root cause

Fan-out of N individual POST /v3/memories writes from the import path, instead of using the existing batch endpoint.

Fix

Convert the save loop to chunk the extracted memory strings through APIClient.createMemoriesBatch (POST /v3/memories/batch), chunked by APIClient.memoriesBatchMaxSize. One batch request = one Firestore write + one embeddings call + one Pinecone upsert on the server, regardless of size.

This mirrors the already-accepted local-file import path in OnboardingPagedIntroCoordinator.importLocalFileMemories. Metadata preserved: content/visibility/category/tags/headline (the chatgpt/claude/memory_log source info is already carried in tags; the batch model has no source field, same as the reference path — not a silent drop, documented in a code comment).

Addresses acceptance criterion #1 of the issue (import creates memories through /v3/memories/batch, not N individual requests). The broader Apple Notes / Gmail / Calendar audit, UX error-differentiation, and Pinecone null metadata items in the issue are intentionally left out of this scoped fix.

Testing

  • xcrun swift build -c debug --package-path Desktop → Build complete (only pre-existing warnings).

🤖 automated by hourly watchdog; opened for review, not merged.

Review in cubic

The ChatGPT/Claude onboarding memory import looped one POST /v3/memories
per extracted memory. On import bursts this tripped the backend
memories:create rate limiter (429s) and caused Firestore cross-transaction
contention (503s), so imports failed partway through.

Convert the save loop to chunk through POST /v3/memories/batch via
APIClient.createMemoriesBatch, mirroring the accepted local-file import
path in OnboardingPagedIntroCoordinator. One batch = one Firestore write +
one embeddings call + one Pinecone upsert regardless of size.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 2 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Re-trigger cubic

@Git-on-my-level

Copy link
Copy Markdown
Member

Verified the batched-write conversion against the existing APIs and reference path — this looks solid.

What I checked:

  • APIClient.createMemoriesBatch and memoriesBatchMaxSize (= 100) exist in APIClient.swift, matching MEMORIES_BATCH_MAX on the backend. The chunk loop respects the cap.
  • The reference path OnboardingPagedIntroCoordinator.importLocalFileMemories uses the identical chunk→MemoryBatchItem→createMemoriesBatch pattern, so this brings the two import flows into consistency.
  • The source: source.memorySource field from the old createMemory call is genuinely absent from MemoryBatchItem (it has content/visibility/category/tags/headline only). The code comment documents this correctly — provenance is preserved via source.tags (["chatgpt","import","memory_log"] / ["claude","import","memory_log"]), so no silent metadata drop. Same tradeoff the local-file path already makes.
  • Per-memory error handling is preserved (log + continue to next chunk), and memoriesSaved now sums response.createdCount rather than incrementing optimistically — slightly more accurate.
  • Changelog format matches the existing unreleased/*.json convention.
  • Checks green (Lint & Format, cubic reviewer).

Scope is appropriately tight for acceptance criterion #1 of #8760; the broader audit/UX items are correctly excluded.

Not approving formally since this is a sequenced fix touching the memory write path — leaving for a human maintainer to give the final merge call. Thanks @kodjima33 for the clean, well-commented fix.

🤖 Automated review by Omi PR maintainer monitor (glm-5.2). Actions taken: comment only, no approve/merge/label changes.

Git-on-my-level added a commit that referenced this pull request Jul 5, 2026
…#8975)

## What

Users can start (`POST /v1/import/limitless`), list (`GET
/v1/import/jobs`), and check the status of an import job, but there was
no way to cancel a stuck or running import or remove a finished/failed
one, so old jobs pile up in the list with no recourse. This adds the two
missing lifecycle verbs. It sits in the actively-built
ChatGPT/Claude/Limitless memory-bank import area (#4862, #8764), and it
wires up the `delete_import_job` db helper that already shipped but was
never called by any router.

Purely additive: no existing route or behavior changes.

## Changes

- `models/import_job.py` — add a `cancelled` status to
`ImportJobStatus`.
- `routers/imports.py`
- `POST /v1/import/jobs/{job_id}/cancel` — cancels a `pending` or
`processing` job (sets `cancelled` + an error note); 409 if the job is
already terminal.
- `DELETE /v1/import/jobs/{job_id}` — deletes a terminal job
(`completed`/`failed`/`cancelled`); 409 while it is still in progress
(cancel first).
- Both mirror the existing `get_import_job_status` ownership checks (404
unknown, 403 wrong owner). The two endpoints form a clean state machine
(cancel for in-progress, delete for terminal), so the delete path never
races the background worker.
- `utils/imports/limitless.py` — the worker re-reads the job right
before its final status write and bails if it was cancelled, so a
mid-run cancel is not overwritten by `completed`/`failed`.

## Tests

`tests/routers/test_imports.py` (14 cases): cancel of pending/processing
sets `cancelled` and calls `update_import_job`; cancel of a terminal job
is 409; delete of completed/failed/cancelled calls `delete_import_job`;
delete of an in-progress job is 409; and both 404 on a missing job and
403 on a wrong-owner job. The module is imported normally and the db
helpers are patched (no `sys.modules` mutation, no network).


<!-- This is an auto-generated description by cubic. -->
<a
href="https://cubic.dev/pr/BasedHardware/omi/pull/8975?utm_source=github"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img
alt="Review in cubic"
src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a>
<!-- End of auto-generated description by cubic. -->
@kodjima33

Copy link
Copy Markdown
Collaborator Author

Closing — opened by an automated bot and left unreviewed. The bot policy has changed: it now tests and merges fixes directly (or reports them), and no longer leaves open PRs for review. If this fix is still wanted, reopen and it'll be landed properly (tested → merged). 🤖

@kodjima33 kodjima33 closed this Jul 22, 2026
@kodjima33
kodjima33 deleted the watchdog/issue-8760-batch-memory-log-import branch July 22, 2026 19:08
@github-actions

Copy link
Copy Markdown
Contributor

Hey @kodjima33 👋

Thank you so much for taking the time to contribute to Omi! We truly appreciate you putting in the effort to submit this pull request.

After careful review, we've decided not to merge this particular PR. Please don't take this personally — we genuinely try to merge as many contributions as possible, but sometimes we have to make tough calls based on:

  • Project standards — Ensuring consistency across the codebase
  • User needs — Making sure changes align with what our users need
  • Code best practices — Maintaining code quality and maintainability
  • Project direction — Keeping aligned with our product principles and locked invariants

Before your next PR, please skim:

  • PRODUCT.md — product north star
  • Product invariants — locked rules (shared chat, memory tiers, agent control plane, integrations, brand)

If this was declined for direction or taste, maintainers should cite an invariant ID or open a proposed one — ask if that citation is missing.

Your contribution is still valuable to us, and we'd love to see you contribute again in the future! If you'd like feedback on how to improve this PR or want to discuss alternative approaches, please don't hesitate to reach out.

Thank you for being part of the Omi community!

@undivisible undivisible added the AI label Aug 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants