Repository navigation
feat(service-knowledge): adapters list their documents; a complete reindex skips unchanged documents and purges stale ones; adapter contract suite - #37164
Conversation
…e, adapter contract suite Claude-Session: https://claude.ai/code/session_01QSeKYmGV9ehU2Bfmw95h7E Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QSeKYmGV9ehU2Bfmw95h7E Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QSeKYmGV9ehU2Bfmw95h7E Co-authored-by: Claude <noreply@anthropic.com>
…ce and reference docs for the knowledge members Claude-Session: https://claude.ai/code/session_01QSeKYmGV9ehU2Bfmw95h7E Co-authored-by: Claude <noreply@anthropic.com>
…o the tenant-audit census can place them Claude-Session: https://claude.ai/code/session_01QSeKYmGV9ehU2Bfmw95h7E Co-authored-by: Claude <noreply@anthropic.com>
📓 Docs Drift CheckThis PR changes 4 package(s): 3 hand-written doc(s) NAME something this change touched and may need an implementation-accuracy re-verification:
⛔ 1 release-owned page(s) also name something this change touched. These are read-only:
What this run could not see
Coarse fallback — 176 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): Which tree this was computed onThis run read A worktree cut from an older # while this PR is open — GitHub drops the merge commit once it closes
git fetch origin 164927445888f8160ba55bff05a7c6a1671a4285 && git checkout 164927445888f8160ba55bff05a7c6a1671a4285
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin 0a1b69c0b196ae3785c7c6b8027e80fe774d0165 8ba26077dea4ad94150c04d21ccf32190ee001dc && git checkout -B drift-repro 0a1b69c0b196ae3785c7c6b8027e80fe774d0165 && git merge --no-ff 8ba26077dea4ad94150c04d21ccf32190ee001dc
node scripts/docs-audit/affected-docs.mjs --json 0a1b69c0b196ae3785c7c6b8027e80fe774d0165
|
…e-ragflow aliases the ./testing subpath File surface extended by the dispatching zone (card What 4; check:test-source-alias). Claude-Session: https://claude.ai/code/session_01QSeKYmGV9ehU2Bfmw95h7E Co-authored-by: Claude <noreply@anthropic.com>
…ec takes minor Claude-Session: https://claude.ai/code/session_01QSeKYmGV9ehU2Bfmw95h7E Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QSeKYmGV9ehU2Bfmw95h7E Co-authored-by: Claude <noreply@anthropic.com>
…sh instead of replacing it Claude-Session: https://claude.ai/code/session_01QSeKYmGV9ehU2Bfmw95h7E Co-authored-by: Claude <noreply@anthropic.com>
|
repo:objectstack#4 · os-justin · session_01QSeKYpEsWWE9Y5YtSsDgqZ Contract reviewServed-tier: First review of this PR. Inputs read: card #37096 (body and its three comments: triage 7143730265, claim 7147400808, dev report 7148521174), the PR body at this head, the full diff from the merge base ① Derived judgmentsAccept sets and published types, each read at this head:
Declared-and-enforced (ADR-0049), for
The
Behaviour that moves for an existing caller: over an adapter with ② Semver level
③ Boundary flags
④ Design judgment
The purge against the card's acceptance: candidates are listed-before minus seen; the purge is skipped on S1 (should-fix) — the per-document chain around the purge has no pin. S2 (should-fix) — the purge's re-read compares the id as text, and that is a real miss on two shipped drivers. Read through:
Nits: N1 (nit) — the spec JSDoc on N2 (nit) — N3 (nit) — N4 (nit) — N5 (nit) — the skip keys on content, title and metadata. A change of embedder or split leaves every Tests that pin the new behaviour, read for ablation:
Implemented-by: VERDICT: PASS |
|
repo:objectstack#4 · os-justin · session_01QSeKYpEsWWE9Y5YtSsDgqZ 席位核对 — REWORK · L1 · head
|
…er, finds numeric ids by number; pin its sync chain Claude-Session: https://claude.ai/code/session_01QSeKYmGV9ehU2Bfmw95h7E Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QSeKYmGV9ehU2Bfmw95h7E Co-authored-by: Claude <noreply@anthropic.com>
|
repo:objectstack#4 · os-justin · session_01QSeKYpEsWWE9Y5YtSsDgqZ Contract reviewServed-tier: Delta review. Prior record: 7151166003 at ① Derived judgmentsAccept sets and published types against the prior record:
Behaviour that moves in the delta, each read at this head:
Is the numeric re-ask safe:
② Semver level
③ Boundary flags
④ Design judgmentPrior S1 (the chain around the purge had no pin): closed. The new case holds the purge's Prior S2 (the id compared as text missed on driver-mongodb and driver-memory): closed for those two drivers, by the first of the two ways the record offered. The new case uses rows with numeric ids over an engine double that compares with S1 (should-fix) — the number re-ask runs on every driver, and on the SQL dialects that compare a text column with a number numerically it has not been looked at. Read, not run:
Prior nits:
New nits: N1 (nit) — the event sync's new arm has no pin and no line in the protocol doc. A non-array answer to its re-read used to delete the document and now warns and keeps it (①). The dev's ablation of the re-read guard turned one case red, the purge one, so the event-sync half is held by nothing. One case on N2 (nit) — the chain case and the numeric case each wait on Tests that pin the delta, read for ablation:
Implemented-by: VERDICT: PASS |
|
repo:objectstack#4 · os-justin · session_01QSeKYpEsWWE9Y5YtSsDgqZ 席位核对 — ACCEPT · L1 · head
|
… limit; pin the event sync's keep; no clock in the purge tests Claude-Session: https://claude.ai/code/session_01QSeKYmGV9ehU2Bfmw95h7E Co-authored-by: Claude <noreply@anthropic.com>
|
repo:objectstack#4 · os-justin · session_01QSeKYpEsWWE9Y5YtSsDgqZ Contract reviewServed-tier: Delta review. Prior record: 7152394541 at ① Derived judgmentsAccept sets and published types against the prior record:
Behaviour that moves in the delta, each read at this head:
Is the purge direction stated truly, as a deletion, in each text:
The limit against the drivers it names, read, not run:
② Semver level
③ Boundary flags
④ Design judgmentPrior S1 (the number re-ask reached driver-sql, unexamined on MySQL, SQL Server and Oracle): closed, by the second of the two ways the record offered, and more thoroughly than that way asked: the re-ask is removed, not kept with a caveat. What is left is a limit on two drivers, in the opposite direction (a deletion where the prior head kept), and it is stated as a deletion in the TSDoc, the protocol doc, the changeset and the PR body, with #37221 filed. Is the stated limit enough at this head, or does it need more before landing:
Does the event sync's warn-and-keep contradict anything:
Prior nits:
New nits: N1 (nit) — the general sentences still read without exception. N2 (nit) — #37221 is named only in the PR body. The TSDoc, the mdx and the changeset state the limit in full and do not need the number, but the card has no label, so nothing but this PR's body leads to it. A label that puts it in the K8 backlog (epic #37000) would hold it. Tests that pin the delta, read for ablation:
No must-fix, no should-fix. Implemented-by: VERDICT: PASS |
|
repo:objectstack#4 · os-justin · session_01QSeKYpEsWWE9Y5YtSsDgqZ 席位核对 — ACCEPT · L1 · head
|
…owledge-list-purge
The os-regen driver kept the branch's side of the shard in the merge commit and step 2 took main's; gen:schema on the merged HEAD yields both: main's 56 entries (#37173) and this branch's ai/KnowledgeDocument:docHash. Claude-Session: https://claude.ai/code/session_01QSeKYmGV9ehU2Bfmw95h7E Co-authored-by: Claude <noreply@anthropic.com>
|
repo:objectstack#4 · os-justin · session_01QSeKYpRrYuqSLCvbSk9zrL Landing · zone a4-K · head
Ready for review, with auto-merge on. |
Fixes #37096
Clause-②: yes
Metadata-protocol: added
Skills-docs: none — no skill under
skills/**teachesKnowledgeDocument, the adapter contract or reindex;skills/objectstack-ai/SKILL.mdteachesKnowledgeSourceauthoring only.content/docs/protocol/knowledge.mdxgains the members, the skip and the purge in this change.维护者速读
What changes
ADR-0161 K8 items 1 and 2, each landing with its reader (ADR-0049):
Contract (
@objectstack/spec).IKnowledgeAdapter.listDocuments?(ctx, { cursor?, limit })→{ documents: { documentId, docHash? }[], nextCursor? }(new exported interfacesAdapterListDocumentsOptions,AdapterListedDocument,AdapterListDocumentsPage), andKnowledgeDocument.docHash?. Both optional; shapes exactly as K8's table.docHash(service).computeDocHash=v1:+ SHA-256 over{ content, title, metadata }serialized with every plain object's keys sorted. Stamped byrecordToDocument(walk and event sync) and byindexDocument, which refuses a caller-supplieddocHash(it throws, namingdocHashand that the service computes it) instead of replacing it.Skip (its reader).
reindexSourcelists the adapter's documents before the walk (paged,LIST_DOCUMENTS_PAGE_SIZE= 500, a repeated cursor refused); a document whose computed hash equals the listed one is not upserted (skipped). A listed entry with no hash reads as changed.Purge. One function,
purgeDocuments, exported from the service module for row 15's reconcile in this package (not re-exported from the package entry). It runs only after a complete walk (nolimit, nodryRun, no failed page), never forrefresh.onRecordChange: false, never withoutlistDocuments. Candidates = listed before the walk − seen in it. Each candidate is confirmed by the event sync's own re-read — extracted unchanged into one helper,rereadRow(whereAND id,limit: 1, system context), now called by both — and runs on the per-document record-sync chain, so an event sync of the same row cannot interleave between the re-read and the delete. A listed id the source does not derive (SOURCE:RECORD) is kept and counted inmessage. A walk page or a re-read that answers no list of rows is a failure, never "empty" or "no row": the walk stops (purged: null) or the purge stops (ok: false). The event sync sharesrereadRow, so on a non-list answer it now warns and keeps the document where it used to delete it (pinned). The re-read asks by the id text only; see the numeric-id limit in Acceptance notes.Result.
skippedandpurgedon every return ofreindexSource;purged: null= no purge ran. A failed listing: everything written, nothing purged,messagesays why, stillok: true. A failed purge step:ok: false,purged= deletions before it.knowledge-memoryimplementslistDocuments(id order, cursor = last id of the page before;docHashstored as given) — the reference implementation.Contract suite.
@objectstack/service-knowledge/testing→runKnowledgeAdapterContract({ name, makeAdapter, implements: { listDocuments } }): upsert / search / delete;listDocumentsat 0, one page, one page + 1,docHashas stored, source scoping; skip, purge, and no purge underlimit/dryRunthrough a realKnowledgeServiceover an engine double.implementsis asserted against the adapter, and an adapter withoutlistDocumentsruns thepurged: nullcase instead. Entry follows theservice-cluster/metadata-coreprecedent: owntsup.config.ts, ESM-only./testingexport (norequire),vitestexternal, not reachable from..knowledge-memoryruns it.Docs.
content/docs/protocol/knowledge.mdx(§3.2, §3.3, §3.4 with the suite, a new "Reindex: skip and purge" section, the stale-index callout and the predicate-write paragraph); the plugin's predicate-write warning text says the same. Regenerated:api-surface/contracts.json,export-origins/contracts.json,authorable-surface/ai.json,content/docs/references/ai/knowledge-document.mdx.KnowledgeReindexResult(@objectstack/spec) gains optionalskipped?: numberandpurged?: number | null(fields only added;null= no purge ran).knowledge-ragflowtest config gains the one anchored@objectstack/service-knowledge/testingalias ahead of its bare entry, ascheck:test-source-aliasprescribes; nothing else in that package.Deviations
packages/spec/src/contracts/knowledge-service.tsandpackages/plugins/knowledge-ragflow/vitest.config.ts, granted by the dispatching zone after the first report; both edits are exactly the two described above.pnpm testbefore opening was scoped to the three touched packages' builds, typechecks and suites plus the 131 derived gate families (below).Tests
build, typecheck and vitest (head 48ed4f1)
Ablations (committed first; ablation-replace, restored to the HEAD blob each time)
rereadRowline deleted): 3 red — "purges … each confirmed by a re-read", "a document written by the event sync during the walk survives the purge", "a purge whose re-read fails stops…". Restored: blob == HEAD,git diff HEADempty.knowledge-service.test.ts; 1 red in the contract suite onknowledge-memory("a second complete reindex skips every unchanged document…"). Restored both times.New cases:
computeDocHash(prefix, key-order stability at depth, sensitivity to content / title / metadata / array order), skip (all unchanged; only the changed row; entry without hash), listing paged to its end, purge of a deleted row and of a row that leftwherewith the exact re-readwheres, no purge underlimit/limit: 0/dryRun/ failed page, event-sync-created and restored documents survive,onRecordChange: false, failed listing, repeated cursor, failed re-read, foreign ids. Thirteen existing exact-result assertions gainedskipped: 0, purged: null(stub adapters withoutlistDocuments; otherwise unchanged).Acceptance notes
where, after the walk read past it, its document is deleted; the row is untouched and its document returns at its next event or the next complete reindex. A second re-read by the number was tried and removed: on driver-sql it binds a number against the textidcolumn, which MySQL compares numerically ('05'matches5) and SQL Server and Oracle reject, and no object schema types itsid, so the service cannot tell which objects have numeric ids. Stated inpurgeDocuments' TSDoc, the protocol doc and the changeset, and pinned by "the purge re-reads by the id text only".docHashand the metadata protocol:KnowledgeDocumentis referenced by no metadata-type schema, only by the adapter and service contracts, so no metadata author writes it; it shows on theauthorable-surfaceshard because that shard records the keys of every exportedai/schema (KnowledgeHit, equally runtime-only, is there too), andCheck Changesetreads any shard move as a protocol change, henceMetadata-protocol: addedand spec atminor. The key has its producer (the service) and its readers (the adapter stores and lists it; the reindex compares it), so it is not declared-but-unenforced.knowledge-memorystores no chunk for a document with empty content, so such a document is never listed: it is re-written on every reindex and never purged (the safe direction).Verification
Read first (risk order):
packages/services/service-knowledge/src/knowledge-service.ts(walkObjectSourceend,purgeDocuments,rereadRow);packages/services/service-knowledge/src/testing.ts;packages/services/service-knowledge/package.json+tsup.config.ts.Two minutes:
pnpm --filter @objectstack/knowledge-memory exec vitest run src/__tests__/contract.test.ts— expect 12 passed, the suite named "IKnowledgeAdapter contract — knowledge-memory".Local gates (head cf8b70a)
node scripts/pm/dispatch-gates.mjs --repo objectstack-ai/objectstack --ranat cf8b70a: 131 derived, 126 run, 5 NOT-MEASURED, 0 UNRUN (exit codes recorded before any pipe; the derived list is unchanged from c6e78ea).NOT MEASURED:
check-plugin-teardown-shape --self-test:: exit 3 — its pinned fixture commit is not in this shallow clone.spec check:skill-examples,check:dual-build-cjs-loads,check:published-readme-exports:: exit 3 — they read built output of packages this worktree did not build.check:dts-closure:: exit 1 — each run names the next package this worktree never built (service-cluster-redis, thenservice-i18n); the three touched packages' declarations are present and not listed.Everything else exit 0, including
check:test-source-alias,spec check:generated(all 14 up to date),check:tenant-audit-census,check:type-check-debt,check:query-options-erasure,check:slot-lookupandcheck-comment-mask-corpus(the last four rerun with a longer local time cap after the first sweep's cap fired),check:engine-double-contract,check:nul-bytes,check:doc-authoring. Local-only:check:skill-frame-freshnessexit 0.Patch round at eddd9a6 (changeset only:
@objectstack/spectominor,Metadata-protocol: added,Skills-docs:line):check-changeset-no-major --base MERGE_BASEagainst this body as the PR event exit 0 (level axis ✓);check-empty-changeset(self-test and base) exit 0;check-adr-0087-registration(self-test and base) exit 0;check:changeset-gate-self-testsexit 0; speccheck:generatedafter a spec build exit 0, all 14 up to date.Round at 58478ca (
indexDocumentrefuses a caller-supplieddocHash; TSDoc and changeset wording to match): typecheck service-knowledge and knowledge-memory exit 0; service-knowledge 8/8 files 165/165 tests, knowledge-memory 2/2 files 20/20; ablation (refusal disabled through ablation-replace): 1 failed, exactly "indexDocument refuses a caller-supplied docHash, naming it, and writes nothing", 75 passed, restored to the HEAD blob (a first attempt was void: the suite could not load before the closure was built in the fresh worktree); speccheck:generatedexit 0;check-changeset-no-majoragainst this body exit 0;check-empty-changeset,check-adr-0087-registration,check:nul-bytesexit 0; overlap-check clean.Round at ffc6bff (L1 REWORK 7151268664 S1–S4 and N1–N4; contract review 7151166003 S1–S2, N1–N3):
stopped(...);rereadRowthrows on a non-list answer; the purge asks for a canonical-integer id again by the number.git diff HEADempty: page guard madebreak→ 1 failed | 79 passed (the page test); re-read guard madereturn undefined→ 1 failed (the re-read test);serializemade a direct call → 1 failed (the chain test); numeric re-ask deleted → 1 failed (the numeric test).check:generatedexit 0 (all 14 up to date).dispatch-gates --ranat ffc6bff: 131 derived, 127 run, 4 NOT-MEASURED (exit 3:check-plugin-teardown-shape --self-test, pinned fixture not in this shallow clone;spec check:skill-examples,check:dual-build-cjs-loads,check:published-readme-exports, built output of packages this worktree did not build), 0 UNRUN;check:dts-closureexit 0; four commands that hit the local 100 s cap reran green with a longer one. Changeset gates against this body:check-changeset-no-majorexit 0,check-empty-changesetexit 0,check-adr-0087-registrationexit 0.content/docs/protocol/knowledge.mdxnow saysindexDocumentrefuses a carrieddocHash, and that a non-list answer stops the walk or the purge. Changeset reworded in plain terms;purgedTSDoc lists everynullcase and what an absent key means.Round at 48ed4f1 (L1 ACCEPT 7152441226 N1–N2; contract review 7152394541 S1 and N1–N2):
id, so the service cannot restrict it to numeric-id objects without new spec surface); the limit is stated inpurgeDocuments' TSDoc,knowledge.mdxand the changeset, and pinned by "the purge re-reads by the id text only: a numeric id restored mid-walk is not found (the stated limit)".knowledge.mdxand in the changeset, and pinned by "a re-read that answers no list leaves the document and warns once; it does not delete".setTimeout(5)in this PR's tests are gone. Two wait on the heldfindbeing entered (holdNextFind().reached). The chain case waits onesetImmediateturn, which lets every pending promise run with no clock involved. The remainingsetTimeout(5)is in the pre-existing "a second reindex of the same source waits" case (fix(service-knowledge): reindexSource pages an object source by id, one walk per source at a time #37129), which this PR does not touch.check:generatedexit 0.git diff HEADempty. Re-read guard madereturn undefined: 2 failed | 79 (the purge re-read case and the event-sync case).serializemade a direct call: 1 failed | 80 (the chain case, with the clock-free wait). Numeric re-ask re-added: 1 failed | 80 (the limit pin). A first numeric attempt was void because the replacement kept the anchor text; the tool refused it and restored the file.dispatch-gates --ranat 48ed4f1: 131 derived, 127 run, 4 NOT-MEASURED, 0 UNRUN. The same four exit-3 prerequisites as before. Three commands that hit the 100 s local cap reran exit 0.Generated by Claude Code