Repository navigation
Commit 3014176
fix(service-knowledge): widen the record-sync covered margin to the queue lease (#38577)
<!-- claude-projects-attribution: {"github_login":"os-project-manager"}
-->
_Requested by **Leehom** · [project
thread](https://claude.ai/code/project/chan_01TenzsRopZj4jMbvjX8uz1X?thread=cmsg_01TenzsRopZj4jMbvjX8uz1XDXvJPPtrTGfdDYhWWpihq5)_
Fixes #38556
Clause-②: no
Metadata-protocol: none
## 维护者速读
- 用户能看到什么变化:知识库在重建前 30 秒内收到的记录改动会照常同步,不再被当成“重建已覆盖”而跳过;普通使用者无感。
- 为什么做:知识库检索大项里批量同步评审标出的罕见竞态——向量服务很慢时,一次还没写完的旧同步可能在重建之后落盘,把旧内容留在索引里。
- 出错会怎样:最坏是这 30 秒窗口内的改动多做一次正常同步(多一点向量调用);只改一个内部常量与注释,可直接撤回。
- 要你做什么:无。
## Premise check
Holds at `main` (d08d2ae). `coveredByBuild` (`knowledge-service.ts`)
answers `covered` when `publishedAt < build.startedAt -
RECORD_SYNC_COVER_MARGIN_MS`, and the constant was `5_000` with a
docblock naming clock skew only. Nothing in `coveredByBuild` asks
whether a sync of the record is still in flight (and a sync on another
node is invisible to it), so a sync that re-read a record before a later
write and whose store write lands after the walk leaves the older
document, and the later write's message (published more than 5 s before
the build began) completes as `covered`.
## What changes
- `RECORD_SYNC_COVER_MARGIN_MS`: `5_000` → `30_000`, the queue adapter's
default message lease (`DbQueueAdapterOptions.leaseMs`).
- Its docblock names both guards (clock skew, a sync in flight), the
cost (a normal sync for messages inside the margin) and what stays
uncovered (a sync in flight longer than the margin, since a live handler
keeps renewing its lease; skew beyond what the sync's own time leaves of
the margin), and where it is repaired (the next purging build, ADR-0161
K1).
- No change to `IQueueService`, the build's purge, or the per-message /
batch paths outside `covered`.
## Choice and reasons
Widened, not documented-only:
- The only cost of a wider margin is a normal sync (one re-read, one
embed, one write) for messages published in the 25 s that move from
`covered` to synced; the backlog case `covered` exists for is messages
published long before the walk, which stay covered.
- 30 s moves the reach from "one sync slower than 5 s" (one slow
provider answer; the in-repo embedder neither retries nor bounds a
request) to "one sync slower than the lease a batch is sized to settle
well inside" (`QueueBatchSubscribeOptions.maxBatch`).
- A guard tied to the sync's own completion was considered: an
in-process tracker cannot see a sync on another node, and `covered` is
judged on the node that ran the build, so it would not be smaller and
would not close the cross-node case.
- The lease is not an exported constant (it is an inline default in
`service-queue`, which `service-knowledge` depends on only for tests),
so the value is written here and a test pins it equal to the adapter's
real default; exporting one from `service-queue` sat outside this card's
file surface.
## Tests
New `src/knowledge-record-sync-cover-margin.test.ts` (beside the source,
by the claim's file surface):
- the margin equals `DbQueueAdapter`'s default `leaseMs`;
- after a complete build that purged, a message published 10 s before
the build's start is `synced` on both the per-message and the batch
path, and repairs a document an in-flight sync wrote late;
- a message published more than the margin before the start is
`covered`, with no re-read.
<details><summary>Readings at ee44d49</summary>
- `pnpm --filter @objectstack/service-knowledge test`: Test Files 23
passed (23), Tests 784 passed (784).
- `pnpm --filter @objectstack/service-knowledge typecheck`: exit 0 (tsc
covers the new file, `--listFiles` 1 hit; `check:test-typecheck` OK).
- `dispatch-gates --commands` (67 families): 66 exit 0;
`check:dual-build-cjs-loads` exit 3, PREREQUISITE NOT MET (needs a
whole-repo build), NOT MEASURED locally, CI runs it. `--ran`
reconciliation: 67 accounted, 66 run, 1 NOT MEASURED.
- `check-nul-bytes`: OK.
</details>
## Ablation
`node scripts/ablation-replace.mjs` restoring `= 5_000;` on disk (anchor
1 → 0, blob changed), same test file: 2 failed / 1 passed — `expected
5000 to be 30000` (lease pin) and `expected 'covered' to be 'synced'`
(the inside-the-margin message). Restore verified: blob == HEAD, `git
diff HEAD` empty.
## Acceptance notes
- AGENTS.md asks a new pin for a component with a shared harness to go
into that harness file; the claim placed the test beside the source
because `src/__tests__/` is held by another in-flight claim. The harness
is duplicated in small; folding it into `knowledge-build.test.ts` later
is a follow-up for whoever holds that directory.
## Verification (two minutes)
`pnpm --filter @objectstack/service-knowledge exec vitest run
--maxWorkers=2 src/knowledge-record-sync-cover-margin.test.ts` — expect
3 passed.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01FEkQ5oQLfL8thb6wtUHnTb
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 1332e2c commit 3014176
3 files changed
Lines changed: 186 additions & 5 deletions
File tree
- .changeset
- packages/services/service-knowledge/src
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
209 | 209 | | |
210 | 210 | | |
211 | 211 | | |
212 | | - | |
213 | | - | |
214 | | - | |
215 | | - | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
216 | 233 | | |
217 | | - | |
| 234 | + | |
218 | 235 | | |
219 | 236 | | |
220 | 237 | | |
| |||
0 commit comments