Skip to content

service-knowledge: a backlog reconcile that starts during a bulk import re-embeds and re-writes every record the batch path is already syncing, doubling the embedding requests and writes #38591

Description

@objectstack-fleet

repo:objectstack#1 · zhuangjianguo · session_01QsR2jTsdScTh3o2fSjbxSz

Filing gate: ① (product defect, measured) · Source: fleet (os-dev report on #38529, comment 7256340769, out_of_scope_findings class b; full JSON at /mnt/project-files/card-38529-measure/os-dev-report.json)
Grade: area:ai · domain:server · bug · reach: every bulk import into a record-sourced knowledge source on the default configuration · evidence: measured on origin/main 30141766 against a local Turso store with a real embedder (gateway openai/text-embedding-3-small, 50,000 records, 100,667 passages)
Suggested-grade: p2 (each import pays twice the embedding cost and twice the vector writes of a rebuild)
Related: #38413 (the batch path), #38529 (the measurement), #38577 / PR for #38556 (the cover margin), #38548

维护者速读

  • 出了什么事:批量导入记录时,知识服务除了按批同步,还会在几秒内顺带启动一次"积压对账"。这次对账不认导入前 30 秒内刚发出的同步消息,于是把每条记录又向量化、又写了一遍。
  • 用户看到的:每次导入的向量化请求和写入量都是重建一次的两倍左右,也就是花两倍的钱和时间。5 万条记录实测 985 次请求、99,551 次写入;同样记录重建只要 503 次和 50,012 次。
  • 要做什么:让对账跳过已经在同步路上的记录,或者在导入还在排空时推迟对账,二选一,按实测决定。
  • 要你做的:无。

What is measured

  • Drain on the default configuration: 568.6 s, 985 embedding requests, 99,551 document writes, 0 dead letters, state current.
  • Drain on the batch path only (the reconcile stubbed, since no option turns it off): 805.7 s, 501 requests.
  • Rebuild of the same 50,000 records: 591.4 s, 503 requests, 50,012 writes.
  • Why: considerBacklogReconcile schedules a reconcile next to the syncs within seconds of an import. The reconcile treats a message as covered only when it was published at least RECORD_SYNC_COVER_MARGIN_MS (30 s) before the reconcile started (knowledge-service.ts ~L3511–3524). So every message of the import is uncovered, and the reconcile re-embeds and re-writes each record beside the batch path.

Ask

  1. Stop a reconcile that starts during an import from redoing records whose sync messages are still pending. Fix choices, to be decided by measurement:
  2. Keep the reconcile's purpose: records with no sync message at all are still reconciled.

Acceptance:

Not in scope: the cover margin's value for its own case (#38577); the batch size; a remote libSQL store (not measured).

Dedupe: searched backlog reconcile, cover margin, duplicate embed. Only #38489 (backlog display), #38413 and #38529 matched, and none covers this.

Activity

  1. added
    bug
    priority:p2
    pm:queue
    area:ai
    domain:server
    on Nov 29, 2026
  2. objectstack-fleet commented on Nov 29, 2026

    @objectstack-fleet
    ContributorAuthor

    triage#1 · zhuangjianguo · session_01QsR2jRH2X4frz9bBiZHNk4

    Triage: lands in considerBacklogReconcile / the reconcile's cover check in service-knowledge (knowledge-service.ts) · area:ai · domain:server · Bug · p2 · pm:queue · size M. Rationale: measured on 30141766 with a real embedder: every bulk import into a record-sourced knowledge source pays about twice the embedding requests and vector writes of a rebuild (985 vs 503 requests, 99,551 vs 50,012 writes). A shipped capability slow and costly enough to hurt its use is a Bug; p2 confirmed. Same file family as #38413 and #38556; no open PR holds the reconcile path.

  3. objectstack-fleet commented on Nov 30, 2026

    @objectstack-fleet
    ContributorAuthor

    repo:objectstack#3 · os-steve · session_01ADHkmPDtfMCw4FJfyFfQ7v

    Claim: PM loop round 1
    Session: session_01ADHkmPDtfMCw4FJfyFfQ7v
    Account: os-steve
    Branch: claude/issue-38591-reconcile-skips-pending-sync
    Worktree: objectstack-issue-38591
    Domain: domain:server
    Seat: repo:objectstack#3
    Area: o3-K (area:ai p1/p2, knowledge topic first; zone order o3-area-K.md priority 2, card-pick --order area:ai)
    File surface: packages/services/service-knowledge/src/knowledge-service-record-sync.ts (considerBacklogReconcile and the reconcile's cover check, moved here from knowledge-service.ts by e6b424b), packages/services/service-knowledge/src/knowledge-record-sync-queue.ts (the cover reading, only if fix (a) needs it), a new test file packages/services/service-knowledge/src/__tests__/reconcile-during-import-38591.test.ts, .changeset/38591-*.md. Anything else ⇒ stop and report.
    Container & model: M, mode:subagent, model: opus (dispatch-gates --tier: "Model tier — no path-derived mandate … floor sonnet · default opus · ceiling fable"), effort: high
    Clause-②: no
    Metadata-protocol: none
    Responsibility: service-knowledge's own backlog reconcile in this repo treats every message of a running import as uncovered (cover margin, RECORD_SYNC_COVER_MARGIN_MS) and re-embeds each record beside the batch path | no existing path covers it (#38577 widened the margin for its own case; nothing skips pending messages or defers the reconcile) | every bulk import into a record-sourced knowledge source on the default configuration, today (measured on 3014176: 985 vs 503 embedding requests, 99,551 vs 50,012 writes)
    Thread-read: 7256625683
    Premise: holds (origin/main acf3b33: considerBacklogReconcile at knowledge-service-record-sync.ts:645, called from the batch path at :516; the measurement commit 3014176 already contains #38577, so the margin change does not retire it). The 50,000-record re-measure needs a real embedder; this container has no gateway key, so the dev measures request and write COUNTS with a counting embedder on a local store and reports the real-embedder timing as NOT MEASURED.
    Pre-claim lane: domain:server — packages/services/service-knowledge (services family).
    Pre-claim deps: none named by the card. No open PR touches knowledge-service-record-sync.ts or knowledge-record-sync-queue.ts (PR #38722's list does not); overlap-check.mjs runs before every push.
    Prior rulings read: check-prior-rulings.mjs --card 38591 --paths knowledge-service-record-sync.ts → 376 term hits; ADR-0098 §7, ADR-0058 D4, ADR-0145 D2, ADR-0071 §1, ADR-0077 §1 named by term only, none on the reconcile's cover rule; linked cards #38529 #38413 #38556 #38548 closed, #38577 merged, #38489 open (display only).
    Fold-or-serial: no fold with #38728 (search refusal, other file, other mechanism); parallel, disjoint files.
    Serial constraints cleared: check-handover --inflight --paths=knowledge-service-record-sync.ts,knowledge-record-sync-queue.ts --card=38591: one overlap, #38692 (claim 7270621658, dir-wide packages/services/service-knowledge/src/**); none of its open PRs (#38720 #38721 #38722 #38745) touches these files.

  4. added
    pm:dispatched
    and removed
    pm:queue
    on Nov 30, 2026
  5. objectstack-fleet commented on Nov 30, 2026

    @objectstack-fleet
    ContributorAuthor

    repo:objectstack#3 · os-steve · session_01ADHkmPDtfMCw4FJfyFfQ7v
    os-dev-report

    {
     "issue": 38591,
     "status": "done",
     "branch": "claude/issue-38591-reconcile-skips-pending-sync",
     "pr": "https://github.com/objectstack-ai/objectstack/pull/38767",
     "session": "session_01ADHkmPDtfMCw4FJfyFfQ7v",
     "premise_still_valid": true,
     "premise_evidence": "origin/main acf3b33e: considerBacklogReconcile at knowledge-service-record-sync.ts:645, called from processRecordSyncBatch at :516 via `void this.enqueueReconcile`; coveredByBuild (:480) covers only publishedAt < startedAt - RECORD_SYNC_COVER_MARGIN_MS after a done+purged build; walkObjectSource lists adapter docs once before page 1 and skips only listed unchanged hashes, so during an import it embeds every row while the drain syncs every message. 30141766 IS the #38577 merge commit (margin 30_000 there), so the margin change does not retire the card. Reproduced on the base before the fix: 1,001 requests / 99,976 writes vs the rebuild's 500 / 50,000, 0 covered.",
     "summary": "Fix (b), chosen by measurement: considerBacklogReconcile now defers the walk when the source's estimated backlog is no larger than its rows (a bulk import or update, about one message per record) until the backlog drains (new backlogDrained: the pending count is re-read every RECORD_SYNC_BACKLOG_READ_INTERVAL_MS, and the walk starts when count x source share < 1, bounded by RECORD_SYNC_BACKLOG_RETRY_MAX_MS, and dropped on stop, held, or source gone). The walk then writes only the rows no message reached. A backlog that outnumbers the rows is still walked beside the drain, so the #38413 suite in knowledge-build.test.ts is unchanged and green. (a) was rejected because IQueueService has no read of pending or claimed messages by record (that would be a spec contract change), and the walk lives outside the fence. coveredByBuild and the margin are untouched, and the #38556 cover-margin test is unchanged and green. 50,000-record import drain, counts: before 1,001 req / 99,976 writes, after 501 / 50,000, rebuild 500 / 50,000 (+0.2% / 0%).",
     "count_table": {
      "harness": "real kernel: ObjectQLPlugin + SqlDriver(better-sqlite3 file) + QueueServicePlugin db (defaults) + KnowledgeServicePlugin; counting store (1 upsert = 1 embedding request, 1 doc = 1 write, 100 ms/request); build over the empty table, then ql.insert 50,000 in arrays of 500; harness kept out of the diff",
      "before_acf3b33e": {
       "requests": 1001,
       "texts": 99976,
       "writes": 99976,
       "synced": 50000,
       "covered": 0,
       "reconcile": "beside the drain: 50,000 read, 49,976 written"
      },
      "after_785feded": {
       "requests": 501,
       "texts": 50000,
       "writes": 50000,
       "synced": 50000,
       "covered": 0,
       "reconcile": "after the drain: 50,000 read, 0 written, 50,000 unchanged"
      },
      "rebuild": {
       "requests": 500,
       "texts": 50000,
       "writes": 50000
      },
      "real_embedder_timing": "NOT MEASURED: no gateway key in this container",
      "wall_shared_box": "import 36.5/34.4 s; drain 108.6 s before / 105.5 s after; deferred reconcile ended at 126.8 s; rebuild 52.0/51.8 s"
     },
     "tests": "At 785feded: `pnpm --filter @objectstack/service-knowledge test` gives Test Files 26 passed (26), Tests 840 passed (840). `vitest run src/__tests__/reconcile-during-import-38591.test.ts` gives 4 passed. `pnpm --filter @objectstack/service-knowledge typecheck` exits 0, and `tsc --listFiles` names the new test once in tsconfig.json and once in tsconfig.test.json. Ablation: `node scripts/ablation-replace.mjs` turned `const deferred = estimate <= rows;` into `const deferred = false;` (anchor 1->0, blob 8cdba5dc3e67->8ae94f8819d7; the test imports src directly, so no dist is involved). Result: 4 failed / 4. The card's pin failed with `expected [ 'kb:imp00100', …(5899) ] to deeply equal []`. Restored: blob == HEAD and git diff HEAD is empty.",
     "gates": "Local: build of the dependency closure `pnpm --filter '@objectstack/service-knowledge^...' build` exited 0. `dispatch-gates --commands --repo objectstack-ai/objectstack` at 785feded derived 68 families: 67 exited 0, and check:dual-build-cjs-loads exited 3 (PREREQUISITE NOT MET, whole-repo build), which is NOT MEASURED and left to CI. check-plugin-teardown-shape --self-test first exited 3 because the shallow clone lacked its fixture commit; after `git fetch --depth=1` of 621a4876 it exited 0. check:query-options-erasure (392 s) and check:type-check-debt (234 s) exited 0 once re-run past the per-command timeouts. `--ran` reconciliation: 68 derived, 67 run, 1 NOT-MEASURED, 0 UNRUN. CI check-runs on PR #38767: NOT MEASURED at report time (just opened); left to the seat.",
     "overlap_check": "node scripts/pm/overlap-check.mjs before each push: `claude/issue-38591-reconcile-skips-pending-sync (785feded89) changes 3 file(s); against origin/main (acf3b33e31) and 0 PR head(s)` / `origin/main: merges cleanly` / `VERDICT clean exit 0`",
     "files_changed": [
      ".changeset/38591-reconcile-skips-pending-sync.md",
      "packages/services/service-knowledge/src/knowledge-service-record-sync.ts",
      "packages/services/service-knowledge/src/__tests__/reconcile-during-import-38591.test.ts"
     ],
     "line_budget": "401 changed lines (+377/-24). knowledge-service-record-sync.ts is under 1,000 lines after the change, and knowledge-record-sync-queue.ts is untouched.",
     "deviations": [
      "Two gate loops passed the 10-min foreground cap and the harness moved them to the background (not by request); both finished and their results were read. The remaining gates ran in the foreground.",
      "New pins are in a new file, per the claim, though AGENTS.md asks for knowledge-build.test.ts (the shared harness); this is noted in the PR's Acceptance notes."
     ],
     "mcp_calls": "0",
     "api_writes": "2 — relay pr_create (POST /repos/objectstack-ai/objectstack/pulls, run 46423540509, read-back byte-identical, no assignees, no labels); post-stamped os-dev-report comment on #38591. Plus git push (not REST): the probe and 785feded.",
     "classifier_refusals": [],
     "open_questions": [],
     "security_findings": "none",
     "out_of_scope_findings": [
      "carrier: none · noted, not filed: a source row count cached within RECORD_SYNC_SOURCE_ROWS_TTL_MS from an earlier backlog can send a later import down the walk-beside branch (only after a failed backlog reconcile's 5 min retry). Recorded in the PR's Acceptance notes.",
      "carrier: none · noted, not filed: with (b), an import drains at the batch-only rate (#38529 real provider: 805.7 s vs rebuild 591.4 s, 1.36x, inside #38413's small multiple). The default drain's earlier speed came from paying twice. Recorded in the PR's Acceptance notes."
     ]
    }
  6. added a commit that references this issue on Dec 1, 2026
    95a49ad
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area:aibugdomain:serverpm:dispatchedpriority:p2

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions