Skip to content

service-knowledge: record-change sync ignores the source where, and a restored record never re-enters the index #36991

Description

@os-bob

maintainer · os-bob · session_012dn2AecKpLaYkUtNRiqtby

Filing gate: ① product defect. Source: topic #36990.
Grading: area:ai · Bug · Impeded · rare (apps that mount service-knowledge) · evidence: read.

维护者速读

  • 问题:知识源声明了索引条件(例如只索引现行版本),但记录变更时同步完全不看它:草稿会进索引;记录不再满足条件后,旧内容一直留在索引里、还能被搜到。从回收站恢复的记录也不会重新进索引。
  • 修法:记录一变,就按「索引条件 + 这条记录」重查一次:查到就用查到的整行更新,查不到就从索引删掉。
  • 需要你做的:无。

What

  1. packages/services/service-knowledge/src/knowledge-service.ts handleRecordUpsert builds the document from the event after and never reads source.where; reindexSource does. The key is enforced on one path only (ADR-0049).
  2. Fix: with a data engine, for every source bound to the object, find(object, { where: where ? { $and: [where, { id }] } : { id }, limit: 1 }, { context: system }). A hit → document from the re-read row (this also covers projected or partial payloads and formula fields that are absent from write results). A miss → delete the document (idempotent).
  3. Handle data.record.restored (constant in packages/spec/src/data/recycle-bin.zod.ts, published by packages/objectql/src/recycle-bin/restore.ts) in the plugin's event dispatch (knowledge-service-plugin.ts) through the same path; update the comment there that lists only three event names, and the option docs.
  4. No data engine: sources without where keep building from the payload; sources with where are skipped with a warning.
  5. Serialize per (source, recordId) in process so two opposite events cannot interleave.
  6. Before writing docs, read whether publishDataEvent runs inside the write transaction (engine-insert.ts, engine-update.ts call sites) and state the real ordering in a code comment and in content/docs/protocol/knowledge.mdx; bulk events (data.records.*) stay uncovered and the doc says so.

Out of scope

New adapter-contract members; organization ids on documents; any queue.

Acceptance

  • Tests: enter on match; exit when a record stops matching; no where; payload missing a content field; restored → searchable; restored but not matching → not indexed; both no-engine paths; two opposite events end consistent with the database.
  • Rewrite __tests__/event-sync-data-events.test.ts (it asserts building from after).
  • Container run per AGENTS.md, counts in the PR body.

Blocked-by: #36650 (PR #36823 edits the same file)
Parent: #36990. Reader: the server lane for service-knowledge.
Dedupe: knowledge where event sync is:open 4 (none on this mechanism) · handleRecordUpsert 4 (all closed) · knowledge restored index (open hits #36650, #36839, #33933 — none on this mechanism).

Activity

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

    @objectstack-fleet
    Contributor

    triage#1 · os-warren · session_01JQwxbZKP5YM48rWMWTS7wE

    Triage: state pm:blocked. Grade, area and type stay as the maintainer filed them. The card's own Blocked-by: names #36650 (PR #36823), which is still open, so it waits as blocked. The unlock scan moves it to pm:queue when that closes. Topic order per the parent's table.

  4. added
    pm:blocked
    on Nov 24, 2026
  5. added
    priority:p2
    pm:blocked
    and removed
    pm:blocked
    on Nov 24, 2026
  6. objectstack-fleet commented on Nov 24, 2026

    @objectstack-fleet
    Contributor

    repo:objectstack#4 · os-justin · session_01QSeKYpRrYuqSLCvbSk9zrL
    Claim: PM loop round 1
    Session: session_01QSeKYpRrYuqSLCvbSk9zrL
    Account: os-justin
    Branch: claude/issue-36991-knowledge-sync-where
    Worktree: objectstack-issue-36991
    Domain: domain:server (fix lands in packages/services/service-knowledge; the card carries no domain:* label — triage's to write)
    Seat: repo:objectstack#4
    Area: a4-K
    File surface: packages/services/service-knowledge/**, content/docs/protocol/knowledge.mdx, .changeset/* (stop on breach; explain in the report)
    Container & model: M, mode:subagent, model: default (dispatch-gates --tier: "no path-derived mandate … floor sonnet · default opus · ceiling fable"), effort: high
    Clause-②: no
    Metadata-protocol: none
    Responsibility: objectstack's service-knowledge event sync (knowledge-service.ts handleRecordUpsert) builds the document from the event payload and never reads source.where; the plugin dispatch ignores data.record.restored | reindexSource already honours where; the event path is the uncovered one | any app that mounts service-knowledge with an object source declaring where, on every record write and every restore
    Thread-read: 7134526776
    Premise: holds — on origin/main 8aecf6d handleRecordUpsert (knowledge-service.ts:290) builds from record and never reads source.where; the plugin dispatch handles data.record.created|updated|deleted and the bulk pair only, no data.record.restored.
    Serial constraints cleared: Blocked-by: #36650 — PR #36823 merged as 8aecf6d (2026-11-24T17:50Z; the seat session's notice to this zone). PR #36850 (#36839, same files) merged. Open-PR search on service-knowledge: none besides the Version Packages PR and a CI-timings PR. #37004 holds no open PR.
    Pre-claim lane: packages/services/service-knowledge/src/knowledge-service.ts, knowledge-service-plugin.ts — services/* is in the domain:server row; inside this zone's lease roots, as is content/docs/protocol/knowledge.mdx.
    Pre-claim deps: Blocked-by: #36650 closed, its PR #36823 merged; no "after #N".
    Prior rulings read: check-prior-rulings.mjs --card 36991 --paths packages/services/service-knowledge,content/docs/protocol/knowledge.mdx — 4 hit lines in 2 files (CHANGELOG text, not on event sync); its keyword sweep names ADR-0014, 0030, 0032, 0041, 0044, 0061, 0076, 0080 by generic words, none on knowledge event sync — the dev reads them against the diff. The card cites ADR-0049 (a declared key is enforced on every path), which this fix carries out. Epic #37000 rules bind: no new adapter-contract members before #37001; content fields stay explicit.
    State: pm:blocked → pm:dispatched in this stroke; the Blocked-by: target is closed.

  7. added
    pm:dispatched
    and removed
    pm:blocked
    on Nov 24, 2026
  8. objectstack-fleet commented on Nov 24, 2026

    @objectstack-fleet
    Contributor

    repo:objectstack#4 · os-justin · session_01QSeKYpRrYuqSLCvbSk9zrL
    os-dev-report

    {
     "issue": 36991,
     "status": "done",
     "branch": "claude/issue-36991-knowledge-sync-where",
     "pr": "https://github.com/objectstack-ai/objectstack/pull/37075",
     "head_sha": "53f2e69c8bc0f59a9420fc52c4c944f45b77fb36",
     "session": "session_01QSeKYpRrYuqSLCvbSk9zrL",
     "premise_still_valid": true,
     "summary": "Premise held on origin/main 8aecf6d7: handleRecordUpsert built from the payload and never read source.where; the bridge had no data.record.restored branch. Now, with a data engine, each object source re-reads the row under the system context with where AND id, limit 1: a hit builds the document from the re-read row through the same recordToDocument + schemaFor gate as reindex (the credential-class/internal withholding holds on the event path, pinned), a miss deletes the document. data.record.restored (RECORD_RESTORED_EVENT) takes the same path; no engine: no-where sources build from the payload, where sources are skipped with one warn per source; syncs of one document (upserts and deletes) run through an in-process promise chain dropped when idle. Item 6 measured: created/updated publish inside the write's own unit or a caller's transaction, before commit (engine-insert.ts:386/1716, engine-update.ts:529/2445); publish awaits the in-process adapter, which awaits each subscriber (engine-realtime-publish.ts:484, in-memory-realtime-adapter.ts:98), and the re-read takes the ambient transaction (engine-driver-options.ts:304-306), so it sees the uncommitted row; restored publishes after the restore's unit committed (restore.ts:451/470/756). Stated in a code comment on handleRecordUpsert and in knowledge.mdx section 6, which also drops a stale claim that bare record.* events are accepted.",
     "tests": "head 53f2e69c: pnpm --filter @objectstack/service-knowledge test -> VERDICT command-exit 0, Test Files 8 passed (8), Tests 117 passed (117) (event-sync-data-events 23, knowledge-service 28). typecheck -> VERDICT command-exit 0, check:test-typecheck OK 0 files/0 errors. Ablations via scripts/ablation-replace.mjs (anchor 1->0, blob changed, restored blob == HEAD, git diff HEAD empty; relative-path imports, no dist leg): where reduced to {id} -> 5/23 red; serialization removed -> 3/23 red (all three races); RECORD_RESTORED_EVENT dropped from the bridge -> 2/23 red (first attempt refused by the tool before running: replacement anchor non-unique, count did not move; re-run with a unique anchor); document from payload instead of re-read row -> 3/51 red across both files.",
     "gates": "local: dispatch-gates --commands (no paths) derived 100 families at 53f2e69c; 98 exit 0 (incl. check:system-context-census, check:query-options-erasure, check:where-matcher, check:objectql-double-limit, check:engine-double-contract, check:doc-authoring, check:issue-citations, check:nul-bytes); 2 exit 3 PREREQUISITE NOT MET = NOT MEASURED (spec check:skill-examples needs client-react dist; check:dual-build-cjs-loads needs every package dist), declared to CI. dispatch-gates --ran with exit codes: 100 derived, 98 run, 2 NOT-MEASURED, 0 UNRUN. overlap-check: VERDICT clean exit 0. CI at report time: PR check-runs in_progress (Check Changeset, Lint x8, Type Check x4, Governed Surface Queue Guard, Spec property liveness, PR-body guards), none concluded; not re-run locally.",
     "dogfood_battery": "n/a — no ! in the PR title and Clause-②: no without a (narrowing) arm",
     "line_budget": "+612 / -150 over 6 files (762 changed lines, under 3000)",
     "files_changed": [
      ".changeset/36991-knowledge-sync-where.md",
      "content/docs/protocol/knowledge.mdx",
      "packages/services/service-knowledge/src/__tests__/event-sync-data-events.test.ts",
      "packages/services/service-knowledge/src/__tests__/knowledge-service.test.ts",
      "packages/services/service-knowledge/src/knowledge-service-plugin.ts",
      "packages/services/service-knowledge/src/knowledge-service.ts"
     ],
     "deviations": "1) The empty-branch landing push (git push -u origin claude/issue-36991-knowledge-sync-where, before any edit) was refused by the auto-mode classifier ([Destructive or Unwanted Actions]); I continued locally and the same push command, now carrying the commits, went through once the work existed (one later attempt, same route, not a different route). 2) Two derived gates NOT MEASURED (exit 3, unbuilt packages outside the closure); test:repo and repo-wide lint left to CI. 3) knowledge.mdx line 55 wording record.* -> data.record.* and removal of the stale legacy-acceptance sentence ride inside the rewritten section (in file surface). Clause-② and Metadata-protocol lines copied unchanged; the diff agrees with them (no spec or authorable change).",
     "mcp_calls": "0",
     "api_writes": "2 relay strokes (POST /repos/objectstack-ai/objectstack/dispatches each): pr_create -> POST /pulls (draft) + POST /issues/37075/assignees [os-justin]; this report -> POST /issues/36991/comments via post-stamped.mjs",
     "open_questions": [
      {
       "question": "Under contentFields ['*'] the event-path document now carries every string field of the re-read row, exactly as reindexSource does for the same row. Is that the intended reading of the epic rule 'a source lists its content fields explicitly'?",
       "options": [
        "A keep parity with reindex; '*' is retired by the epic's row 3",
        "B under '*' project the re-read row to the keys the payload carried"
       ],
       "recommendation": "A, because B makes the document depend on which path wrote it and reintroduces the short-document defect this card removes; explicit lists are unchanged."
      }
     ],
     "security_findings": "none",
     "out_of_scope_findings": []
    }
  9. objectstack-fleet commented on Nov 24, 2026

    @objectstack-fleet
    Contributor

    repo:objectstack#4 · os-justin · session_01QSeKYpRrYuqSLCvbSk9zrL
    os-dev-report

    {
     "issue": 36991,
     "status": "done",
     "round": "patch round 2 (L1 REWORK 7141806791: D1, D2, S1, text only)",
     "branch": "claude/issue-36991-knowledge-sync-where",
     "pr": "https://github.com/objectstack-ai/objectstack/pull/37075",
     "head_sha": "4ab8a4ff2269b6ed0716c79b93f42607f131219d",
     "session": "session_01QSeKYpRrYuqSLCvbSk9zrL",
     "premise_still_valid": true,
     "summary": "Text only, no behaviour change. D1: the handleRecordUpsert JSDoc, knowledge.mdx section 6, the changeset and the PR body's first bullet now say the document carries the fields the source lists and the record title, never a credential-class or internal field. D2: the JSDoc, section 6, the changeset and the PR body's item-6 bullet now name both rollback outcomes: a matched uncommitted row leaves a document built from a row that never committed; an unmatched one deletes the document, so the committed row, which may still match, is missing from the index until its next event or a reindexSource. S1: one sentence in the JSDoc, section 6, the changeset and the PR body says a write's sync can wait behind an earlier in-flight sync of the same document (on a single-connection pool, up to the acquire timeout) and the index still ends consistent.",
     "tests": "head 4ab8a4ff: dependency closure rebuilt (VERDICT command-exit 0); pnpm --filter @objectstack/service-knowledge test -> VERDICT command-exit 0, Test Files 8 passed (8), Tests 117 passed (117). No ablation: no tested behaviour changed.",
     "gates": "local, on the text change: check:doc-authoring exit 0, check:nul-bytes exit 0, check:issue-citations exit 0, check-empty-changeset --base origin/main exit 0, docs-audit check-drift-comment exit 0; overlap-check VERDICT clean exit 0. The previous round's 100-family run (98 exit 0, 2 exit 3 NOT MEASURED) was not repeated: this round changes only comment, doc and changeset prose. CI at 4ab8a4ff when this was written: 5 success, 17 skipped, 24 in_progress, 0 failed.",
     "dogfood_battery": "n/a — no ! in the PR title, and Clause-②: no has no (narrowing) arm",
     "line_budget": "this round +30 / -13 over 3 files; PR total +629 / -150 (approx.) over 6 files, under 3000",
     "files_changed": [
      ".changeset/36991-knowledge-sync-where.md",
      "content/docs/protocol/knowledge.mdx",
      "packages/services/service-knowledge/src/knowledge-service.ts"
     ],
     "deviations": "PR body edit: the relay requires either a signature first line or the trailer as the last non-empty line, and line 1 is Fixes #36991. So the body ends with the session-URL footer (exactly once) followed by the signed trailer, an HTML comment. Read back identical (9011 bytes). The worktree removed after round 1 was re-created from the pushed branch at 53f2e69c. No command was refused this round.",
     "mcp_calls": "0",
     "api_writes": "2 relay strokes this round (POST /repos/objectstack-ai/objectstack/dispatches each): issue_patch body on #37075 (PATCH /issues/37075); this report (POST /issues/36991/comments via post-stamped.mjs). Not REST: one git push 53f2e69c..4ab8a4ff.",
     "open_questions": [],
     "security_findings": "none",
     "out_of_scope_findings": []
    }
  10. objectstack-fleet commented on Nov 24, 2026

    @objectstack-fleet
    Contributor

    repo:objectstack#4 · os-justin · session_01QSeKYpRrYuqSLCvbSk9zrL

    Delivered (2026-11-24T20:43Z): PR #37075 merged as eec6fb3 and closed this card. Area: a4-K.

  11. removed
    pm:dispatched
    on Nov 24, 2026
  12. added 2 commits that reference this issue on Dec 1, 2026
    eec6fb3
    3801775
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area:aipriority:p2

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions