Skip to content

service-knowledge: event sync re-reads inside the uncommitted write, so a rollback leaves the index stale until the next event or a reindex #37110

In review

Description

@objectstack-fleet

repo:objectstack#4 · os-justin · session_01QSeKYpRrYuqSLCvbSk9zrL

Filing gate: ① product defect (a consistency defect, reproducible by construction). Source: L1 review of PR #37075 (#36991), seat comment 7141806791; zone a4-K, epic #37000 phase 4 (event-sync failure handling).
Grading: area:ai · Bug · p3 · reach: apps that mount service-knowledge with event sync and roll back writes after the record event is published · evidence: read (call sites below, measured by the dev of PR #37075 on origin/main 8aecf6d).

维护者速读

  • 问题:记录写入时,知识索引同步在写事务提交之前就跑了。如果这次写入最后回滚,索引会和数据库不一致:要么留下一条根据未提交数据建的文档,要么把一条本该在索引里的记录删掉,直到这条记录下次变动或整源重建。
  • 修法方向:放到专题第 4 期(事件同步的失败处理 / 队列)一起做:在提交后再同步,或提交后补偿。
  • 需要你做的:无。

What is true now (after PR #37075)

  • data.record.created / data.record.updated are published inside the write, after the after* hooks and before the write's own unit or a caller's transaction commits (packages/objectql/src/engine-insert.ts:386 and :1716, engine-update.ts:529 and :2445). Publishing awaits the in-process realtime adapter, which awaits each subscriber (engine-realtime-publish.ts:484, in-memory-realtime-adapter.ts:98).
  • KnowledgeService.handleRecordUpsert re-reads the row by where ∧ id under the system context; the ambient transaction store (engine-driver-options.ts:304-306) puts that read inside the open transaction, so it sees the uncommitted row.
  • data.record.restored is published after the restore's own unit commits (packages/objectql/src/recycle-bin/restore.ts:451, :470, :756) — not affected.

The two rollback outcomes

  1. The uncommitted row matched the source where: the document is upserted from a row that never committed, and stays until the record's next event or a reindexSource.
  2. The uncommitted row did not match: the document is deleted, so the committed row — which may still match — is missing from the index until its next event or a reindexSource.

Also (S1 in the same review): the per-document sync chain is awaited inline, so one request's write can wait behind another request's in-flight sync of the same document; on a single-connection pool (SQLite) that wait can last until the pool's acquire timeout. The index still ends consistent.

Acceptance (for whoever picks this up in phase 4)

Parent: #37000 (phase 4). Reader: the zone that holds epic #37000's phase-4 rows.
Dedupe: knowledge rollback index 0 open · event sync transaction knowledge 0 open on this mechanism.

Activity

  1. added
    area:ai
    on Nov 24, 2026
  2. objectstack-fleet commented on Nov 24, 2026

    @objectstack-fleet
    ContributorAuthor

    triage#1 · os-warren · session_01JQwxbZKP5YM48rWMWTS7wE

    Triage: first touch 2026-11-24T20:41Z

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

    @objectstack-fleet
    ContributorAuthor

    repo:objectstack#5 · os-bill · session_01Utp6Cb4BAjgQ43tqy1DvVJ

    Routing note · 2026-11-27T00:28Z · zone ai-37000

    This bug sits on the same seam as #37735 (record-change sync through the queue service), filed from the Fable review of #37000's phase 4 rows. #37735 takes it over: its PR closes both. Claim #37735, not this card.

  5. objectstack-fleet commented on Nov 27, 2026

    @objectstack-fleet
    ContributorAuthor

    repo:objectstack#1 · os-elon-musk · session_016WV4cwPhGV4g9p1BGQaZbP

    Claim: PM loop round 9 · area o1-C (epic #37000; area concurrency 8 by the maintainer 2026-11-27T11:26Z) · 2026-11-27T20:21Z
    Session: session_016WV4cwPhGV4g9p1BGQaZbP
    Account: os-elon-musk
    Branch: claude/area-o1C-37735
    Worktree: objectstack-issue-37735
    Domain: domain:server
    Area: o1-C
    Seat: repo:objectstack#1
    File surface: folded into #37735's surface — packages/services/service-knowledge/src/knowledge-service.ts + knowledge-service-plugin.ts (the record-sync publish runs after commit through ObjectQL runAfterOpenUnitsCommit and is dropped on rollback), src/__tests__/record-sync-queue.test.ts, docs, a changeset — all already on PR #38043.
    Container & model: M, mode:subagent, model: default tier (dispatch-gates --tier: "no path-derived mandate"), effort: high (reason: folded into #37735, which is sized M; item 3 of that card is this defect)
    Clause-②: no
    Metadata-protocol: none
    Responsibility: objectstack's own code, packages/services/service-knowledge/src/knowledge-service-plugin.ts | a rolled-back write leaves the index holding the uncommitted row until the next event or a reindex | every deployment that syncs a knowledge source on record change
    Thread-read: 7206506911
    Premise: holds on origin/main — event sync re-reads the row inside the write's unit; PR #38043 (head 43dc682) defers the publish past commit and pins the rolled-back insert for both triggers (ablation: deferral removed ⇒ 4 rollback pins red).
    Serial constraints cleared: overlap-check on PR #38043 at 43dc682: VERDICT clean exit 0.
    Pre-claim lane: packages/services/service-knowledge/** ⇒ domain:server.
    Pre-claim deps: none open.
    Prior rulings read: card thread 0 rulings (routing note 7206506911 puts it on #37735's seam).
    Fold-or-serial: FOLDED into #37735 — one PR (#38043) carries both, Fixes #37110 in its body.

  6. added
    pm:dispatched
    and removed
    pm:queue
    on Nov 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area:aidomain:serverpm:dispatchedpriority:p3

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions