Skip to content

fix: embed artifact auto-sync chunks at the background class - #47877

Open
winnythedev wants to merge 1 commit into
mainfrom
fix/47854-artifact-sync-bulk-embed
Open

winnythedev wants to merge 1 commit into
mainfrom
fix/47854-artifact-sync-bulk-embed

Conversation

@winnythedev

Copy link
Copy Markdown
Contributor

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, a memory_recall call 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) called pipeline.ingest_file without embed_priority, so IngestionPipeline._embed_item embedded every chunk at PRIORITY_NORMAL. Only a PRIORITY_BULK text 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

  • Changing the class of any attended ingest: dashboard folder scans, uploads, URL sync, knowledge_add_document, and the manual Sync on the Artifacts source keep PRIORITY_NORMAL.
  • Making a bulk embed wait for a cold model load (the shared embedder's bulk rule).
  • Changing bulk pacing or the thread pools.

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), as docs/system-specs/modules/knowledge.md says unattended work must.

  • ingest_artifact, reconcile_artifacts and ArtifactKnowledgeSync.reconcile_now take an embed_priority keyword, default PRIORITY_NORMAL, passed down unchanged to ingest_file. This is the same call-scoped shape ingest_file itself uses.
  • Only the two unattended callers pass PRIORITY_BULK: the save-event handler ArtifactKnowledgeSync._handle and the start-time reconcile _run_reconcile.
  • The dashboard's manual Sync on the Artifacts source (dashboard/handlers/knowledge_sync.py, _reconcile_artifact_source_task -> reconcile_now) is not edited and keeps the normal class. The issue said both callers of ingest_artifact are unattended; that missed the manual Sync, which reaches it through reconcile_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.py runs the real ArtifactKnowledgeSync, ingest_artifact and IngestionPipeline with a recording embedder and no model:

  • a save event embeds each chunk at PRIORITY_BULK;
  • the start-time reconcile embeds each chunk at PRIORITY_BULK;
  • the manual Sync (reconcile_now with no keyword) keeps PRIORITY_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:

  • the 20 test files naming artifact_ingest, ingest_artifact, ArtifactKnowledgeSync, reconcile_artifacts or embed_priority, plus test_wait_discipline_ratchet.py and test_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 load libffi.so.6, a coverage-version mismatch, and a missing pytest_split plugin) and none touches knowledge code;
  • black (touched files), 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, and semgrep 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_file call 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_artifact for 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 into test_knowledge_rebuild_bulk_pacing.py (the artifact sync needs its own store and sync fixtures; the duplicated attended-ingest case was dropped instead), bounding await sync._reconcile_task with 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 of AGENTS.md and 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 of knowledge.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 touch ingestion.py, which this PR does not.

Sibling sweep

Swept: git grep -n "ingest_file(" src/kiro_crew and git grep -n "reconcile_now(\|ingest_artifact(" src/kiro_crew
Sibling: 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

  • A Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...); PR Hygiene does not count commits
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

Contribution License Agreement

Contributions are accepted under the project's Apache-2.0 license.

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
@winnythedev
winnythedev requested review from a team and KiroCrewCaptain as code owners December 5, 2026 18:42
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Dec 5, 2026
@github-actions

github-actions Bot commented Dec 5, 2026

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision 24a030dc65d3bf3f7ddf5a8490da6b86fb52849d touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Does not block merge.

@github-actions

github-actions Bot commented Dec 5, 2026

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of 24a030dc65d3bf3f7ddf5a8490da6b86fb52849d — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

Nothing blocks: the attendance class is now set per call, and only the two unattended artifact paths switch to bulk.

Notes

  • After a cold-load skip, the chunks only get vectors once the watcher's store-wide self-heal runs (watcher.py:634). If no folder watcher runs on a gateway, auto-ingested artifacts stay keyword-only until a rebuild. Check that the watcher's sweep runs even when no folder source is configured.

[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 .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Dec 5, 2026

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of 24a030dc65d3bf3f7ddf5a8490da6b86fb52849d — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

First-Principles-Verdict: PASS

Nothing blocks. The fix works at the cause: the only unattended artifact callers now pass the bulk class, as watcher.py already does. The attended manual Sync keeps the normal class.

What this change ships

Inventory (4 items) — 4 justified

Intent: 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).

  1. When an artifact is saved with auto-ingest on, its chunks are embedded in the background class, so a person's recall interrupts them — justified
  2. The start-time artifact reconcile also embeds in the background class — justified
  3. The manual Sync on the Artifacts source still embeds in the normal class. It is the only caller that passes no keyword (knowledge_sync.py:643), so it keeps the default — justified
  4. The "Embedding attendance is call-scoped" bullet in knowledge.md now names all three paths and the cold-load consequence — justified

[FIRST-PRINCIPLES-REVIEWED] 24a030d

Description read

[DESCRIPTION-READ] d053685dd5a34b807288a062b4ea3038a0ada9c497a2a46d057fc95ddb573167

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@github-actions

github-actions Bot commented Dec 5, 2026

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed 24a030dc65d3bf3f7ddf5a8490da6b86fb52849d — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 24a030d

Verdict parsed from the review's SHA-scoped output markers for commit 24a030dc65d3bf3f7ddf5a8490da6b86fb52849d.

False positive or not applicable? A repository writer can comment:
/ai-review override fable 24a030dc65d3bf3f7ddf5a8490da6b86fb52849d false-positive: <reason, 20 to 500 characters>

@github-actions

github-actions Bot commented Dec 5, 2026

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of 24a030dc65d3bf3f7ddf5a8490da6b86fb52849d and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 24a030d

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 24a030dc65d3bf3f7ddf5a8490da6b86fb52849d false-positive: <reason, 20 to 500 characters>

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

readiness: checking Automated validation is still running

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Artifact auto-sync embeds at the normal class, so memory recall waits up to about 9 s behind each chunk of a saved artifact

1 participant