Skip to content

Commit 959b20f

Browse files
fix(service-knowledge): a record write before the boot reads a runtime-composed knowledge service calls no store (#39414)
<!-- claude-projects-attribution: {"github_login":"os-bill"} --> _Requested by **Bill** · [project thread](https://claude.ai/code/project/chan_016iMXWSZDzqWRWvWzdNo8wg?thread=cmsg_016iMXWSZDzqWRWvWzdNo8wgNdLPCyWnpE5AwiFhzTdGe9)_ Fixes #38479 ## What changes `@objectstack/service-knowledge`: a record sync that arrives before the boot reads a runtime-composed knowledge service as enabled or held (ADR-0161 K8, the dated note on item 12) now waits for that reading and calls no store meanwhile. - A new `KnowledgeService` field, `enablementWaiters`, holds the waiting syncs. `settleEnablement` wakes them (`knowledge-service-sources.ts`). - Queue worker paths (`processRecordSync`, `processRecordSyncBatch`) await the reading before they resolve a message. - Inline paths (`handleRecordUpsert`, `handleRecordDelete`) are deferred past the reading and return at once. A write the boot itself awaits, such as a seed, would otherwise wait for a reading that comes after it. A deferred sync that fails is one `warn` line. - Once the reading is taken, held completes each sync with no store call (`not-synced` on the queue paths), and enabled runs it as before. A host-mounted service (`enabledByConfiguration` unset) has no window and is unchanged. - The logic lives in the facets (`knowledge-service-record-sync.ts`, `knowledge-service-sources.ts`). The facade gets one field and one host getter, so `check-facade-delegation-only` stays green. ## Why On a held deployment (no embedder), a seed written before `kernel:bootstrapped` reached the store. A fresh blank-template or Starter scaffold printed `WARN [knowledge] a batch of 4 record syncs of source 'blank-blank_articles' failed (knowledge-turso has no embedder …)`. That contradicts #38369's "no store is called" for a held service. This blocks #38374 (draft PR #39340), whose template `starter.test.ts` no-embedder case is red on this line alone. ## Verification - New `src/__tests__/boot-window-38479.test.ts` (4 cases): the held case and the enabled case are red on main and green here. The host-mounted control is green both ways. The fourth case is the card's second pin. On an enabled runtime-composed service, the reap guard is registered at the reading, before a sweep a later plugin runs at `kernel:bootstrapped`, and that sweep de-indexes before it deletes. - `@objectstack/service-knowledge`: vitest 34 files / 912 tests green on `origin/main` 301a378 + this diff. `pnpm typecheck` (incl. `check:test-typecheck`) green. `node scripts/check-facade-delegation-only.mjs` green (knowledge-service.ts 1696/1758 lines). eslint on the four touched files is clean. - #39340's blank-template `starter.test.ts`, run from a copy of the template against PR #39340's head `ca114a34` plus this diff: 6/6 green. Control: the same run with this diff's source reverted and the package rebuilt fails only the no-embedder case, on the exact WARN line above. `@objectstack/example-starter` tests 17/17 and the create-objectstack parity test 15/15 are green on the same tree. Clause-②: no Metadata-protocol: none ## Human Minimum - [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic. (not touched) - [x] 2. Every name I added uses the casing for its kind. - [x] 3. No formatter ran; `pnpm lint` passes. (eslint on the touched files) - [x] 4. One issue, one branch off an up-to-date `main`, one pull request. - [x] 5. A change that publishes carries a changeset, and both declaration lines are filled in here and in the changeset. - [x] 6. `packages/spec` touched: not touched. - [x] 7. No hand edits to `content/docs/references/`, `packages/*/CHANGELOG.md` or `content/docs/releases/`. - [x] 8. Title, body and comments are in English. - [x] The *Before Submitting* list in CONTRIBUTING.md is done. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01Utp6CYvu4t9zSjsTHiUubP --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 4eca9da commit 959b20f

7 files changed

Lines changed: 325 additions & 9 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
'@objectstack/service-knowledge': patch
3+
---
4+
5+
fix(service-knowledge): a record write before the boot reads a runtime-composed knowledge service calls no store
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
A knowledge service the runtime composes is read as enabled or held once, at `kernel:bootstrapped` (ADR-0161 K8, the dated note on item 12). A record write could land before that reading, such as a seed or a package's sample data on a new project's first boot, and its sync ran at once. On a deployment with no embedder this called the store, and the boot logged a `[knowledge] a batch of N record syncs of source … failed (… has no embedder …)` warning, although a held service calls no store.
11+
12+
Now a record sync that arrives before the reading waits for it, on every path: inline, and on the record-sync queue's per-message and batch paths. Nothing calls a store meanwhile. Once the reading is taken, a held service completes each sync without one, and an enabled service runs it as it did before. The inline sync never holds the write up: it is deferred past the reading, so a write the boot itself awaits does not wait on a reading that comes after it. A service a host mounts itself has no such window and syncs as before. If the service stops before the reading (a boot that failed first), every waiting sync completes without one, so the queue's worker is not left waiting at shutdown.
Lines changed: 205 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,205 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* [#38479, ADR-0161 K8, the dated note on item 12] A service the runtime
5+
* composed is read as enabled or held once, at `kernel:bootstrapped`. A record
6+
* write can land before that reading: a seed, or a package's sample data, on
7+
* a new project's first boot. Its sync — inline, on the queue's per-message
8+
* path or on its batch path — calls no store until the reading:
9+
*
10+
* - held (no embedder, or the deployment's store not mounted): each completes
11+
* without a sync, and no store is ever called for it;
12+
* - enabled: each runs once the reading is taken, as it would have before.
13+
*
14+
* The inline sync never holds the write up: a write the boot itself awaits
15+
* would otherwise wait for a reading that comes after it. A service a host
16+
* mounts itself has no such window and syncs at once, as it always did.
17+
*
18+
* The second half pins the reap guard on an enabled runtime-composed service:
19+
* it is registered at the reading, before the earliest sweep a host can run
20+
* at `kernel:bootstrapped`, so that sweep de-indexes before it deletes.
21+
*/
22+
23+
import { describe, it, expect, vi } from 'vitest';
24+
import { LiteKernel } from '@objectstack/core';
25+
import type { Plugin, PluginContext } from '@objectstack/core';
26+
import type { KnowledgeSource } from '@objectstack/spec/ai';
27+
import type { IDataEngine, IKnowledgeAdapter } from '@objectstack/spec/contracts';
28+
import { KnowledgeService } from '../knowledge-service.js';
29+
import { KnowledgeServicePlugin } from '../knowledge-service-plugin.js';
30+
31+
/** The lifecycle service's guard shape, as `knowledge-reap-guard.ts` builds it. */
32+
type ReapGuard = (object: string, rows: Array<Record<string, unknown>>) => Promise<Array<string | number>>;
33+
34+
const SOURCE: KnowledgeSource = {
35+
name: 'kb',
36+
label: 'KB',
37+
adapter: 'vec',
38+
source: { kind: 'object', object: 'kb_article', content: ['body'] },
39+
};
40+
41+
function setup(opts: { runtimeComposed: boolean }) {
42+
const calls: string[] = [];
43+
const adapter: IKnowledgeAdapter = {
44+
id: 'vec',
45+
upsert: vi.fn(async () => { calls.push('upsert'); }),
46+
delete: vi.fn(async () => { calls.push('delete'); }),
47+
search: vi.fn(async () => { calls.push('search'); return []; }),
48+
};
49+
const rows: Record<string, unknown>[] = [{ id: 'r1', body: 'Seeded article' }];
50+
const engine = {
51+
find: vi.fn(async (_object: string, q: { where?: Record<string, unknown> } = {}) => {
52+
const ids = (q.where as { id?: { $in?: unknown[] } } | undefined)?.id?.$in;
53+
const wanted = (q.where as { id?: unknown } | undefined)?.id;
54+
return rows.filter((r) => (ids ? ids.includes(r.id) : typeof wanted === 'string' ? r.id === wanted : true));
55+
}),
56+
findOne: vi.fn(async () => rows[0]),
57+
} as unknown as IDataEngine;
58+
const warn = vi.fn();
59+
const service = new KnowledgeService({
60+
dataEngine: engine,
61+
logger: { warn, debug: () => undefined, info: () => undefined },
62+
...(opts.runtimeComposed ? { enabledByConfiguration: true } : {}),
63+
});
64+
service.registerAdapter('vec', adapter);
65+
service.registerSource(SOURCE);
66+
return { service, adapter, calls, warn };
67+
}
68+
69+
const MESSAGE = { source: 'kb', object: 'kb_article', recordId: 'r1', reason: 'event' };
70+
71+
/** Let every queued promise settle. */
72+
const settle = () => new Promise((resolve) => setTimeout(resolve, 0));
73+
74+
describe('[#38479] a record write before the boot reads a runtime-composed service calls no store', () => {
75+
it('held: the inline sync, a queued message and a queued batch wait, then complete without a sync; no store is called', async () => {
76+
const { service, calls, warn } = setup({ runtimeComposed: true });
77+
78+
// Inline: the write is not held up.
79+
await expect(service.handleRecordUpsert('kb_article', { id: 'r1', body: 'Seeded article' })).resolves.toBeUndefined();
80+
await expect(service.handleRecordDelete('kb_article', 'r0')).resolves.toBeUndefined();
81+
// The queue's worker took the messages before the reading.
82+
const one = service.processRecordSync(MESSAGE);
83+
const batch = service.processRecordSyncBatch([{ data: MESSAGE }]);
84+
await settle();
85+
expect(calls).toEqual([]);
86+
87+
service.settleEnablement({ embedder: 'no embedder provider is saved' });
88+
89+
await expect(one).resolves.toBe('not-synced');
90+
await expect(batch).resolves.toEqual([{ ok: true, outcome: 'not-synced' }]);
91+
await settle();
92+
expect(calls).toEqual([]);
93+
expect(warn).not.toHaveBeenCalled();
94+
});
95+
96+
it('enabled: the same syncs wait for the reading, then run as ever', async () => {
97+
const { service, adapter, calls } = setup({ runtimeComposed: true });
98+
99+
await service.handleRecordUpsert('kb_article', { id: 'r1', body: 'Seeded article' });
100+
await service.handleRecordDelete('kb_article', 'r0');
101+
const one = service.processRecordSync(MESSAGE);
102+
await settle();
103+
expect(calls).toEqual([]);
104+
105+
service.settleEnablement(undefined);
106+
107+
await expect(one).resolves.toBe('synced');
108+
await vi.waitFor(() => expect(vi.mocked(adapter.delete)).toHaveBeenCalledWith(['kb:r0'], expect.anything()));
109+
const upserted = vi.mocked(adapter.upsert).mock.calls.flatMap(([docs]) => docs.map((d) => d.id));
110+
expect(upserted).toEqual(['kb:r1', 'kb:r1']);
111+
});
112+
113+
it('stopped before the reading (a boot that failed first): every waiting sync completes without one, and none waits after', async () => {
114+
const { service, calls } = setup({ runtimeComposed: true });
115+
116+
await service.handleRecordUpsert('kb_article', { id: 'r1', body: 'Seeded article' });
117+
const one = service.processRecordSync(MESSAGE);
118+
const batch = service.processRecordSyncBatch([{ data: MESSAGE }]);
119+
await settle();
120+
121+
service.stopBuilds();
122+
123+
await expect(one).resolves.toBe('not-synced');
124+
await expect(batch).resolves.toEqual([{ ok: true, outcome: 'not-synced' }]);
125+
// A message taken after the stop does not wait either.
126+
await expect(service.processRecordSync(MESSAGE)).resolves.toBe('not-synced');
127+
await settle();
128+
expect(calls).toEqual([]);
129+
});
130+
131+
it('control: a service a host mounts itself syncs at once, as it always did', async () => {
132+
const { service, adapter } = setup({ runtimeComposed: false });
133+
await service.handleRecordUpsert('kb_article', { id: 'r1', body: 'Seeded article' });
134+
expect(adapter.upsert).toHaveBeenCalledOnce();
135+
await expect(service.processRecordSync(MESSAGE)).resolves.toBe('synced');
136+
});
137+
});
138+
139+
/** The earliest sweep a host can run: in its own `kernel:bootstrapped` handler, registered after the knowledge plugin's. */
140+
class BootSweepPlugin implements Plugin {
141+
name = 'test.boot-sweep';
142+
version = '1.0.0';
143+
type = 'standard' as const;
144+
dependencies = ['com.objectstack.service.knowledge'];
145+
constructor(private readonly order: string[], private readonly guards: Array<ReapGuard>) {}
146+
async init(): Promise<void> {}
147+
async start(ctx: PluginContext): Promise<void> {
148+
ctx.hook('kernel:bootstrapped', async () => {
149+
this.order.push(`sweep (guards: ${this.guards.length})`);
150+
for (const guard of this.guards) await guard('kb_article', [{ id: 'k1' }]);
151+
});
152+
}
153+
}
154+
155+
describe('[#38479] the reap guard of an enabled runtime-composed service is registered before the first sweep', () => {
156+
it('registered at the reading, so a sweep at kernel:bootstrapped de-indexes before it deletes', async () => {
157+
const order: string[] = [];
158+
const guards: Array<ReapGuard> = [];
159+
const deletedDocs: string[] = [];
160+
const lifecycle = {
161+
registerReapGuard: vi.fn((object: string, guard: ReapGuard) => {
162+
order.push(`guard ${object}`);
163+
guards.push(guard);
164+
}),
165+
};
166+
const adapter: IKnowledgeAdapter = {
167+
id: 'vec',
168+
upsert: async () => undefined,
169+
delete: async (ids: string[]) => { deletedDocs.push(...ids); },
170+
search: async () => [],
171+
};
172+
const kernel = new LiteKernel();
173+
kernel.use({
174+
name: 'test.lifecycle-and-embedder',
175+
version: '1.0.0',
176+
async init(ctx: PluginContext) {
177+
ctx.registerService('lifecycle', lifecycle);
178+
ctx.registerService('embedder', { id: 'own', dimensions: 2, embed: async (t: string[]) => t.map(() => [1, 0]) });
179+
},
180+
} as Plugin);
181+
kernel.use(new KnowledgeServicePlugin({
182+
sources: [{ ...SOURCE, adapter: undefined }],
183+
deploymentAdapter: 'vec',
184+
runtimeComposed: { declared: false },
185+
buildAtBoot: false,
186+
reconcile: false,
187+
}));
188+
kernel.use({
189+
name: 'test.deployment-store',
190+
version: '1.0.0',
191+
dependencies: ['com.objectstack.service.knowledge'],
192+
async init() {},
193+
async start(ctx: PluginContext) {
194+
ctx.getService<KnowledgeService>('knowledge').registerAdapter('vec', adapter);
195+
},
196+
} satisfies Plugin);
197+
kernel.use(new BootSweepPlugin(order, guards));
198+
await kernel.bootstrap();
199+
200+
expect(kernel.getService<KnowledgeService>('knowledge').heldReading()).toBeUndefined();
201+
expect(order).toEqual(['guard kb_article', 'sweep (guards: 1)']);
202+
expect(deletedDocs).toEqual(['kb:k1']);
203+
await kernel.shutdown();
204+
});
205+
});

‎packages/services/service-knowledge/src/knowledge-service-indexing.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ export interface KnowledgeIndexingHost {
109109
readonly buildUnderLease: KnowledgeService['buildUnderLease'];
110110
readonly builds: KnowledgeService['builds'];
111111
buildsStopped: KnowledgeService['buildsStopped'];
112+
readonly enablementWaiters: KnowledgeService['enablementWaiters'];
112113
readonly cancelPendingReconcile: KnowledgeService['cancelPendingReconcile'];
113114
readonly clearRepairedFailures: KnowledgeService['clearRepairedFailures'];
114115
readonly closeStaleBuild: KnowledgeService['closeStaleBuild'];
@@ -1277,9 +1278,13 @@ export async function buildIfDue(
12771278

12781279
/** The body of {@link KnowledgeService.stopBuilds}; the member's docblock there is its contract. */
12791280
export function stopBuilds(
1280-
this: Pick<KnowledgeIndexingHost, 'buildsStopped' | 'cancelPendingReconcile' | 'pendingReconciles'>,
1281+
this: Pick<KnowledgeIndexingHost, 'buildsStopped' | 'cancelPendingReconcile' | 'enablementWaiters' | 'pendingReconciles'>,
12811282
): void {
12821283
this.buildsStopped = true;
1284+
// [#38479] A record sync still waiting for the boot's enablement reading
1285+
// (a boot that failed before it) completes without a sync, so the queue's
1286+
// worker is not left waiting while it is unsubscribed.
1287+
for (const wake of this.enablementWaiters.splice(0)) wake(false);
12831288
for (const key of [...this.pendingReconciles.keys()]) this.cancelPendingReconcile(key);
12841289
}
12851290

‎packages/services/service-knowledge/src/knowledge-service-record-sync.ts‎

Lines changed: 69 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ export interface KnowledgeRecordSyncHost {
9393
readonly considerBacklogReconcile: KnowledgeService['considerBacklogReconcile'];
9494
readonly coveredByBuild: KnowledgeService['coveredByBuild'];
9595
readonly deadLettersOf: KnowledgeService['deadLettersOf'];
96+
readonly enablementPending: KnowledgeService['enablementPending'];
97+
readonly enablementWaiters: KnowledgeService['enablementWaiters'];
9698
readonly enqueueReconcile: KnowledgeService['enqueueReconcile'];
9799
readonly handed: KnowledgeService['handed'];
98100
readonly held: KnowledgeService['held'];
@@ -386,12 +388,41 @@ export function publishRecordSyncs(
386388
else send();
387389
}
388390

391+
/**
392+
* [#38479, ADR-0161 K8] A service the runtime composed is neither held nor
393+
* enabled until the boot reads it at `kernel:bootstrapped`
394+
* (`KnowledgeService.settleEnablement`), and a record write can land before
395+
* that: a seed, or a package's sample data. A record sync that arrives in that
396+
* window waits for the reading and calls no store meanwhile; once it is read,
397+
* held completes the sync without one and enabled runs it as ever. The answer
398+
* is `undefined` when there is nothing to wait for: a service a host mounts
399+
* itself, and one whose reading is settled. Otherwise it resolves `true` once
400+
* the reading is taken, or `false` when the service stops first
401+
* (`KnowledgeService.stopBuilds`, a boot that failed before the reading):
402+
* the sync then completes without one, so a stopping worker never waits on a
403+
* reading that will not come.
404+
*/
405+
function enablementSettled(
406+
host: Pick<KnowledgeRecordSyncHost, 'buildsStopped' | 'enablementPending' | 'enablementWaiters'>,
407+
): Promise<boolean> | undefined {
408+
if (!host.enablementPending) return undefined;
409+
if (host.buildsStopped) return Promise.resolve(false);
410+
return new Promise<boolean>((wake) => host.enablementWaiters.push(wake));
411+
}
412+
389413
/** The body of {@link KnowledgeService.processRecordSync}; the member's docblock there is its contract. */
390414
export async function processRecordSync(
391-
this: Pick<KnowledgeRecordSyncHost, 'adapterFor' | 'recordSyncTails' | 'resolveRecordSync' | 'syncRow'>,
415+
this: Pick<
416+
KnowledgeRecordSyncHost,
417+
'adapterFor' | 'buildsStopped' | 'enablementPending' | 'enablementWaiters' | 'recordSyncTails' |
418+
'resolveRecordSync' | 'syncRow'
419+
>,
392420
data: unknown,
393421
publishedAt?: number,
394422
): Promise<KnowledgeRecordSyncOutcome> {
423+
// [#38479] The worker may take a message before the boot's reading: it
424+
// waits for it, so a held deployment calls no store for it.
425+
if ((await enablementSettled(this)) === false) return 'not-synced';
395426
const resolved = this.resolveRecordSync(data, publishedAt);
396427
if ('outcome' in resolved) return resolved.outcome;
397428
const { source, message, engine } = resolved;
@@ -493,9 +524,16 @@ export function coveredByBuild(
493524

494525
/** The body of {@link KnowledgeService.processRecordSyncBatch}; the member's docblock there is its contract. */
495526
export async function processRecordSyncBatch(
496-
this: Pick<KnowledgeRecordSyncHost, 'considerBacklogReconcile' | 'resolveRecordSync' | 'syncRecordGroup'>,
527+
this: Pick<
528+
KnowledgeRecordSyncHost,
529+
'buildsStopped' | 'considerBacklogReconcile' | 'enablementPending' | 'enablementWaiters' | 'resolveRecordSync' |
530+
'syncRecordGroup'
531+
>,
497532
batch: readonly KnowledgeRecordSyncBatchItem[],
498533
): Promise<KnowledgeRecordSyncBatchResult[]> {
534+
// [#38479] As on the per-message path: a batch taken before the boot's
535+
// reading waits for it.
536+
if ((await enablementSettled(this)) === false) return batch.map(() => ({ ok: true, outcome: 'not-synced' }));
499537
const results: KnowledgeRecordSyncBatchResult[] = new Array(batch.length);
500538
const groups = new Map<string, RecordSyncGroup>();
501539
batch.forEach((item, index) => {
@@ -837,10 +875,22 @@ export async function syncRows(
837875

838876
/** The body of {@link KnowledgeService.handleRecordUpsert}; the member's docblock there is its contract. */
839877
export async function handleRecordUpsert(
840-
this: Pick<KnowledgeRecordSyncHost, 'held' | 'serializeRecordSync' | 'sourcesForObject' | 'syncRecord'>,
878+
this: Pick<
879+
KnowledgeRecordSyncHost,
880+
'buildsStopped' | 'enablementPending' | 'enablementWaiters' | 'held' | 'options' | 'serializeRecordSync' |
881+
'sourcesForObject' | 'syncRecord'
882+
>,
841883
object: string,
842884
record: Record<string, unknown>,
843885
): Promise<void> {
886+
// [#38479] Before the boot's reading the sync is deferred past it and the
887+
// write is not held up: a write the boot itself awaits (a seed) would
888+
// otherwise wait for a reading that comes after it.
889+
const settled = enablementSettled(this);
890+
if (settled) {
891+
void settled.then((go) => (go ? handleRecordUpsert.call(this, object, record) : undefined)).catch((err: unknown) => deferredSyncFailed(this, object, err));
892+
return;
893+
}
844894
if (this.held) return;
845895
const recordId = record.id;
846896
for (const source of this.sourcesForObject(object)) {
@@ -1008,15 +1058,30 @@ export function schemaFor(this: Pick<KnowledgeRecordSyncHost, 'options'>, object
10081058
}
10091059
}
10101060

1061+
/** A record sync deferred past the boot's reading that failed where nothing awaits it: one `warn` line. */
1062+
function deferredSyncFailed(host: Pick<KnowledgeRecordSyncHost, 'options'>, object: string, err: unknown): void {
1063+
host.options.logger?.warn?.(
1064+
`[knowledge] a record sync of object '${object}' deferred past the boot's enablement reading failed: ` +
1065+
`${err instanceof Error ? err.message : String(err)}`,
1066+
);
1067+
}
1068+
10111069
/** The body of {@link KnowledgeService.handleRecordDelete}; the member's docblock there is its contract. */
10121070
export async function handleRecordDelete(
10131071
this: Pick<
10141072
KnowledgeRecordSyncHost,
1015-
'adapterFor' | 'held' | 'label' | 'options' | 'planIndex' | 'serializeRecordSync' | 'sourcesForObject'
1073+
'adapterFor' | 'buildsStopped' | 'enablementPending' | 'enablementWaiters' | 'held' | 'label' | 'options' | 'planIndex' |
1074+
'serializeRecordSync' | 'sourcesForObject'
10161075
>,
10171076
object: string,
10181077
recordId: string,
10191078
): Promise<void> {
1079+
// [#38479] Deferred past the boot's reading, as {@link handleRecordUpsert}.
1080+
const settled = enablementSettled(this);
1081+
if (settled) {
1082+
void settled.then((go) => (go ? handleRecordDelete.call(this, object, recordId) : undefined)).catch((err: unknown) => deferredSyncFailed(this, object, err));
1083+
return;
1084+
}
10201085
if (this.held) return;
10211086
const targets = this.sourcesForObject(object);
10221087
for (const source of targets) {

‎packages/services/service-knowledge/src/knowledge-service-sources.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ export interface KnowledgeSourcesHost {
7979
readonly cancelPendingReconcile: KnowledgeService['cancelPendingReconcile'];
8080
readonly describeSources: KnowledgeService['describeSources'];
8181
enablementPending: KnowledgeService['enablementPending'];
82+
readonly enablementWaiters: KnowledgeService['enablementWaiters'];
8283
readonly forget: KnowledgeService['forget'];
8384
held: KnowledgeService['held'];
8485
readonly label: KnowledgeService['label'];
@@ -97,11 +98,17 @@ export interface KnowledgeSourcesHost {
9798

9899
/** The body of {@link KnowledgeService.settleEnablement}; the member's docblock there is its contract. */
99100
export function settleEnablement(
100-
this: Pick<KnowledgeSourcesHost, 'cancelPendingReconcile' | 'enablementPending' | 'held' | 'pendingReconciles'>,
101+
this: Pick<
102+
KnowledgeSourcesHost,
103+
'cancelPendingReconcile' | 'enablementPending' | 'enablementWaiters' | 'held' | 'pendingReconciles'
104+
>,
101105
held: KnowledgeHeldReading | undefined,
102106
): void {
103107
this.enablementPending = false;
104108
this.held = held;
109+
// [#38479] The record syncs that waited for this reading go on now: held,
110+
// each completes without a sync; enabled, each runs.
111+
for (const wake of this.enablementWaiters.splice(0)) wake(true);
105112
if (!held) return;
106113
for (const key of [...this.pendingReconciles.keys()]) this.cancelPendingReconcile(key);
107114
}

0 commit comments

Comments
 (0)