Skip to content

service-knowledge: a bulk import syncs one record per queue message, read, embedded and written alone, so the index trails the data for hours #38413

Todo

Description

@os-project-manager

maintainer · os-project-manager · session_01FEkQ5oW6SeQkzCccNxEc83

Filing gate: ③ maintainer-directed (topic child). Source: topic #37000 (phase four, operability). Key words (maintainer, 2026-11-29, this session): 「相关任务都加入知识专题」; on scope, earlier in the same session: 「哪些是平台的通用功能值得修改的」.
Grading: area:ai · Bug (a shipped feature slow enough to hurt its use) · Impeded (workaround: an operator rebuild of the source) · reach: administrators and builders, on every import or bulk update of an indexed object · evidence: measured once on 19.0.0-next.2 (below); mechanism read from the code on main 3511432.

维护者速读

  • 问题:往已建索引的对象里批量导入数据后,检索要很久才能搜到新内容:每条记录单独排一条队列消息,单独读、单独算向量、单独写。评测里导入六万多条后只能改为手动整体重建(重建只要九分半钟)。
  • 做什么:同一个知识源的同步消息成批处理(一次读一批、一次算一批向量、一次写入);积压超过阈值时自动改走对账或重建,而不是一条条追。
  • 谁受益:所有会批量导入或批量更新的应用(数据迁移、定期同步、批量改字段),不限制度库。
  • 不做会怎样:导入后数小时内检索结果是旧的,界面上没有任何提示;管理员得知道要手动重建。

What happens

Record-change sync runs through the queue (#37735). Per record:

  • one message per record per source: packages/services/service-knowledge/src/knowledge-record-sync-queue.ts:5-33 (identifiers only, by design: the worker re-reads the row);
  • the database queue claims batchSize 10 messages per tick on a 1 s poll (packages/services/service-queue/src/db-queue-adapter.ts:276-279) and dispatches the claimed rows one after another (pollOnce, lines 567-580);
  • each message re-reads its row, builds one document, embeds it and upserts it alone (packages/services/service-knowledge/src/knowledge-service.ts, syncRecord at line 3426 and writeSynced at line 3493; the subscription is knowledge-service-plugin.ts:877).

The embedder already batches inputs per provider limit (#36995) and a complete build already pages (#36992); the event path uses neither.

Measured

BrightRule app on 19.0.0-next.2, libSQL store, a remote embedding endpoint: importing 67,379 clause records left the index so far behind that the evaluation abandoned the incremental path and triggered a full rebuild, which took 9.5 minutes for the same records. The incremental drain rate was not timed to completion; at the claim ceiling alone (10 messages per 1 s tick, before any read or embedding time) 67,379 messages need at least 112 minutes. One deployment, one run.

Ask

  1. The worker drains the queue per source in batches: claim N messages of one source, read the rows in one query, split, embed in the embedder's batches, upsert in one adapter call. Per-document ordering (serializeRecordSync) and the identifiers-only message stay. A failed batch falls back to per-message handling so one bad record dead-letters alone, as today.
  2. Above a backlog threshold for a source, the worker stops chasing messages and schedules one reconcile (or rebuild) of that source, then drops the messages that reconcile covers. The threshold and the choice between reconcile and rebuild are the dev's proposal, with numbers.
  3. The sync state record (service-knowledge: each source's sync state is one durable record, the same on every node — last build, pending and failed syncs — listed in Setup, and the reconcile clears the failures it repaired #37736) shows the backlog while it drains, so "search is behind" is visible to an administrator.

Whether point 1 needs a batch-consume shape on the queue contract (IQueueService.subscribe hands one message at a time) or is done inside the knowledge worker is the first thing to settle; if it changes the contract, report the fork before coding.

Acceptance

  • A test that publishes 1,000 record syncs for one source observes a bounded number of embedder calls and adapter writes (batches, not 1,000 of each), and the index ends equal to a rebuild's.
  • A measured drain of at least 50,000 records on a real store and embedder, before and after, in the report; the after figure is within a small multiple of the rebuild time for the same records.
  • A poisoned record in a batch dead-letters alone; its neighbours are indexed.
  • Deletes and where-excluded records in a batch leave the index as the per-message path does.

Reader

repo:objectstack#5 (the seat that took over #37000's follow-on work on the maintainer's word of 2026-11-28, recorded on #37000), after triage's first touch for domain:* and queue state.
Related, not children: #37735 (sync through the queue, closed), #37736 (durable sync state, closed), #36995 (embedder batches, closed), #36992 (paged rebuild, closed), #38346 (knowledge splitting and retrieval topic), objectstack-ai/brightrule#88 (the evaluation tooling).
Dedupe (open and closed): knowledge-record-sync 189 (#37735, #37736, #37954, #36991 closed; none open on throughput) · knowledge bulk import sync slow 9 (none on this).

Activity

  1. added
    priority:p2
    area:ai
    on Nov 29, 2026
  2. objectstack-fleet commented on Nov 29, 2026

    @objectstack-fleet
    Contributor

    triage#1 · sunhaolin · session_017xRBcSxvUE3fDrox79CL9t

    Triage: lands in packages/services/service-knowledge/src/knowledge-service.ts (syncRecord, writeSynced), knowledge-record-sync-queue.ts and the plugin's subscription · area:ai · domain:server · Bug · p2 · pm:queue · size M. Rationale: a bulk import syncs one record per queue message (a batch of 10 on a 1 s poll, one read, embed and upsert each). That is a shipped feature slow enough to hurt its use, which is a Bug by North Star rule 2. An operator rebuild is the workaround, so Impeded × administrators/builders ⇒ p2 (fleet grade). A child of topic #37000 (now seat 5's). ⛔ A change to IQueueService (packages/spec/src/contracts/queue-service.ts) is a contract fork: report it, do not build it. Ask 3 (a backlog field in Setup) splits off as a Feature if it adds a stored field.

    Recorded 2026-11-29T00:49Z.

  3. added
    domain:server
    pm:queue
    on Nov 29, 2026
  4. objectstack-fleet commented on Nov 29, 2026

    @objectstack-fleet
    Contributor

    repo:objectstack#5 · os-project-manager · session_01FEkQ5mC8eA4qtKSweeF7wd
    Claim: PM loop round 1 · 2026-11-29T02:09Z
    Session: session_01FEkQ5mC8eA4qtKSweeF7wd
    Thread session: session_01FEkQ5mC8eA4qtKSweeF7wd
    Account: os-project-manager
    Branch: claude/project-thread-caiyo5
    Worktree: objectstack-issue-38413
    Domain: domain:server
    Seat: repo:objectstack#5
    Area: o5-ai37000
    File surface: packages/services/service-knowledge/src/knowledge-service.ts (the syncRecord / writeSynced region), packages/services/service-knowledge/src/knowledge-record-sync-queue.ts, packages/services/service-knowledge/src/knowledge-service-plugin.ts (the record-sync queue subscription only), new batch-worker module(s) and new test files named for this card in packages/services/service-knowledge/src/, packages/services/service-queue/src/db-queue-adapter.ts (+ a new test file) only for an implementation change that leaves IQueueService unchanged, packages/services/service-knowledge/src/knowledge-sync-state.ts for ask 3 only after #38418 merges and only if no stored field is added, one changeset .changeset/38413-knowledge-batch-sync.md (stop on breach; explain in the report). Not in it: packages/spec/src/contracts/queue-service.ts and packages/spec/src/contracts/knowledge-adapter.ts — a needed change there is a fork reported before coding (triage 7248383369).
    Container & model: M, mode:thread (this card thread dispatches one os-dev subagent in its own container), model: default (dispatch-gates --tier at da184da, "Model tier — no path-derived mandate"; a throughput redesign with a queue-contract fork question carries design judgement, so not floor), effort: high (M, two packages, fork question first)
    Clause-②: no
    Metadata-protocol: none
    Responsibility: @objectstack/service-knowledge (objectstack): the record-sync worker reads, embeds and writes one record per queue message, and @objectstack/service-queue's database adapter dispatches the claimed rows one after another | an operator rebuild of the source (reindexSource, paged since #36992) is the only path that batches; none on the event path | administrators and builders on every import or bulk update of an indexed object; measured once on 19.0.0-next.2 (BrightRule, 67,379 records, card body)
    Thread-read: 7248383369
    Premise: holds at da184da — batchSize ?? 10 and pollIntervalMs ?? 1000 at db-queue-adapter.ts:276-279; pollOnce awaits this.dispatch(row) per claimed row (:567-575); syncRecord at knowledge-service.ts:3426, writeSynced at :3493; the subscription queue.subscribe(KNOWLEDGE_RECORD_SYNC_QUEUE, …) at knowledge-service-plugin.ts:877; IQueueService.subscribe(queue, handler) hands one message per call (packages/spec/src/contracts/queue-service.ts:110); IKnowledgeAdapter.upsert(docs: KnowledgeDocument[], ctx) already takes many documents (knowledge-adapter.ts:327)
    Serial constraints cleared: check-handover --inflight at da184dac: OVERLAP verdict on the DIR/** surface, 5 claims, each handled. (1) #38418 (p1, repo:objectstack#1, knowledge-sync-state.ts): ask 3's edits to that file queue behind its merge, main merged in first. (2) #38419 (repo:objectstack#1, knowledge-service.ts save-time admission): another hunk; overlap-check before every push, queue only on a real merge-tree conflict. (3) #38369 (this area's card thread, knowledge-service.ts and knowledge-service-plugin.ts, held-not-served gating): overlap-check before every push; a real merge-tree conflict queues this PR behind it; the batch path keeps that card's gate (a not-enabled service syncs nothing). (4)(5) #38351 and #38377 (split/**): not in this surface. Not folded: no sibling card shares this mechanism.
    Pre-claim lane: packages/services/service-knowledge, packages/services/service-queue ⇒ domain:server (file ownership only); in lane.
    Pre-claim deps: none named by the card; #37735, #37736, #36995, #36992 closed.
    Prior rulings read: check-prior-rulings at da184da: 0 ruling comments on the card; 7 ruling-hit lines in the tree, the ones on this surface bind: knowledge-record-sync-queue.ts:20 "One record-sync message: identifiers only. ⛔ Never a field value" (kept, as the card says); knowledge-sync-state.ts:37 "build_message and last_error are the platform's own sentences" (ask 3). ADR-0161 K7 "an index never mixes two [generations], on a write or on a search" (a batch write carries one fingerprint); K8 "This record adds no member" (no adapter member added; upsert already batches); ruling 7248214179 (2A/3A: a not-enabled service builds, syncs and searches nothing). Triage 7248383369: "A change to IQueueService … is a contract fork: report it, do not build it" and "Ask 3 … splits off as a Feature if it adds a stored field".

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

    @objectstack-fleet
    Contributor

    repo:objectstack#5 · os-project-manager · session_01FEkQ5mC8eA4qtKSweeF7wd
    os-dev-report

    {
      "issue": 38413,
      "status": "needs_decision",
      "branch": "claude/project-thread-caiyo5",
      "pr": null,
      "session": "session_01FEkQ5mC8eA4qtKSweeF7wd",
      "premise_still_valid": true,
      "summary": "Point 1 settled first, as the card and dispatch order say, and it lands on the queue contract: the database queue hands the knowledge worker one message at a time AND paces claims at batchSize per poll interval for every queue, so neither a coalescer inside the knowledge worker (H1, measured: batches of 1) nor any handler speed-up can drain 50,000 messages faster than about 83 minutes (measured ceiling: 40 messages in 3.05 s, an instant handler, defaults). Getting more than one message per call, or a faster claim, for the record-sync queue alone needs either an opt-in batch-consume member on IQueueService (contract fork, triage 7248383369) or an implementation-only change in DbQueueAdapter that alters concurrency and pacing for EVERY queue consumer (the email-send worker included). Nothing was built, committed or pushed; the fork and four-axis analysis are in open_questions. H2 enumerated (record sync runs only on a queue with listFailed: DbQueueAdapter in this repo; MemoryQueueAdapter and the kernel fallback queue never carry it); H3 holds (adapter.upsert embeds a whole batch through the embedder's provider batching; the reconcile is the existing complete-build walk). Not waiting on the decision: the knowledge-side batch writer (one re-read under where AND id in a set, one split, one upsert, one delete for unmatched ids, per-message fallback) is common to options A, B and D, but it stays dormant on DbQueueAdapter until the answer, so it was not started.",
      "tests": "No code change, so no package test run. Measurements at worktree base da184dac (objectstack), on service-queue's own fake engine, in a scratch probe file run with `pnpm exec vitest run --maxWorkers=2 src/probe-38413.test.ts` and deleted afterwards (Test Files 1 passed, Tests 2 passed): (1) H1 — 30 published, pollOnce claimed and dispatched 10, handler in-flight maximum 1, a setImmediate coalescer flushed groups [1,1,1,1,1,1,1,1,1,1]. Reason in code: DbQueueAdapter.pollOnce awaits this.dispatch(row) per claimed row (db-queue-adapter.ts:567-578). (2) Pace — 200 published, default options (pollIntervalMs 1000, batchSize 10), instant handler: 40 dispatched in 3,051 ms. Reason in code: DispatchLoop (packages/core/src/dispatch-loop.ts:313-321) waits intervalMs from the START of a tick that claimed work, so the claim ceiling is batchSize per interval whatever the handler does: 50,000 messages = 83 min, 67,379 = 112 min (the card's figure), even for messages a reconcile has made no-ops. Acceptance measurement (50,000 records on a real store and embedder) NOT MEASURED: reason, nothing was built (needs_decision).",
      "gates": "No diff, so no derived gate family applies and dispatch-gates.mjs --commands was not run; dependency closure built once for the probe under the lock: os-verify-lock.sh -c \"pnpm --filter '@objectstack/service-knowledge^...' --filter '@objectstack/service-queue^...' --filter '@objectstack/objectql' build --concurrency=2\" gave VERDICT command-exit 0. No PR, so no check-runs to cite.",
      "dogfood_battery": "n/a — no PR, no `!` in a title and no (narrowing) arm",
      "mcp_calls": "0",
      "api_writes": "1 — this report comment on #38413 via scripts/pm/post-stamped.mjs (POST /repos/objectstack-ai/objectstack/issues/38413/comments through the fleet relay). Reads: 2 single-card REST GETs (issue 38413 and its comments).",
      "open_questions": [
        {
          "question": "How does record-sync batching reach the knowledge worker, given DbQueueAdapter hands claimed rows one at a time and claims at most batchSize (10) per poll interval (1 s) for every queue?",
          "options": [
            "A — Contract widening (fork): an optional batch-consume member on IQueueService (for example subscribeBatch(queue, handler, { maxBatch }), the handler takes QueueMessage[] and answers one outcome per message). DbQueueAdapter implements it: claims up to maxBatch rows of that queue per tick, ticks again at once while a claim comes back full, settles each row by its own outcome (complete, retry or dead letter). The knowledge worker uses it when the composed queue has it and keeps per-message subscribe otherwise (correct on every adapter, H2). Ask 2 then drops covered messages in batches. Cost: packages/spec/src/contracts/queue-service.ts edit (Clause-2 yes (widening), api-surface regeneration, contract-tier L2 review), DbQueueAdapter + tests, knowledge batch path + tests; size M-L, about 2-3 days. Only opted-in subscribers change; the email-send worker is untouched.",
            "B — Implementation-only in DbQueueAdapter (no contract edit): dispatch the claimed rows of a queue concurrently and tick again at once after a full claim, for every queue; the knowledge worker coalesces, per source, the handlers that arrive in the same macrotask. Cost: size M. It changes every database-queue consumer: email-send gets up to batchSize concurrent sends and an unpaced drain under a backlog (a provider rate limit sees bursts, 429s, retries, then dead letters); batches are capped by the global db.batchSize (default 10 documents per embed call, against the rebuild's 100-row pages), so reaching the 50,000-record acceptance needs an operator to raise db.batchSize for all queues; and knowledge throughput then depends on an adapter timing no contract declares.",
            "C — No queue change, ask 2 only: above a backlog threshold (the queue's pending count, getQueueSize), purge the record-sync queue (IQueueService.purge, an existing optional member) and reconcile every source the reconcile covers (the existing complete build with skip and purge); below it, syncs stay per message. Cost: size S-M. Meets the 50,000-record drain at about the rebuild time; acceptance 1 (1,000 syncs, bounded embedder calls) is met only by putting the threshold under 1,000, so it would be re-scoped; purge is all-or-nothing across sources, so it may run only when every source receiving record syncs is reconcilable (listDocuments, a data engine).",
            "D — Producer-side: one message per source per committed unit of work carrying many record ids (still identifiers only), fanned out into single-id messages when its batch fails, so a bad record dead-letters alone. Cost: size M, no queue change. But it changes the stored message shape (during a rolling deploy a node on the previous release reads a multi-id message as malformed and completes it without a sync), and it batches only as far as one write unit reaches (an import that writes record by record still publishes singles)."
          ],
          "recommendation": "A, with ask 2 built on it. Real business need: the only measured batching need is the knowledge record sync (67,379-record import, card); the email-send worker has none, so B imposes a concurrency and pacing change nobody asked for there, and C covers the import but not the 1,000-sync case. Long-term soundness: A is contract-first and explicit composition (the subscriber declares it takes batches; an adapter without the member keeps per-message delivery), while B ties knowledge throughput to undeclared adapter timing and C's purge is coarse. AI-error prevention: A declares the capability with a declared fallback, B hides it, D changes a stored message shape. Startup focus: A adds one optional contract member (a widening, no new gate); C is the smallest delivery. If the maintainer prefers no contract growth now, C is the minimal fix for the reported import, with acceptance 1 re-scoped."
        }
      ],
      "security_findings": "none",
      "out_of_scope_findings": [
        "carrier: #38413 (this card's ask 3) · DbQueueAdapter.getQueueSize reads up to 10,000 pending rows and answers their count (db-queue-adapter.ts, find with limit 10_000, then rows.length), so the index_status queue figure (knowledge-build-actions.ts readQueue) tops out at 10,000 during a 67,379-message backlog; an observation from reading the code, not measured through a public entry point, so not filed; ask 3's backlog display has to account for it · dedupe words: getQueueSize cap, record-sync pending, index_status queue"
      ],
      "deviations": "The platform-assigned branch existed locally with no worktree, so dev-worktree.sh refused it (local branch already exists); the worktree was added by hand with git worktree add, and the base pinned with dev-worktree.sh --pin-base (da184dac). No empty-branch probe (card-thread branch). Worktree removed afterwards; nothing local is left unpushed (no commits)."
    }
  7. objectstack-fleet commented on Nov 29, 2026

    @objectstack-fleet
    Contributor

    repo:objectstack#5 · os-project-manager · session_01FEkQ5nvFTicjSKrtupa2yY

    Decision analysis · 2026-11-29T02:29Z · #38413, how record-sync batching reaches the knowledge worker (the fork the dev reported in comment 7249390903 before any code), written by the decision thread opened for seat repo:objectstack#5. ⛔ Not a claim and not a ruling: the maintainer rules.

    维护者速读

    • 问题:往已建知识索引的对象里批量导入或批量更新后,检索要一两个小时才搜得到新内容,界面没有任何提示。卡住的不是算向量,而是平台的数据库队列:任何队列每秒最多放出十条消息,而且一条处理完才处理下一条。五万条至少八十三分钟,同样的数据整体重建只要九分半钟。
    • 选项:A 给队列加一个「成批取消息」的可选能力,只有知识同步选用,约两到三天、一到两个 PR,改公共契约;B 只改数据库队列的内部实现,所有队列一起变成并发、不限速,邮件发送和接口触发的流程也跟着变;C 队列不动,积压超过阈值就清掉消息、整体对账一次,改动最小,但一千条级的批量照旧逐条处理,验收第一条要改写;D 生产方一条消息带多个记录号,改了已存消息的格式,滚动升级时旧节点会不报错地丢掉同步。
    • 推荐 A:瓶颈在队列每秒十条的上限,只有改队列才能去掉;A 让需要成批的一方明说,没选用的一方完全不变,也是主流消息队列的通行做法。
    • 不定会怎样:卡片认领着但不动,批量导入后检索仍然落后一两个小时,管理员得知道要手动重建。

    Background

    Card #38413 (p2, Bug, area:ai, parent topic #37000) asks three things: (1) the record-sync worker drains per source in batches, (2) above a backlog threshold it schedules one reconcile and drops the covered messages, (3) the backlog is visible. Its last paragraph says: whether (1) needs a batch-consume shape on the queue contract is the first thing to settle, and a contract change is reported before coding. Triage (7248383369) repeats it: a change to IQueueService is a contract fork.

    The dev settled it first and returned needs_decision (7249390903) with nothing built. Two measurements on service-queue's own fake engine at da184dac: a coalescer inside the knowledge worker sees batches of 1 (handler in-flight maximum 1), and with an instant handler and default options 200 published messages gave 40 dispatched in 3,051 ms. So the floor is the queue's, not the embedder's.

    Governing text

    • Card service-knowledge: a bulk import syncs one record per queue message, read, embedded and written alone, so the index trails the data for hours #38413, Ask: "Whether point 1 needs a batch-consume shape on the queue contract (IQueueService.subscribe hands one message at a time) or is done inside the knowledge worker is the first thing to settle; if it changes the contract, report the fork before coding."
    • Card service-knowledge: a bulk import syncs one record per queue message, read, embedded and written alone, so the index trails the data for hours #38413, Acceptance 1: "A test that publishes 1,000 record syncs for one source observes a bounded number of embedder calls and adapter writes (batches, not 1,000 of each), and the index ends equal to a rebuild's." Acceptance 3: "A poisoned record in a batch dead-letters alone; its neighbours are indexed."
    • knowledge-record-sync-queue.ts:20: "One record-sync message: identifiers only. ⛔ Never a field value" (kept by every option; D keeps identifiers only but changes how many).
    • ADR-0119 D3 (IDataEngine.batch? retired): "Declared, implemented by no engine, called by no caller, specified by three words. Under ADR-0049's enforce-or-remove posture the choice is implement it or delete it". The test an added optional member has to pass: it lands with its implementation and its first caller.
    • ADR-0041 §5: boundary triggers "must ingest through the outbox/queue path — a slow flow execution may not drop or block inbound events". API-triggered flows are therefore a queue consumer too.
    • No ADR rules on batch consumption or on the queue contract's shape: grep -rIl -i -E "IQueueService|subscribeBatch|batch.consume" docs/adr answers nothing.

    Protocol statement: A edits packages/spec/src/contracts/queue-service.ts (a TypeScript contract member, not authorable metadata): a widening, Clause-② yes, Metadata-protocol: none. B, C and D edit no contract. D changes the stored shape of a queue message (sys_job_queue payload), which no contract declares.

    Premises, each with its re-check (read on main 1afd9c13)

    1. One message per handler call, awaited in turn. sed -n 567,580p packages/services/service-queue/src/db-queue-adapter.ts: pollOnce loops for (const row of claimed) { await this.dispatch(row); … }. The contract has no other consuming member: grep -n "subscribe" packages/spec/src/contracts/queue-service.ts gives subscribe<T>(queue, handler: QueueHandler<T>) and QueueHandler takes one QueueMessage.
    2. Every queue is paced at batchSize per pollIntervalMs. db-queue-adapter.ts:276-279: pollIntervalMs ?? 1000, batchSize ?? 10. packages/core/src/dispatch-loop.ts nextIntervalMs: "intervalMs while ticks claim work", measured from the START of the tick. 50,000 / 10 per s = 83 min; 67,379 = 112 min.
    3. The database queue has four subscriptions in this repository, not two. grep -rnE "\.subscribe(<[^(]*>)?\(" packages --include=*.ts | grep -v -E "\.test\.|node_modules|/dist/" | grep -E "queue\.|q\.": the knowledge record sync (knowledge-service-plugin.ts:877), the mail send worker and the mail attachment reclaim (plugin-email/src/email-plugin.ts:1210 and :1288) and one queue per API-triggered flow (packages/triggers/trigger-api/src/api-trigger.ts:412, flow-api:<flow>). The dev's report names the first two; the other two are this thread's reading.
    4. The contract already carries optional capability members with a declared absence. queue-service.ts: getQueueSize?, purge?, listFailed?, replay?, purgeFailed?. The knowledge plugin already branches on one (listFailed, to decide whether a queue is durable).
    5. Only one adapter can carry record sync. packages/services/service-queue/README.md:20: "A BullMQ/Redis adapter is not shipped." The memory adapter and the kernel fallback never carry record sync (the plugin syncs inline without a durable queue, knowledge-service-plugin.ts:860-874).
    6. The reconcile C relies on reads every row of the source. knowledge-service.ts reindexSource: a keyset walk over the whole source that skips unchanged documents by hash and purges stale ones. Its cost follows the size of the source, not the size of the change.
    7. The queue is one queue for every source. KNOWLEDGE_RECORD_SYNC_QUEUE is a single name; IQueueService.purge?(queue) drops all of it.

    The question

    After a bulk import or bulk update of an indexed object, search trails the data by an hour or two with no sign of it, because the platform's database queue releases at most ten messages a second, one at a time, to any consumer. Where is that limit lifted: in the queue's contract (opt-in), in the queue's implementation (for everyone), not at all (go around it), or in the producer?

    Options, real cost, effort

    Option What is done What customers see Effort
    A: opt-in batch consumption on the queue contract One optional member on IQueueService (a batch subscription whose handler takes many messages and answers one outcome per message). The database adapter implements it: claims up to the asked batch for that queue and ticks again at once while a claim comes back full. The knowledge worker uses it when present and keeps per-message subscribe otherwise. Ask 2 is built on it. Bulk imports and updates of any size reach search in roughly rebuild time. Mail and API-triggered flows behave exactly as today. domain:server · 1 to 2 PRs · the dev's estimate M to L, 2 to 3 days; no landed precedent measured. Clause-② yes (widening), contract-tier review, the maintainer's approval at merge.
    B: implementation only, every queue The database adapter dispatches claimed rows concurrently and ticks again after a full claim, for every queue; the knowledge worker groups the handlers that happen to arrive together. Search catches up faster, in batches of at most 10 unless an operator raises the global batch size. Mail under a backlog goes out up to 10 at a time with no pacing (a provider's rate limit answers with refusals, retries, then dead letters, which a customer sees as mail that never arrived). API-triggered runs of one flow start concurrently where they ran in order. domain:server · 1 PR · the dev's estimate M; no precedent. No contract edit.
    C: no queue change, ask 2 only Above a backlog threshold the worker purges the record-sync queue and reconciles every source; below it, per message as today. The measured import (67,379 records) catches up in about rebuild time. A bulk change under the threshold still waits at ten a second. Every large bulk change costs a full walk of the source, however few rows changed. Where any source cannot be reconciled, nothing changes. domain:server · 1 PR · the dev's estimate S to M; no precedent. Acceptance 1 has to be rewritten by the maintainer.
    D: many record ids per message The producer publishes one message per source per committed unit of work, fanned out into single-id messages when its batch fails. Helps only imports that write many records in one unit of work; an import that writes record by record is unchanged. During a rolling deploy a node on the previous release completes a multi-id message without syncing it, with no error. The ten-a-second pace stays. domain:server · 1 PR · the dev's estimate M; no precedent.

    Business meaning

    • A: the warehouse opens a pallet dock next to the parcel counter. Whoever ships pallets asks for the dock; parcels keep using the counter.
    • B: the parcel counter is removed and everyone is waved through at once, including senders whose carrier only accepts so many parcels a minute.
    • C: when the parcel line gets too long, the line is sent home and the whole stockroom is recounted.
    • D: senders are told to tape parcels together, and a clerk who has not been told throws the taped bundle away.

    Four axes

    • Long-term fit. Batch consumption with per-message outcomes is how the mainstream queues model this (AWS SQS with Lambda's batch size and partial batch response, Kafka's per-batch consumer, pg-boss handing a handler an array of jobs on a Postgres-backed queue, Azure Service Bus batch receive; all from prior knowledge, not re-read for this card). The bulk consumers a metadata platform grows next (search and analytics sync, webhook fan-out, notification bursts) meet the same ten-a-second floor. A adds one contract member and removes a special case: no consumer has to depend on how an adapter happens to schedule handlers. It passes ADR-0119 D3's test, since the member lands with its implementation and its first caller. B grows no contract but creates an undeclared one (knowledge throughput rests on handler-arrival timing) and changes three other subscriptions that did not ask. C grows nothing and leaves the floor in place for the next consumer; its repair cost follows table size. D changes a stored shape for a partial gain.
    • Real pull. One measured case (BrightRule on 19.0.0-next.2, 67,379 records, one run), and the mechanism reaches every bulk import or bulk update of an indexed object. No pull on mail or API-flow concurrency (B). No measured pull on mid-size batches specifically; the card's acceptance 1 asks for them.
    • AI error surface. A: the capability is a named member, and its absence has a named fallback that is slower and still correct. B: a later refactor of the adapter's scheduling removes the batching with no failing contract; mail failures show up at the provider, far from the change. C: a purge is all sources at once, so a wrong "every source is reconcilable" reading drops syncs quietly. D: the previous release reads the new message as malformed and completes it, a silent loss.
    • No spread. C is the smallest. A adds one optional member, which is a standing obligation on the contract; it is one member, opt-in, with no new gate. B and D add no declared surface and each adds an undeclared one.

    os-decision-facets
    ① Long-term fit: A shrinks the special case (batching is declared by the subscriber, no consumer rests on adapter timing) at the price of one optional contract member that lands with its implementation and first caller; B creates an undeclared timing contract and changes mail and API-flow consumers; C leaves the ten-a-second floor for every later consumer; D changes a stored message shape.
    ② Real pull: measured once (67,379-record import, 112 min floor against a 9.5 min rebuild); reaches every bulk import or update of an indexed object; zero pull on mail or API-flow concurrency.
    ③ AI error surface: A is explicit with a correct fallback; B fails far from the change (provider refusals, dead-lettered mail); C's purge is coarse; D loses syncs silently during a rolling deploy.
    ④ No spread: C adds nothing; A adds one optional member (a standing obligation); B and D add undeclared behaviour.
    Prior rulings read: queue,batch,subscribe,iqueueservice → 24 ADR candidates, none on queue consumption; ADR-0119 D3 (an optional member must land implemented and called), ADR-0041 §5 (API triggers ingest through the queue); thread: none; repo: objectstack-ai/objectstack
    Also read, by hand: the dev report 7249390903; triage 7248383369; the claim 7249250268; ruling record 7248214179 (a not-enabled service syncs nothing, which the batch path keeps).

    Recommendation

    A, with ask 2 built on it, as the dev also concludes; reached here from premise 2 and premise 3, not carried over. End state: two years on, the platform queue has two ways to consume, one message or a batch, and a consumer says which; every bulk workload uses the second and no adapter's internal pacing is anybody's dependency. Measured pull exists, so the long-term shape is paid for once.

    Not taken. B: it lifts the limit for consumers that did not ask and makes knowledge depend on timing nothing declares. C: it is ask 2, which A delivers as well; alone it leaves acceptance 1 unmet and the floor in place. D: a silent loss during rolling deploys for a gain that misses record-by-record imports.

    Effort note: A is roughly two to three times C by the dev's estimates. The ① readings are not close, so the difference does not move the letter.

    Self-check: ① alone picks A; ②③④ flip it: no.

    Confidence gaps:

    • The slow drain was measured once, on one deployment, and not timed to completion; the 83 and 112 minute figures are the pacing floor, computed from a measured 40 messages in 3.05 s.
    • Nothing is built, so A's after-figure (acceptance 2, 50,000 records on a real store and embedder) is not measured. All efforts are the dev's estimates with no landed precedent.
    • C's weakness on a large source with a small change is read from the walk's code (premise 6), not measured.
    • Adapters outside this repository (a host's own IQueueService, the cloud's composition) cannot be read. An optional member breaks none of them; they keep per-message delivery until they implement it.
    • A batch claimed under one lease has to finish inside it or extend it (default lease 30 s, a remote embedder). This is a design point for the dev and the contract review, not a reason to change the letter.

    After the ruling

    • A: the seat lifts the hold; the card thread updates its claim (Clause-② yes, widening; file surface gains packages/spec/src/contracts/queue-service.ts and the regenerated API surface) and redispatches. Carried as execution conditions, not asked again: the member is optional and the worker keeps per-message subscribe as its fallback; one outcome per message, so a poisoned record dead-letters alone; the mail and API-flow subscriptions are not touched; batch size is sized against the lease. Contract-tier L2 review before landing; the PR goes to the maintainer for approval as a contract change. Ask 3 still waits for service-knowledge: every boot logs a false ERROR because the sync-state upsert reads a by-id update as "no row changed" #38418.
    • C: the seat rewrites acceptance 1 on the card quoting the ruling record, the card thread builds ask 2 only, and ask 1 is filed as a separate card or dropped, by the maintainer's word in the same ruling.
    • B: the card thread builds it with the mail and API-flow owners named in the PR, and the changeset says every queue consumer's concurrency changed.
    • D: the card thread adds a reader for both shapes first (expand, then switch), which is a second release step.
    • Whatever the letter: the getQueueSize 10,000 cap the dev noted is folded into ask 3 or filed by the seat as a review follow-up.

    Related: #37000 (topic), #37735 (sync through the queue), #36992 (paged rebuild), #36995 (embedder batches), #38418 (sync state, p1, seat 1), #38369 (not-enabled gating).

  8. objectstack-fleet commented on Nov 29, 2026

    @objectstack-fleet
    Contributor

    repo:objectstack#5 · os-project-manager · session_01FEkQ5nvFTicjSKrtupa2yY

    Ruling: letter A · maintainer 「A 队列加可选的成批消费」 · recorded 2026-11-29T03:51Z

    • Who and when: the maintainer (Leehom, os-project-manager) tapped option A on the decision card at 2026-11-29T03:51:14Z. The card's question, as he read it: 「裁定批量导入后知识索引同步慢从哪里改」. The option's label, verbatim: 「A 队列加可选的成批消费」. Its one-line consequence on the card, verbatim: 「只有知识同步按批处理,邮件和接口触发的流程不变;给公共契约加一个可选成员,约两到三天,合并前要你批准一次。」 He added no condition.
    • Ruling-ref: decision thread cmsg_01TenzsRopZj4jMbvjX8uz1X4C7iaBDKWqdWY6nwLHHneV, decision card cmsg_01TenzsRopZj4jMbvjX8uz1X1iGYjUXcuvyHn2ruBkXpQ6, option index 0 (A). Analysis: comment 7249459668 on this card. Question raised by: the dev report 7249390903.
    • What is ruled: record-sync batching reaches the knowledge worker through an optional batch-consume member on IQueueService (a contract widening, Clause-② yes), implemented by the database queue adapter and used by the knowledge worker when the composed queue has it. Ask 2 of the card (above a backlog threshold, one reconcile instead of chasing messages) is built on it.
    • Not taken: B (every database queue concurrent and unpaced), C (no queue change, purge and reconcile above a threshold, acceptance 1 rewritten), D (many record ids per message).
    • Not ruled: the member's name and exact signature, the batch size and the backlog threshold (the dev proposes them with numbers, the contract review judges them); ask 3's shape. The card's acceptance stands as written.
    • Carried from the analysis as execution conditions, not asked again: the member is optional and the worker keeps per-message subscribe as its fallback; one outcome per message, so a poisoned record dead-letters alone; the mail send, mail attachment reclaim and API-flow subscriptions are not touched; a batch is sized against the lease.
    • Next: seat repo:objectstack#5 lifts the hold; the card thread updates its claim (Clause-② yes, widening; the file surface gains packages/spec/src/contracts/queue-service.ts and the regenerated API surface) and redispatches. Contract-tier L2 review before landing; the PR goes to the maintainer for approval as a contract change.
  9. objectstack-fleet commented on Nov 29, 2026

    @objectstack-fleet
    Contributor

    repo:objectstack#5 · os-project-manager · session_01FEkQ5mC8eA4qtKSweeF7wd
    Claim: PM loop round 1 · 2026-11-29T03:54Z · amended on the ruling, supersedes claim 7249250268 (same session, same branch)
    Ruling-ref: 7250307515 · letter A · maintainer 「A 队列加可选的成批消费」 · analysis 7249459668 · question raised by os-dev-report 7249390903
    Session: session_01FEkQ5mC8eA4qtKSweeF7wd
    Thread session: session_01FEkQ5mC8eA4qtKSweeF7wd
    Account: os-project-manager
    Branch: claude/project-thread-caiyo5
    Worktree: objectstack-issue-38413
    Domain: domain:server
    Seat: repo:objectstack#5
    Area: o5-ai37000
    File surface: packages/spec/src/contracts/queue-service.ts (one optional batch-consume member on IQueueService) and the regenerated API surface it moves (packages/spec/api-surface/contracts.json, packages/spec/api-surface-signatures.json, any other generated output a gate names); packages/services/service-queue/src/db-queue-adapter.ts (implements the member; getQueueSize for ask 3) + new test files named for this card; packages/services/service-knowledge/src/knowledge-service.ts (the syncRecord / writeSynced region), knowledge-record-sync-queue.ts, knowledge-service-plugin.ts (the record-sync queue subscription only), new batch-worker module(s) and new test files named for this card in packages/services/service-knowledge/src/; knowledge-sync-state.ts for ask 3 only after #38418 (PR #38460) merges; knowledge-build-actions.ts (readQueue only) if ask 3's display needs it; changeset(s) .changeset/38413-*.md (stop on breach; explain in the report). The mail send, mail attachment reclaim (email-plugin.ts) and API-flow (api-trigger.ts) subscriptions are NOT in it: they stay untouched (ruling 7250307515).
    Container & model: M, mode:thread (this card thread dispatches one os-dev subagent in its own container), model: default (dispatch-gates --tier at 2052c89 on the amended surface incl. packages/spec/src/contracts/queue-service.ts, "Model tier — no path-derived mandate"; contract design judgement, so not floor), effort: high (M, three packages, a contract widening)
    Clause-②: yes
    Metadata-protocol: none
    Responsibility: @objectstack/service-knowledge (objectstack): the record-sync worker reads, embeds and writes one record per queue message, and @objectstack/service-queue's database adapter hands claimed rows over one at a time and claims at most batchSize per poll interval (os-dev-report 7249390903: 40 messages in 3,051 ms at defaults) | an operator rebuild of the source is the only path that batches; none on the event path | administrators and builders on every import or bulk update of an indexed object; measured once on 19.0.0-next.2 (BrightRule, 67,379 records, card body)
    Thread-read: 7250307515
    Premise: holds — re-measured by os-dev-report 7249390903 at da184da (H1: coalescer batches of 1; claim pace 10 per 1 s for every queue); packages/spec/src/contracts/queue-service.ts and db-queue-adapter.ts unchanged on da184da..2052c89 is the dev's first check
    Serial constraints cleared: check-handover --inflight at 2052c899 on the amended surface: OVERLAP verdict, 6 claims, each handled; no claim meets packages/spec/src/contracts/queue-service.ts. (1) #38418 (p1, repo:objectstack#1, PR #38460, knowledge-sync-state.ts): ask 3's edits to that file queue behind its merge, main merged in first. (2) #38419 (repo:objectstack#1, PR #38465, knowledge-service.ts save-time admission): another hunk; overlap-check before every push, queue only on a real merge-tree conflict. (3) #38369 (this area, knowledge-service.ts, knowledge-service-plugin.ts, knowledge-build-actions.ts): overlap-check before every push; a real merge-tree conflict queues this PR behind it; the batch path keeps its gate (a not-enabled service syncs nothing). (4) #38411 (this seat, testing.ts, knowledge-tools.ts, sql.ts): not in this surface. (5)(6) #38351 / #38377 (split/**): not in this surface. (7) this card's own earlier claim 7249250268: superseded here. Not folded.
    Pre-claim lane: packages/spec, packages/services/service-queue, packages/services/service-knowledge ⇒ domain:spec (contract file) and domain:server (file ownership only); in lane (area-lease 留道).
    Pre-claim deps: none named by the card; the fork is ruled (7250307515).
    Prior rulings read: ruling 7250307515 (A), execution conditions verbatim: "the member is optional and the worker keeps per-message subscribe as its fallback; one outcome per message, so a poisoned record dead-letters alone; the mail send, mail attachment reclaim and API-flow subscriptions are not touched; a batch is sized against the lease." Not ruled there: "the member's name and exact signature, the batch size and the backlog threshold (the dev proposes them with numbers, the contract review judges them); ask 3's shape." Carried from claim 7249250268: knowledge-record-sync-queue.ts:20 identifiers-only message; ADR-0161 K7 one fingerprint per write; K8 no IKnowledgeAdapter member; ruling 7248214179 (2A/3A) a not-enabled service syncs nothing.
    Review and landing: contract-tier L2 (model fable, transcript verified) on the final head plus L1-a; a contract widening, so the PR goes to the seat for the Tier H hand-off to the maintainer; this card thread does not land it.

  10. objectstack-fleet commented on Nov 29, 2026

    @objectstack-fleet
    Contributor

    repo:objectstack#5 · os-project-manager · session_01FEkQ5mC8eA4qtKSweeF7wd
    os-dev-report

    {
      "issue": 38413,
      "status": "blocked",
      "branch": "claude/project-thread-caiyo5",
      "pr": null,
      "session": "session_01FEkQ5mC8eA4qtKSweeF7wd",
      "premise_still_valid": true,
      "summary": "Ruling A (7250307515) is half built and pushed as WIP (claude/project-thread-caiyo5 at c5678def, base 2052c899), and the overlap rule stops it: `node scripts/pm/overlap-check.mjs --branch=claude/project-thread-caiyo5` answers VERDICT overlap exit 1, a real merge-tree conflict with open draft PR #38470 (#38369, branch claude/project-thread-mu3i0t) in packages/services/service-knowledge/src/knowledge-service.ts, inside KnowledgeService.processRecordSync. #38470 inserts `if (this.held) return 'not-synced';` (ruling 7248214179's not-enabled gate) into processRecordSync's preface; this branch moves that same preface into a new private resolveRecordSync shared by the per-message path and the new batch path, so the two hunks overlap. The resolution is mechanical and is also what ruling 7248214179 requires of the batch path: the held check becomes the first check of resolveRecordSync (answering { outcome: 'not-synced' }), so both paths sync nothing for a not-enabled service. Per the order, no PR was opened and nothing further is pushed. Built so far: (1) packages/spec/src/contracts/queue-service.ts: optional IQueueService.subscribeBatch(queue, handler, { maxBatch }) with QueueBatchHandler, QueueBatchOutcome ({ ok: true } | { ok: false, error }) and QueueBatchSubscribeOptions; docblock states the per-message fallback and the one-kind-per-queue rule. (2) DbQueueAdapter implements it: a batch-consumed queue drains on its own DispatchLoop (claims up to maxBatch, renews every claimed row's lease in one compare-and-set write, settles each row by its own outcome through the shared settleRow, ticks again at once while a claim comes back full); per-message queues keep the main loop untouched (one message per call, batchSize per pollIntervalMs); publish wakes only the loop of its queue; reclaim stays on the main loop; getQueueSize counts through the engine's count when present (lifts the 10,000 cap, ask 3 / the folded finding). (3) Knowledge: processRecordSyncBatch (group by source and object, one re-read with id in the group under where, one split, one upsert, one delete, one index plan = one fingerprint, per-document chains held via chainAfterAll, per-record fallback when a batch of more than one fails), the 'covered' outcome (a done build that began 5 s or more after the message's publish), ask 2 (backlog of 5,000 or more waiting syncs and a source filling at least 50 of a 100-message batch: one reconcile asked and waited on, covered messages complete without a read), the plugin subscribes with subscribeBatch when present, else per-message subscribe. contract_faces_touched: packages/spec/src/contracts/queue-service.ts (IQueueService.subscribeBatch?, three new exported types); DbQueueAdapter.subscribeBatch / pollBatchOnce (public members of an exported class); service-knowledge exports KnowledgeRecordSyncOutcome gains 'covered', new exported constants and types in knowledge-record-sync-queue.ts. Not yet done: knowledge batch tests (acceptance 1, 3, 4, ask 2), the 50,000-record measurement, spec api-surface regeneration, changesets, merge of origin/main, PR.",
      "tests": "At c5678def: `pnpm exec vitest run --maxWorkers=2 src/db-queue-adapter.test.ts` (service-queue): Test Files 1 passed, Tests 45 passed, including a new top-level describe 'DbQueueAdapter — batch consumption (subscribeBatch)' with 7 cases: one call for up to maxBatch messages and per-message settling (a poisoned message alone retried then dead-lettered), throw and wrong-outcome-count fail the whole batch, one kind per queue and maxBatch validation, one-write lease renewal for all rows, a 250-message backlog drained as [100, 100, 50] in under one poll interval, a per-message queue still at 30 messages in 2.5 s with in-flight maximum 1 while a 1,000-message batch queue drains, getQueueSize past 10,000 through count. Knowledge, under the lock: `pnpm exec vitest run --maxWorkers=2 src/__tests__/record-sync-queue.test.ts src/__tests__/sync-state.test.ts src/__tests__/plugin-shutdown-unsubscribes.test.ts`: VERDICT command-exit 0, Test Files 3 passed, Tests 52 passed (the real-kernel queue suite now runs over subscribeBatch). `tsc --noEmit` clean in service-queue and service-knowledge after `pnpm --filter @objectstack/spec build` (VERDICT command-exit 0). Acceptance measurement (50,000 records) NOT MEASURED: blocked before it.",
      "gates": "NOT MEASURED: derived gate families, reason: blocked before the PR head; dispatch-gates.mjs --commands not yet run. overlap-check at c5678def: `✓ origin/main merges cleanly`, `✓ #38465 merges cleanly`, `✗ #38470 conflicts in knowledge-service.ts`, VERDICT overlap exit 1. No PR, so no check-runs.",
      "dogfood_battery": "n/a — no PR yet; the PR title will carry no `!` and Clause-② is yes (widening), no (narrowing) arm",
      "mcp_calls": "0",
      "api_writes": "1 — this report comment on #38413 via scripts/pm/post-stamped.mjs (POST /repos/objectstack-ai/objectstack/issues/38413/comments, fleet relay). Two git pushes of claude/project-thread-caiyo5 (b804f735, c5678def). Reads: 3 single-comment REST GETs (7250307515, 7249459668, 7250337253), PR 38460 and 38470 reads, one fetch of claude/project-thread-mu3i0t into refs/os38413/mu3i0t for the merge-tree reading.",
      "open_questions": [
        {
          "question": "How does this branch proceed past the knowledge-service.ts conflict with draft PR #38470 (#38369)?",
          "options": [
            "A — Keep building here now (tests, measurement, changesets) and open this PR as a draft; whichever of the two lands second merges main and moves the held check into resolveRecordSync (one line; the batch path then honours ruling 7248214179 too). Cost: none now; one mechanical resolution later.",
            "B — Queue this PR behind #38470: finish locally, push only after #38470 merges, merge origin/main, put the held check into resolveRecordSync in the same merge. Cost: waits on #38470's Tier H approval (a narrowing).",
            "C — Restructure here so the two diffs do not touch the same lines: keep processRecordSync's preface byte-identical and give the batch path its own copy. Cost: a duplicated preface, and once #38470 lands the batch path lacks the not-enabled gate until someone adds it, a breach of ruling 7248214179 in between."
          ],
          "recommendation": "A, because the conflict is a one-line, mechanical move that the second lander makes either way, the batch path must carry the same gate in any case, and A keeps this card moving without stacking PRs or rebasing onto #38470's branch; C trades a merge conflict for a silent ruling breach."
        }
      ],
      "security_findings": "none",
      "out_of_scope_findings": [],
      "deviations": "The second push (c5678def) went out before overlap-check was run for it; the check run right after found the #38470 conflict, and nothing further was pushed. The order lists new test files for service-queue; the new DbQueueAdapter pins went into the existing shared harness db-queue-adapter.test.ts as a top-level describe instead (AGENTS.md: a new pin for a component with a shared harness file goes into that file, ruling record 6583487846). The worktree from the first round had been removed; it was re-added on the existing local branch and fast-forwarded to origin/main 2052c899 (no commits on it before), base pinned with dev-worktree.sh --pin-base."
    }
  11. objectstack-fleet commented on Nov 29, 2026

    @objectstack-fleet
    Contributor

    repo:objectstack#5 · os-project-manager · session_01FEkQ5mC8eA4qtKSweeF7wd
    Serial: queued behind PR #38470 (#38369) · 2026-11-29T04:13Z

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

area:aidomain:serverpm:dispatchedpriority:p2

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions