Repository navigation
feat(knowledge): import knowledge base bundles through the API and sim knowledge import - #9327
Conversation
…im knowledge import` - v2 knowledge imports resource (create, part URLs, complete, get, cancel) over a new knowledge_import upload purpose - background runner recreates the base, tags, and documents from an exported bundle; reuses vectors when the embedding model matches and queues re-processing otherwise - knowledge_base_import job table with a stale-import janitor sweep - `sim knowledge import <bundle.simkb.zip>` plus `knowledge imports get/cancel`, and an import guide - shared dispatchBackgroundTask helper for Trigger.dev-or-in-process task dispatch
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
2 issues found across 67 files
Confidence score: 3/5
imports/route.tsexposes cross-tenant authorization failures, letting callers distinguish inaccessible workspace or import scopes. UseconcealImportAuthorizationwhile preserving the intended authorization behavior.upload-session/service.tscan leave a completedknowledge_importupload orphaned if the process fails before durable import creation. Add cleanup or recovery for completed sessions.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="apps/sim/app/api/v2/knowledge/imports/route.ts">
<violation number="1" location="apps/sim/app/api/v2/knowledge/imports/route.ts:16">
P2: This create endpoint exposes cross-tenant authorization failures instead of concealing them. Use `concealImportAuthorization` so callers cannot distinguish an inaccessible workspace/import scope, while retaining the usage-limit rendering.</violation>
</file>
<file name="apps/sim/lib/uploads/upload-session/service.ts">
<violation number="1" location="apps/sim/lib/uploads/upload-session/service.ts:229">
P2: A completed knowledge-import upload can become an orphaned object if the process fails between upload completion and durable import creation. Make cleanup or recovery recognize completed `knowledge_import` sessions without a corresponding import record and delete or resume their source object; otherwise reads remain `uploading` and storage is retained indefinitely.</violation>
</file>
Heads up: you’re close to your flex budget. Increase your flex budget so reviews don’t pause.
Turn on auto-fix | Re-trigger cubic
[High impact] The changes since the previous review appear safe to merge. SummaryAdds knowledge-base bundle imports through the API and
No new actionable issues were found in the changes since the previous review.
|
…and cleanup gaps, and fix CI - read every chunk entry before the base is created, reject reversed offsets, and length-check vectors before decoding - confirm the import is still running before creating the base, and remove it if a cancel wins - record the import inside upload completion, so a refusal or crash cannot strand the bundle; re-read on a concurrent completion - serialize progress writes, keep the source character count, cap rebuilt text, and recheck uploads when issuing part URLs - janitor fails in-process documents a dead worker left processing, and deletes bundles when pruning settled imports - shrink the unused-exports baseline, count the new janitor passes in its test, and fix the integration test's Blob typing
|
@greptile |
|
@cubic-dev-ai review this PR |
@waleedlatif1 I have started the AI code review. It will take a few minutes to complete. |
There was a problem hiding this comment.
All reported issues were addressed across 69 files
Heads up: you’re close to your flex budget. Increase your flex budget so reviews don’t pause.
Turn on auto-fix | Re-trigger cubic
…and remove a base whose tag setup fails - the base takes the import's id and a worker claims the import before working, so a second dispatch exits untouched - a retried completion dispatches again an import no worker has claimed - a worker that finds its import settled before any claim deletes the unused bundle - tag-definition setup that fails removes the still-empty base
|
@greptile |
|
@cubic-dev-ai review this PR |
@waleedlatif1 I have started the AI code review. It will take a few minutes to complete. |
There was a problem hiding this comment.
All reported issues were addressed across 69 files
Heads up: you’re close to your flex budget. Increase your flex budget so reviews don’t pause.
Turn on auto-fix | Re-trigger cubic
…udit each import once, and close review gaps - a dispatch never settles the import itself; a retry or the stale-import janitor does - projected audit entries take an idempotency key, recorded through recordAuditOnce, so a retried completion audits the import exactly once - a cancel that races completion stops the record the completion wrote - refuse empty rebuilt chunk-only documents; knowledge_base_import.user_id references the user
|
@greptile |
|
@cubic-dev-ai review this PR |
@waleedlatif1 I have started the AI code review. It will take a few minutes to complete. |
There was a problem hiding this comment.
All reported issues were addressed across 70 files
Heads up: you’re close to your flex budget. Increase your flex budget so reviews don’t pause.
Turn on auto-fix | Re-trigger cubic
…heck uploads on re-dispatch - knowledge_base_import.user_id is attribution only, so the janitor's cleanup record outlives its importer's account - re-dispatching an unclaimed import repeats the knowledge.upload assertion
|
@greptile |
|
@cubic-dev-ai review this PR |
@waleedlatif1 I have started the AI code review. It will take a few minutes to complete. |
There was a problem hiding this comment.
All reported issues were addressed across 70 files
Heads up: you’re close to your flex budget. Increase your flex budget so reviews don’t pause.
You've manually re-run cubic several times on this PR. Each manual re-review checks the full PR again and counts toward your usage quota. To preserve your usage limits, we recommend letting cubic automatically review new commits.
Turn on auto-fix | Re-trigger cubic
…spatch test - the completion records knowledge_base.import_started; the base exists only once the runner creates it - background-task.test.ts only checked forwarded mock arguments; the delete-async route test and the integration suite exercise the helper's real paths
|
@greptile |
|
@cubic-dev-ai review this PR |
@waleedlatif1 I have started the AI code review. It will take a few minutes to complete. |
There was a problem hiding this comment.
No issues found across 69 files
Confidence score: 5/5
- Automated review surfaced no issues in the provided summaries.
- No files require special attention.
Heads up: you’re close to your flex budget. Increase your flex budget so reviews don’t pause.
You've manually re-run cubic several times on this PR. Each manual re-review checks the full PR again and counts toward your usage quota. To preserve your usage limits, we recommend letting cubic automatically review new commits.
Turn on auto-fix | Re-trigger cubic
Summary
.simkb.zipbundle becomes a new knowledge base with its description, chunking config, tag definitions, tag values, enabled flags, and original filesknowledge/imports(create → part URLs → complete, plus get and cancel) over a newknowledge_importupload purpose; the bundle is uploaded straight to storage like other large uploadspreparedIndexseam inprocessDocumentAsync, so the claim, provenance, index swap, completion, and billing paths stay canonicalknowledge_base_importjob table (migration 0436, additive) with a guardedrunning → completed | failed | canceledstate machine; the stale-execution janitor fails imports whose worker died and deletes their bundleknowledge.createon every step plusknowledge.uploadat create and complete; oneknowledge_base.importedaudit event per import, naming the new basesim knowledge import <bundle.simkb.zip> [--name] [--no-wait],sim knowledge imports get/cancel;tables importnow shares the same pollerdispatchBackgroundTaskhelper (Trigger.dev in the resolved region, or detached in-process) replaces the copy-pasted dispatch blocks in table import/export/backfill/delete and the sandbox image buildType of Change
Testing
bundle-import.integration.tsagainst real Postgres + local storage: real export → import round trip (reused vectors, tags, enabled flags, no embedding calls, upload guard claimed, bundle deleted), model-mismatch routing, bad archive, name conflict, create → complete twice → background run → single audit row, stale-import janitor. Mutation-checked: disabling vector reuse, chunk enabled propagation, the upload-guard claim, or the janitor sweep each turns it redimport-archive.test.ts(refusal modes for untrusted bundles + round trip),background-task.test.ts,knowledge-import.test.ts(CLI), plus existing table import/export/backfill/delete, sandbox image registry, upload-session, storage-sweep, CLI contract, and copilot route inventory testsdb:migrateon a fresh pgvector database; replay is a no-op;check:migrationspassescheck:openapi,check:spec-example-ids,check:permission-group-enforcement,check:api-validation:strict,check:boundaries,check:test-patterns, and the other source audits individually. Full type-check andcheck:auditsrun in CIChecklist
test-auditauthoring gate)