Skip to content

feat(imports): make each bulk import one run you can undo whole - #679

Merged
adeelahmad merged 1 commit into
mainfrom
claude/project-thread-xfmkzn
Oct 19, 2026
Merged

adeelahmad merged 1 commit into
mainfrom
claude/project-thread-xfmkzn

Conversation

@adeelahmad

Copy link
Copy Markdown
Owner

Requested by Adeel · project thread

Description

Before: a bulk import (a folder scan, an archive's files, a list of links, a source's chosen files) left its assets mixed in with everything else, so undoing a wrong one meant finding and deleting each asset by hand.

After: each bulk import is one import run, and every asset it makes carries the run's id (import_run). GET /api/v1/import/runs lists recent runs with how many assets each made and how many are left, and POST /api/v1/import/runs/{id}/undo deletes them all through the normal delete. That needs owner rights on each asset (nothing goes when any isn't yours to delete) and is audited per asset and for the run. The toast after a link or source import has Undo, the Import screen lists recent runs with Undo on each, and the assistant has import_runs and undo_import, which always waits for the person's yes. Assets imported before keep no run, and nothing changes for them.

How: import_runs.py records a run and stamps its assets from ingest, convert, links and sources; imports.py adds the two routes; ops_tools.py adds the two assistant tools, with undo_import in ASK_TOOLS.

Two fixes the new tests found:

  • deletion.py and moving.py now use array::complement(field ?? [], …). On a SurrealDB 3.2.4 server, UPDATE chat SET scope.recordings = array::complement(scope.recordings, [$r]) WHERE scope.recordings CONTAINS $r fails with "Argument 1 … found NONE" when any row lacks the field, even though the WHERE excludes it (reproduced with curl against surrealdb/surrealdb:v3.2.4). That means deleting an asset failed in server mode whenever a chat without a recording scope existed.
  • test_the_assistant_manages_people_with_approval raises chat.CONTEXT_TOKENS the way test_a_setup_conversation_sets_the_server_up already does, because two more admin tools pushed its people list past what fits (Admin assistant toolbox leaves almost no room in the default 16k context window #677).

Motivation and Context

Item from the personal feature plan sheet (undo a whole import).

Screenshots (if appropriate):

n/a

Steps to reproduce (if appropriate):

Paste two links on the Import screen, then press Undo in the toast: both assets are deleted, and the run shows as undone under recent imports.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change; ! in the title)

Checklist:

  • The title is a Conventional Commit.
  • My code follows the code style of this project (make hooks checks it on commit).
  • I added or updated tests (tests/api/test_import_runs.py, __tests__/import-runs.test.tsx).
  • My change requires documentation updates, and I have updated docs/ accordingly (docs/api.md, Import runs; docs/assistant.md; docs/processing.md; docs/database.md).
  • Users need more than the title to understand it, so I wrote it under ## Unreleased in CHANGELOG.md. Written as changelog.d/import-runs.md, per build(release): changelog fragments in changelog.d/ instead of one Unreleased section #581.

Done questions (AGENTS.md)

  • Goal: delivers what the user wanted, merged on green CI.
  • Agents: usable through the API, MCP or an assistant tool. Two routes and the import_runs / undo_import tools.
  • Zero setup: no new prerequisite, .env edit or manual step.
  • Fewest clicks and keystrokes. One Undo in the toast, or one per run on the Import screen; no confirm dialog.
  • Configurable: new settings in the web app with defaults; wizard asks only what is required. n/a: no settings.
  • Light: default install still runs on a Raspberry Pi with cloud models.
  • Private and secure: data local and encrypted, passkeys, threat model updated. New row for the routes and tools; runs are seen only by whoever started them, namespace owners and admins.
  • Cost: cheapest path, model calls in the activity ledger, budgets respected. n/a: no model calls.
  • User decides: consequential or new actions wait for the user; defaults unchanged. The assistant's undo always waits for a yes.
  • Upgrades: existing installs upgrade safely (upgrade step for stored-data changes). import_run is a new optional field and a new table; older assets have none (docs/database.md).
  • Honest: sources cited; labelled built, in progress or planned. README built list and docs/requirements.md name test_import_runs.py.
  • Tests, docs and generated files updated (make openapi).
  • Open standards; dependencies keep Lens MIT. n/a: no dependencies.
  • Result reported with evidence; "refine later" items written down.
  • Reuse: existing Lens code and permissive libraries reused, nothing reinvented. Undo goes through the existing delete.

Local CI (ci/local-ci.sh): Next.js, pre-commit and PR title passed. The two FastAPI jobs failed on the two tests above. After the fixes, test_setup_assistant.py and test_import_runs.py pass embedded (14 passed), and test_import_runs.py and test_delete.py pass against a SurrealDB 3.2.4 server (10 passed).


Generated by Claude Code

@adeelahmad adeelahmad self-assigned this Oct 19, 2026
@adeelahmad
adeelahmad force-pushed the claude/project-thread-xfmkzn branch from c097491 to c159244 Compare October 19, 2026 07:53
@adeelahmad
adeelahmad merged commit 1c8e710 into main Oct 19, 2026
12 checks passed
@adeelahmad
adeelahmad deleted the claude/project-thread-xfmkzn branch October 19, 2026 08:08
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