Repository navigation
fix: embed artifact auto-sync chunks at the background class - #47877
winnythedev wants to merge 1 commit into
Conversation
With knowledge.auto_ingest_artifacts on, every artifact save and the start-time reconcile re-embed the artifact's chunks through ingest_artifact, which called ingest_file without embed_priority. Each chunk ran at PRIORITY_NORMAL on the interactive inference pool, and a person's embed (a first-turn recall, a memory_recall query) waited behind it instead of stopping it, so a prompt build could miss its 5 s deadline and fall back to keyword ranking. ingest_artifact, reconcile_artifacts and reconcile_now take an embed_priority keyword (default PRIORITY_NORMAL) and pass it down to ingest_file. The save-event handler and the start-time reconcile pass PRIORITY_BULK, as the folder watcher's scheduled ingest does. The dashboard's manual Sync on the Artifacts source runs the same reconcile for a person who pressed it, so it keeps the normal class. Fixes #47854
UX Review (Opus 5.5) — ⏭️ skippedRevision |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks: the attendance class is now set per call, and only the two unattended artifact paths switch to bulk. Notes
[DESIGN-REVIEWED] 24a030d Description read[DESCRIPTION-READ] ce91dfb36c0d306c5f4c3be095fd904c196cb923936f87abe998d62dc065ebed That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Nothing blocks. The fix works at the cause: the only unattended artifact callers now pass the bulk class, as What this change shipsInventory (4 items) — 4 justifiedIntent: stop artifact auto-ingest saves from holding up a person's memory recall. This is a FIX (#47854; two tests in this PR fail on base).
[FIRST-PRINCIPLES-REVIEWED] 24a030d Description read[DESCRIPTION-READ] d053685dd5a34b807288a062b4ea3038a0ada9c497a2a46d057fc95ddb573167 That sha256 names the PR description this verdict read. Recompute it with |
Opus 5.5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
Problem / Motivation
Goal: An artifact saved with Knowledge auto-ingest on no longer holds up a person's memory recall while its chunks are embedded.
With Settings > Knowledge "Auto-Ingest Artifacts" on (
knowledge.auto_ingest_artifacts, off by default), every save of a markdown or text artifact re-embeds all its chunks at the normal class. While that runs, amemory_recallcall waits behind each chunk (up to about 9 s for a 4,000-character chunk), and a new session's first-turn recall misses its 5 s deadline and falls back to keyword ranking. Each save also takes the interactive inference pool instead of the 1-thread background pool.Cause:
ingest_artifact(src/kiro_crew/knowledge/artifact_ingest.py) calledpipeline.ingest_filewithoutembed_priority, soIngestionPipeline._embed_itemembedded every chunk atPRIORITY_NORMAL. Only aPRIORITY_BULKtext is stopped by a person's embed; a normal one runs to its end.Why it matters
A Bot that rewrites a 50 KB running log every 10 minutes keeps the embedding model busy at the normal class for 2 to 3 minutes of every 10. During that time any person's recall in any chat on the same gateway waits or loses its vector.
Not a goal
knowledge_add_document, and the manual Sync on the Artifacts source keepPRIORITY_NORMAL.What changed (motivation → approach → change)
Symptom: a person's recall waits behind an artifact save. Root cause: the artifact auto-sync embeds at the normal class. The folder watcher's scheduled ingest already passes
PRIORITY_BULK(knowledge/watcher.py), asdocs/system-specs/modules/knowledge.mdsays unattended work must.ingest_artifact,reconcile_artifactsandArtifactKnowledgeSync.reconcile_nowtake anembed_prioritykeyword, defaultPRIORITY_NORMAL, passed down unchanged toingest_file. This is the same call-scoped shapeingest_fileitself uses.PRIORITY_BULK: the save-event handlerArtifactKnowledgeSync._handleand the start-time reconcile_run_reconcile.dashboard/handlers/knowledge_sync.py,_reconcile_artifact_source_task->reconcile_now) is not edited and keeps the normal class. The issue said both callers ofingest_artifactare unattended; that missed the manual Sync, which reaches it throughreconcile_now. A review round caught it, and the keyword exists so that path stays at the normal class.knowledge.md's "Embedding attendance is call-scoped" bullet now names all three paths.Known consequence: a bulk embed never waits for a cold model load. Chunks saved while the model is idle-unloaded rank by keyword until the watcher's self-heal embeds them, the same as folder files today. The spec sentence says so.
Backwards compatibility
Compatible: the new keyword is optional with the old behaviour as its default, and every existing caller outside the two unattended ones is unchanged.
Removes nothing: no path, row, key or public function is removed or renamed; only the scheduling class of two unattended callers changes.
Tests
test/test_knowledge_artifact_sync_embed_priority.pyruns the realArtifactKnowledgeSync,ingest_artifactandIngestionPipelinewith a recording embedder and no model:PRIORITY_BULK;PRIORITY_BULK;reconcile_nowwith no keyword) keepsPRIORITY_NORMAL.Proof: PROVEN test/test_knowledge_artifact_sync_embed_priority.py::test_a_save_event_embeds_at_bulk_priority, test/test_knowledge_artifact_sync_embed_priority.py::test_the_start_time_reconcile_embeds_at_bulk_priority (head 24a030d)
On the base the two bulk tests fail with
assert [1, 1, 1] == [2, 2, 2]; the manual-Sync test passes on both.Local gate on Linux x86_64:
artifact_ingest,ingest_artifact,ArtifactKnowledgeSync,reconcile_artifactsorembed_priority, plustest_wait_discipline_ratchet.pyandtest_flake_pattern_ratchet.py: 752 passed;scripts/local-gate.py --tree-scans: related set 2781 passed; tree scans 24005 passed in one shard and 34336 passed / 15 failed in the other. The 15 are host-only (a child interpreter started with a scrubbed environment cannot loadlibffi.so.6, a coverage-version mismatch, and a missingpytest_splitplugin) and none touches knowledge code;check_black_formatting.py,check_subprocess_encoding.py, isort, flake8, mypy on the changed module,check_comment_history.py,check_brand_name.py,check_agent_sdk_boundary.py,check_file_line_cap.py,./scripts/docs-lint.sh, andsemgrep scan --config semgrep/ --baseline-commit <base> --error: clean.Inputs tested: a saved 3-chunk markdown artifact through the save handler (bulk), the same through the start-time reconcile (bulk), and through the manual Sync (normal). Not tested separately: html and text artifacts (the same
ingest_filecall with another extension), and an artifact saved while the model is unloaded (covered by the existing bulk cold-load rule and the watcher self-heal).Review (multi-model interrogate)
Two rounds with independent reviewers on the full diff, briefed from the CI review lanes. Round one blocked on the first version, which set the bulk class inside
ingest_artifactfor every caller: that also moved the dashboard's manual Sync to the bulk class. Fixed by the call-scoped keyword above. Round two found no blocking issue; one nit (state the cold-load consequence in the spec) was acted on. Dismissed: moving the test intotest_knowledge_rebuild_bulk_pacing.py(the artifact sync needs its own store and sync fixtures; the duplicated attended-ingest case was dropped instead), boundingawait sync._reconcile_taskwith a timeout (the task ends on its own, as in the neighbouring artifact tests), and the start-time pass holding the sync lock longer on the bulk pool (latency only, the pass is budget-capped). One reviewer per round misread the length ofAGENTS.mdand its review was set aside. No security-class findings. A final re-check of the revised hunks ran before the push.Manual verification
N/A — unit coverage on the real ingest path is sufficient for a change that only selects the scheduling class; no live dashboard run was done.
Real-machine verification
Machine: own computer, Linux x86_64.
Before (main a1f0187):
python -m pytest -q -n 0 test/test_knowledge_artifact_sync_embed_priority.py-> 2 failed, 1 passed (assert [1, 1, 1] == [2, 2, 2]).After (head 24a030d): the same command -> 3 passed.
Real-model contention, measured once on the same host while investigating the issue (a throwaway data home holding a copy of the bundled embedding model, 6 threads), with a script that sets the class directly, so it measures the two classes rather than this diff: a 4,000-character chunk inside the model, then a prompt-build-style interactive embed with a 5 s deadline. Chunk at normal: the query got no vector after 5.05 s (the chunk took 9.22 s). Chunk at bulk: the query got its vector in 0.14 s (the chunk took 10.43 s, stopped once and restarted). It was not re-run for this head. No gateway was started.
Cleanup: own computer; nothing left running.
Related Issues
Fixes #47854
Overlap: no open PR touches
artifact_ingest.py. Open PRs #46378, #44606, #47634, #42725 and #31762 edit other parts ofknowledge.md; #46378's hunk (around line 291) sits just above the attendance bullet this PR edits, so whichever lands second may need a one-line rebase. #44606 and #42725 touchingestion.py, which this PR does not.Sibling sweep
Swept:
git grep -n "ingest_file(" src/kiro_crewandgit grep -n "reconcile_now(\|ingest_artifact(" src/kiro_crewSibling: src/kiro_crew/knowledge/watcher.py -- not affected -- scheduled folder ingest already passes PRIORITY_BULK
Sibling: src/kiro_crew/dashboard/handlers/knowledge_sync.py -- not affected -- manual and URL sync are attended and keep the normal class
Sibling: src/kiro_crew/dashboard/handlers/knowledge_ingest.py -- not affected -- uploads are attended and keep the normal class
Sibling: src/kiro_crew/knowledge/agent_source.py -- not affected -- knowledge_add_document is a tool call the agent waits on
Pattern harvest
Not generalizable: the class is chosen by who waits, which only the call site knows; the one unattended ingest left at the default is fixed here, and every other caller was checked in the sibling sweep.
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...); PR Hygiene does not count commitsContribution License Agreement
Contributions are accepted under the project's Apache-2.0 license.