From 8054ee1f5f7759a80c70b9aaa926f0c532b4d000 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 30 Nov 2026 16:27:50 +0000 Subject: [PATCH 1/3] feat(service-knowledge): index_status and rebuild say when the knowledge service is held Claude-Session: https://claude.ai/code/session_01ADHkmPDtfMCw4FJfyFfQ7v Co-authored-by: Claude --- .changeset/38369-held-status.md | 13 + content/docs/protocol/knowledge.mdx | 6 +- .../src/knowledge-source-unserved.test.ts | 3 + .../objectql/src/knowledge-source-unserved.ts | 19 +- .../src/__tests__/held-status-38369.test.ts | 238 ++++++++++++++++++ .../knowledge-settings-contribution.test.ts | 4 +- .../src/knowledge-build-actions.ts | 107 ++++++-- .../service-knowledge/src/knowledge-build.ts | 25 +- .../src/knowledge-service.ts | 6 +- 9 files changed, 393 insertions(+), 28 deletions(-) create mode 100644 .changeset/38369-held-status.md create mode 100644 packages/services/service-knowledge/src/__tests__/held-status-38369.test.ts diff --git a/.changeset/38369-held-status.md b/.changeset/38369-held-status.md new file mode 100644 index 00000000000..978ca808b15 --- /dev/null +++ b/.changeset/38369-held-status.md @@ -0,0 +1,13 @@ +--- +'@objectstack/service-knowledge': minor +'@objectstack/objectql': patch +--- + +feat(service-knowledge): index_status and rebuild say when the knowledge service is held + +Clause-②: yes (widening) +Metadata-protocol: none + +While the boot read a knowledge service the runtime composed as not enabled (no embedder, or the deployment's store not mounted), the `knowledge` settings actions say so. `index_status` answers each source's index as the new state `held` (not due) without asking its store, adds `enablement` — `state: 'not-enabled'`, the `reason` naming each missing half and its remedy, `embedder` / `store` for the missing halves, and `heldSources` — and its message leads with the reason and the held count. `rebuild` is refused (`ok: false`, which the settings door answers 400) with the service's own sentence: "Rebuild of source 'X' is refused: … To enable it, save an embedder provider, then restart." `os knowledge status` and `os knowledge rebuild` print both. A service a host mounts itself, and an enabled one, answer exactly as before. + +The boot line of a deployment that holds `knowledge_source` items and runs no knowledge service now names the embedder step its save refusal already names: declare `requires: ['knowledge']`, restart, then save an embedder provider and restart again. diff --git a/content/docs/protocol/knowledge.mdx b/content/docs/protocol/knowledge.mdx index b5fd954319a..51dad452a8f 100644 --- a/content/docs/protocol/knowledge.mdx +++ b/content/docs/protocol/knowledge.mdx @@ -225,7 +225,11 @@ no `search_knowledge` definition is handed out; `search`, `rebuildSource` and `reindexSource` answer `503 SERVICE_UNAVAILABLE` naming the missing half; a removed source keeps its index, and no store is called. The boot logs one line, `info` when only a shipped source mounted the service and nothing was saved, -`warn` otherwise, and never refuses to start. A change takes effect at the next +`warn` otherwise, and never refuses to start. The settings `index_status` +action answers each held source's index as `held`, without reading its store, +and adds `enablement`: not enabled, the reason with its remedy, and how many +sources are held. The `rebuild` action refuses the build with the same remedy, +and `os knowledge rebuild` exits 1 with it. A change takes effect at the next restart. A host-mounted service is not read this way and serves from the start. #### How a source is loaded diff --git a/packages/objectql/src/knowledge-source-unserved.test.ts b/packages/objectql/src/knowledge-source-unserved.test.ts index 0d1fc16f607..d093bdbfb27 100644 --- a/packages/objectql/src/knowledge-source-unserved.test.ts +++ b/packages/objectql/src/knowledge-source-unserved.test.ts @@ -23,6 +23,9 @@ describe('describeUnservedKnowledgeSources — items with no knowledge service ( expect(line).toContain('or remove the item.'); // The remedy an author's save on such a deployment is refused with: the token, then a restart. expect(line).toContain("Declare requires: ['knowledge'] in the stack and restart"); + // [ADR-0161 K8, the dated note on item 12] ...and, as the save's remedy does, the embedder step: the + // service the token mounts is held until a provider is saved and the server restarted once more. + expect(line).toContain("in the stack and restart, then save an embedder provider and restart again"); }); it(`names at most ${UNSERVED_KNOWLEDGE_SOURCES_NAMED} items, counts the rest, and says a name two packages hold once`, () => { diff --git a/packages/objectql/src/knowledge-source-unserved.ts b/packages/objectql/src/knowledge-source-unserved.ts index 2233cdb2d89..c327fd41793 100644 --- a/packages/objectql/src/knowledge-source-unserved.ts +++ b/packages/objectql/src/knowledge-source-unserved.ts @@ -20,7 +20,10 @@ * The remedy it names is the one an author's save is refused with on such a * deployment (`authoredKnowledgeSourceRefusal`, `@objectstack/metadata-core`): * `requires: ['knowledge']` in the stack, then a restart, since the service is - * composed at boot and never while the process runs. The items this line + * composed at boot and never while the process runs; then an embedder + * provider saved and one more restart, since a service the stack requires is + * enabled only with an embedder, and its embedder settings exist only once + * the service is mounted (ADR-0161 K8, the dated note on item 12). The items this line * finds are ones the stack does not ship, since a `knowledgeSources` entry * mounts the service by itself: they arrived by the engine's own write, * which is never refused (a package @@ -56,14 +59,16 @@ export function describeUnservedKnowledgeSources(names: readonly string[], servi } /** - * What mounts the service for an item on a deployment that runs none: the - * token (or the plugin, for a host that composes its own kernel), then a - * restart. The same remedy an author's save there is refused with. + * What mounts the service for an item on a deployment that runs none and + * serves the item: the token (or the plugin, for a host that composes its own + * kernel), a restart, then an embedder provider and one more restart. The + * same remedy an author's save there is refused with. */ const UNSERVED_REMEDY = - "Declare requires: ['knowledge'] in the stack and restart — the service and the deployment's store are mounted " + - 'at boot, never while the process runs — or, on a host that composes its own kernel, add KnowledgeServicePlugin ' + - '(@objectstack/service-knowledge) and a knowledge store;'; + "Declare requires: ['knowledge'] in the stack and restart, then save an embedder provider and restart again — " + + "the service and the deployment's store are mounted at boot, never while the process runs, and the service the " + + 'stack requires serves only once an embedder is configured — or, on a host that composes its own kernel, add ' + + 'KnowledgeServicePlugin (@objectstack/service-knowledge) and a knowledge store;'; /** What {@link announceUnservedKnowledgeSources} reads of its host. */ export interface UnservedKnowledgeSourcesHost { diff --git a/packages/services/service-knowledge/src/__tests__/held-status-38369.test.ts b/packages/services/service-knowledge/src/__tests__/held-status-38369.test.ts new file mode 100644 index 00000000000..6e9e9cc80a7 --- /dev/null +++ b/packages/services/service-knowledge/src/__tests__/held-status-38369.test.ts @@ -0,0 +1,238 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * [ADR-0161 K8, the dated note on item 12] The administrator's two knowledge + * actions say when the service is held. While the boot read a service the + * runtime composed as not enabled (no embedder, or the deployment's store not + * mounted): + * + * - `index_status` answers what it answers otherwise, plus `enablement` — the + * state, the reason with its remedy, the missing halves and how many + * sources are held — and its message leads with the state; + * - `rebuild` is refused (`ok: false`, which the settings door answers 400) + * with the service's own refusal of the build, naming the remedy, and no + * store is called. + * + * A service a host mounts itself, and an enabled one, answer as they always + * did: no `enablement`, the same message. The actions are run the way the + * settings page and `os knowledge status` / `os knowledge rebuild` reach + * them: through the settings service's action door. + * + * While held, `index_status` answers each source's index as `held` without + * asking its store: a held service calls no store, and a reading of the + * store would say a build is due that nothing will run. + */ + +import { createHash } from 'node:crypto'; +import { describe, it, expect } from 'vitest'; +import { LiteKernel } from '@objectstack/core'; +import type { Plugin, PluginContext } from '@objectstack/core'; +import { EMBEDDER_SERVICE, KNOWLEDGE_SERVICE } from '@objectstack/spec/contracts'; +import type { KnowledgeSource } from '@objectstack/spec/ai'; +import type { IEmbedder, IKnowledgeAdapter } from '@objectstack/spec/contracts'; +import { SettingsServicePlugin, type CryptoAdapter, type SettingsService } from '@objectstack/service-settings'; +import { KnowledgeServicePlugin } from '../knowledge-service-plugin.js'; +import { KnowledgeService } from '../knowledge-service.js'; +import { knowledgeIndexStatusActionHandler, type KnowledgeIndexStatusEnablement } from '../knowledge-build-actions.js'; + +/** The settings service stores the embedder key only through an adapter that declares confidentiality. */ +class ConfidentialTestAdapter implements CryptoAdapter { + readonly confidential = true; + async encrypt(plaintext: string): Promise { + return 'kms:' + Buffer.from(plaintext, 'utf8').toString('base64'); + } + async decrypt(ciphertext: string): Promise { + return Buffer.from(ciphertext.replace(/^kms:/, ''), 'base64').toString('utf8'); + } + digest(plaintext: string): string { + return createHash('sha256').update(plaintext).digest('hex'); + } +} + +/** The deployment's store (`id`), counting every call made to it. */ +class CountingStorePlugin implements Plugin { + name = 'test.knowledge.counting-store'; + version = '1.0.0'; + type = 'standard' as const; + dependencies = ['com.objectstack.service.knowledge']; + constructor(private readonly storeId: string, private readonly calls: string[]) {} + async init(): Promise {} + async start(ctx: PluginContext): Promise { + const calls = this.calls; + const adapter: IKnowledgeAdapter = { + id: this.storeId, + async upsert() { + calls.push('upsert'); + }, + async search() { + calls.push('search'); + return []; + }, + async delete() { + calls.push('delete'); + }, + async dropSource() { + calls.push('dropSource'); + }, + }; + ctx.getService(KNOWLEDGE_SERVICE).registerAdapter(this.storeId, adapter); + } +} + +/** A host's own embedder, registered at `init`. */ +class HostEmbedderPlugin implements Plugin { + name = 'test.host-embedder'; + version = '1.0.0'; + type = 'standard' as const; + async init(ctx: PluginContext): Promise { + const embedder: IEmbedder = { id: 'host-own', dimensions: 2, embed: async (t) => t.map(() => [0.6, 0.8]) }; + ctx.registerService(EMBEDDER_SERVICE, embedder); + } +} + +const SOURCES: KnowledgeSource[] = [ + { name: 'docs', label: 'Docs', source: { kind: 'object', object: 'doc', content: ['body'] } }, + { name: 'faq', label: 'FAQ', source: { kind: 'object', object: 'faq', content: ['answer'] } }, +]; + +async function boot(opts: { + /** Set ⇒ the runtime composed the service (`resolveCapabilityArgument`). */ + runtimeComposed?: { declared: boolean }; + /** Whether the deployment's store registers its adapter. @default true */ + storeMounted?: boolean; + /** Whether a host plugin registers an embedder. @default false */ + hostEmbedder?: boolean; +}) { + const calls: string[] = []; + const kernel = new LiteKernel(); + if (opts.hostEmbedder) kernel.use(new HostEmbedderPlugin()); + kernel.use(new KnowledgeServicePlugin({ + enableEventSync: false, + buildAtBoot: false, + reconcile: false, + deploymentAdapter: 'vec', + ...(opts.runtimeComposed ? { runtimeComposed: opts.runtimeComposed } : {}), + sources: SOURCES, + })); + kernel.use(new SettingsServicePlugin({ env: {}, registerRoutes: false, crypto: new ConfidentialTestAdapter() })); + if (opts.storeMounted !== false) kernel.use(new CountingStorePlugin('vec', calls)); + await kernel.bootstrap(); + const knowledge = kernel.getService(KNOWLEDGE_SERVICE); + const settings = kernel.getService('settings'); + const run = (action: 'index_status' | 'rebuild', payload: unknown) => settings.runAction('knowledge', action, payload); + return { kernel, knowledge, calls, run }; +} + +const enablementOf = (details: unknown): KnowledgeIndexStatusEnablement | undefined => + (details as { enablement?: KnowledgeIndexStatusEnablement }).enablement; + +describe('[ADR-0161 K8, note on item 12] index_status states a held service: not enabled, why, how many sources', () => { + it('no embedder: the state, the reason naming the remedy, the embedder half and every held source', async () => { + const { knowledge, run, calls } = await boot({ runtimeComposed: { declared: false } }); + expect(knowledge.heldReading()).toBeDefined(); + + const answer = await run('index_status', {}); + expect(answer.ok).toBe(true); + const enablement = enablementOf(answer.details); + expect(enablement).toEqual({ + state: 'not-enabled', + reason: expect.stringMatching(/^\[knowledge\] the knowledge service is not enabled on this deployment: no embedder is configured/), + embedder: expect.stringContaining('ai.embedder_provider'), + heldSources: 2, + }); + expect(enablement?.reason).toContain('To enable it, save an embedder provider, then restart.'); + expect(enablement?.reason).not.toContain('knowledge store'); + // The message leads with the state and counts the held sources. + expect(answer.message).toBe(`${enablement?.reason} 2 source(s) held.`); + // Every source is still listed, as on an enabled service. + expect((answer.details as { sources: Array<{ id: string }> }).sources.map((s) => s.id)).toEqual(['docs', 'faq']); + + // One source named: its entry alone, and the service's held count all the same. + const one = await run('index_status', { source: 'docs' }); + expect((one.details as { sources: Array<{ id: string }> }).sources.map((s) => s.id)).toEqual(['docs']); + expect(enablementOf(one.details)?.heldSources).toBe(2); + expect(calls).toEqual([]); + }); + + it("the store not mounted as well: both halves, and the reason names the store's remedy", async () => { + const { run } = await boot({ runtimeComposed: { declared: false }, storeMounted: false }); + const enablement = enablementOf((await run('index_status', {})).details); + expect(enablement).toMatchObject({ state: 'not-enabled', store: 'vec', embedder: expect.any(String), heldSources: 2 }); + expect(enablement?.reason).toContain("the deployment's knowledge store 'vec' is not mounted"); + expect(enablement?.reason).toContain("save an embedder provider and mount the deployment's knowledge store, then restart."); + }); + + it('a host-mounted service with no embedder, and an enabled runtime-composed one, answer no enablement and the same message', async () => { + for (const opts of [{}, { runtimeComposed: { declared: false }, hostEmbedder: true }]) { + const { knowledge, run } = await boot(opts); + expect(knowledge.heldReading(), JSON.stringify(opts)).toBeUndefined(); + const answer = await run('index_status', {}); + expect(answer.ok).toBe(true); + expect(Object.keys(answer.details as object), JSON.stringify(opts)).not.toContain('enablement'); + expect(answer.message, JSON.stringify(opts)).toMatch(/^2 source\(s\): \d+ need a build, 0 building, 0 with failed syncs\.$/); + } + }); +}); + +describe('[ADR-0161 K8, note on item 12] rebuild is refused on a held service, with the remedy', () => { + it("refused (ok: false), the service's own sentence naming the remedy, and no store is called", async () => { + const { run, calls } = await boot({ runtimeComposed: { declared: false } }); + const answer = await run('rebuild', { source: 'docs' }); + expect(answer).toMatchObject({ ok: false, severity: 'error', details: { source: 'docs', build: null } }); + expect(answer.message).toMatch( + /^Rebuild of source 'docs' is refused: \[knowledge\] the knowledge service is not enabled on this deployment: no embedder is configured/, + ); + expect(answer.message).toContain('To enable it, save an embedder provider, then restart.'); + expect(calls).toEqual([]); + }); + + it('an enabled runtime-composed service is not refused', async () => { + const { run } = await boot({ runtimeComposed: { declared: false }, hostEmbedder: true }); + const answer = await run('rebuild', { source: 'docs' }); + expect(answer.message ?? '').not.toContain('is refused'); + expect(answer.message ?? '').not.toContain('not enabled'); + }); +}); + +describe('[ADR-0161 K8, note on item 12] a held index_status asks no store what it holds', () => { + /** A service with a data engine bound, so its index reading reaches the store; the store counts every call. */ + function service(held: boolean) { + const calls: string[] = []; + const dataEngine = { find: async () => [], findOne: async () => null, count: async () => 0 } as never; + const knowledge = new KnowledgeService({ dataEngine, deploymentAdapter: 'vec', enabledByConfiguration: true }); + const adapter: IKnowledgeAdapter = { + id: 'vec', + async upsert() { calls.push('upsert'); }, + async search() { calls.push('search'); return []; }, + async delete() { calls.push('delete'); }, + async indexStatus() { + calls.push('indexStatus'); + return { fingerprint: 'built-under-another-model', recipeHash: 'r' }; + }, + }; + knowledge.registerAdapter('vec', adapter); + knowledge.registerSource(SOURCES[0]!); + knowledge.settleEnablement(held ? { embedder: 'ai.embedder_provider is not saved' } : undefined); + const status = knowledgeIndexStatusActionHandler(knowledge); + const read = () => status({ namespace: 'knowledge', actionId: 'index_status', values: {}, payload: {}, ctx: {} } as never); + return { calls, read }; + } + + it('held, the store mounted: the index reads held, not due, and the store is never called', async () => { + const { calls, read } = service(true); + const answer = await read(); + const [entry] = (answer.details as { sources: Array<{ index: { state: string; due: boolean; detail: string } }> }).sources; + expect(entry?.index).toMatchObject({ state: 'held', due: false }); + expect(entry?.index.detail).toMatch(/^held: the knowledge service is not enabled on this deployment/); + expect(entry?.index.detail).not.toContain('built anew'); + expect(calls).toEqual([]); + }); + + it('control: enabled, the same store is asked once per source, as it always was', async () => { + const { calls, read } = service(false); + const answer = await read(); + const [entry] = (answer.details as { sources: Array<{ index: { state: string } }> }).sources; + expect(entry?.index.state).toBe('new-fingerprint'); + expect(calls).toEqual(['indexStatus']); + }); +}); diff --git a/packages/services/service-knowledge/src/__tests__/knowledge-settings-contribution.test.ts b/packages/services/service-knowledge/src/__tests__/knowledge-settings-contribution.test.ts index 4499ab1c945..0202d28a902 100644 --- a/packages/services/service-knowledge/src/__tests__/knowledge-settings-contribution.test.ts +++ b/packages/services/service-knowledge/src/__tests__/knowledge-settings-contribution.test.ts @@ -1012,7 +1012,9 @@ describe('[ADR-0161 K8, note on item 12] a runtime-composed knowledge service is // The engine's own write (a package install, a seed) is admitted, and nothing calls the store. expect(await admit(knowledge, SYSTEM)).toEqual({ admitted: true }); // A save with no identity is refused for the held state first: it names the deployment, not the caller. - expect((await admit(knowledge, undefined)).message).toContain(HELD); + // `null`, not `undefined`: `admit`'s default parameter would read `undefined` as the author's identity. + expect(await admit(knowledge, null)).toMatchObject({ admitted: false, status: 503, code: 'SERVICE_UNAVAILABLE' }); + expect((await admit(knowledge, null)).message).toContain(HELD); expect(calls).toEqual([]); }); diff --git a/packages/services/service-knowledge/src/knowledge-build-actions.ts b/packages/services/service-knowledge/src/knowledge-build-actions.ts index accd5719635..e4306b90c72 100644 --- a/packages/services/service-knowledge/src/knowledge-build-actions.ts +++ b/packages/services/service-knowledge/src/knowledge-build-actions.ts @@ -26,6 +26,18 @@ * store runs, a refusal), each mounted store's modes (`adapters`) and the * store a source that names none binds to (`defaultAdapter`). * + * [ADR-0161 K8, the dated note on item 12] While the boot read a service the + * runtime composed as not enabled (`KnowledgeService.heldReading`), both + * actions say so. `index_status` answers each source's index as `held` + * (`heldIndexReading`) without asking its store — a held service calls no + * store — adds `enablement`: the state, the reason with its remedy, the + * missing halves and how many sources are held + * ({@link KnowledgeIndexStatusEnablement}), and leads its `message` with the + * state. `rebuild` is refused (`ok: false`) with the service's own refusal + * of the build, which names the remedy: the refusal is + * `KnowledgeService.rebuildSource`'s, and this action only carries it. A + * service a host mounts itself, and an enabled one, answer exactly as before. + * * Both run through the settings action door (`POST /api/settings/knowledge/ACTION`), * which gates an HTTP caller on the namespace's write permission, * `manage_platform_settings`: an administrator's. `os knowledge rebuild` and @@ -41,13 +53,15 @@ import type { SettingsActionHandler } from '@objectstack/service-settings'; import type { KnowledgeReindexResult } from '@objectstack/spec/contracts'; -import type { - KnowledgeBuildProgress, - KnowledgeBuildRecord, - KnowledgeBuildTrigger, - KnowledgeIndexReading, +import { + heldIndexReading, + type KnowledgeBuildProgress, + type KnowledgeBuildRecord, + type KnowledgeBuildTrigger, + type KnowledgeIndexReading, } from './knowledge-build.js'; -import type { KnowledgeService, KnowledgeSourceDescription } from './knowledge-service.js'; +import type { KnowledgeHeldReading, KnowledgeService, KnowledgeSourceDescription } from './knowledge-service.js'; +import { heldSourcesText } from './knowledge-service-top-level.js'; import type { KnowledgeStoredBuild, KnowledgeSyncFailures } from './knowledge-sync-state.js'; import { KNOWLEDGE_RECORD_SYNC_QUEUE } from './knowledge-record-sync-queue.js'; import type { KnowledgeRetrievalReading } from './knowledge-retrieval-mode.js'; @@ -59,7 +73,10 @@ export const KNOWLEDGE_REBUILD_ACTION = 'rebuild'; /** The `knowledge` settings action that reads each source's index state and last build. */ export const KNOWLEDGE_INDEX_STATUS_ACTION = 'index_status'; -/** The part of `KnowledgeService` the two actions use. */ +/** + * The part of `KnowledgeService` the two actions use. `heldReading` is + * optional: a service without it reads as one that is never held. + */ export type KnowledgeBuildActionsService = Pick< KnowledgeService, | 'describeSources' @@ -74,7 +91,32 @@ export type KnowledgeBuildActionsService = Pick< | 'describeRetrieval' | 'listAdapters' | 'getAdapter' ->; +> & + Partial>; + +/** + * [ADR-0161 K8, the dated note on item 12] The `enablement` of an + * `index_status` answer: present only while the boot read a service the + * runtime composed as not enabled, absent otherwise (a host-mounted service + * and an enabled one answer as they always did). + */ +export interface KnowledgeIndexStatusEnablement { + /** The service is mounted and not enabled: its sources are held. */ + state: 'not-enabled'; + /** Why, naming each missing half and the remedy: the sentence a held search or build is refused with. */ + reason: string; + /** Set when no embedder is available: why, as operator text (the settings missing). Never a key. */ + embedder?: string; + /** Set when the deployment's store is not mounted: the id of its adapter. */ + store?: string; + /** How many sources the service holds: every registered source, whichever the payload named. */ + heldSources: number; +} + +/** The service's held reading, or `undefined` while it serves (and on a service with no such member). */ +function heldOf(service: KnowledgeBuildActionsService): KnowledgeHeldReading | undefined { + return typeof service.heldReading === 'function' ? service.heldReading() : undefined; +} /** One source in an `index_status` answer. */ export interface KnowledgeIndexStatusEntry { @@ -296,6 +338,19 @@ export function knowledgeRebuildActionHandler(service: KnowledgeBuildActionsServ .then((build) => resolve({ build }), (thrown: unknown) => resolve({ thrown })); }); if ('thrown' in started) { + // Held: the service refused the build (`heldSourcesError`, naming the + // remedy). A refusal, not a build that did not start: nothing will + // start it until the deployment is configured and restarted. + if (heldOf(service) !== undefined) { + return { + ok: false, + severity: 'error', + message: + `Rebuild of source '${source.id}' is refused: ` + + `${started.thrown instanceof Error ? started.thrown.message : String(started.thrown)}`, + details: { source: source.id, build: null }, + }; + } // The source went between the lookup above and the start. Answered as // a build that did not start, the way this action has always answered: // `ok` says the request was taken, `build.status` says what came of it. @@ -345,6 +400,8 @@ export function knowledgeIndexStatusActionHandler(service: KnowledgeBuildActions } else { targets = service.describeSources(); } + // Read once: held, no source's store is asked what it holds. + const held = heldOf(service); const sources: KnowledgeIndexStatusEntry[] = []; for (const source of targets) { const adapter = service.boundAdapterId(source.source); @@ -354,7 +411,7 @@ export function knowledgeIndexStatusActionHandler(service: KnowledgeBuildActions label: source.source.label, ...(adapter === undefined ? {} : { adapter }), ...(source.packageId === undefined ? {} : { packageId: source.packageId }), - index: await service.readIndexState(source.id), + index: held === undefined ? await service.readIndexState(source.id) : heldIndexReading(source.id), ...(await readSyncState(service, source.id)), ...(retrieval === undefined ? {} : { retrieval }), }); @@ -371,16 +428,34 @@ export function knowledgeIndexStatusActionHandler(service: KnowledgeBuildActions const running = sources.filter((s) => s.build?.status === 'running').length; const failing = sources.filter((s) => (s.failures?.count ?? 0) > 0).length; const pending = queue?.pending === undefined ? '' : `, ${queue.pending} record sync(s) waiting`; + const details = { + sources, + adapters, + ...(defaultAdapter === undefined ? {} : { defaultAdapter }), + ...(queue === undefined ? {} : { queue }), + }; + if (held === undefined) { + return { + ok: true, + severity: 'info', + message: `${sources.length} source(s): ${due} need a build, ${running} building, ${failing} with failed syncs${pending}.`, + details, + }; + } + const enablement: KnowledgeIndexStatusEnablement = { + state: 'not-enabled', + reason: heldSourcesText(held), + ...(held.embedder === undefined ? {} : { embedder: held.embedder }), + ...(held.store === undefined ? {} : { store: held.store }), + heldSources: service.describeSources().length, + }; return { ok: true, severity: 'info', - message: `${sources.length} source(s): ${due} need a build, ${running} building, ${failing} with failed syncs${pending}.`, - details: { - sources, - adapters, - ...(defaultAdapter === undefined ? {} : { defaultAdapter }), - ...(queue === undefined ? {} : { queue }), - }, + // The state leads; the build counts are left out, since no source is + // built while held. Each source's own entry is in `details` as ever. + message: `${enablement.reason} ${enablement.heldSources} source(s) held.`, + details: { ...details, enablement }, }; }; } diff --git a/packages/services/service-knowledge/src/knowledge-build.ts b/packages/services/service-knowledge/src/knowledge-build.ts index 60a2c389a55..66308361d80 100644 --- a/packages/services/service-knowledge/src/knowledge-build.ts +++ b/packages/services/service-knowledge/src/knowledge-build.ts @@ -97,6 +97,11 @@ import type { AdapterIndexStatus, KnowledgeReindexResult } from '@objectstack/sp * says why. * - `not-built-here` — the service cannot build this source here: no data * engine is bound. + * - `held` — [ADR-0161 K8, the dated note on item 12] the service the + * runtime composed is not enabled at this boot, so every source is held: + * nothing is built, and the adapter is not asked what it holds (a held + * service calls no store). Not due; `detail` says so, and the `index_status` + * answer's `enablement` names why and the remedy ({@link heldIndexReading}). */ export type KnowledgeIndexState = | 'nothing' @@ -108,7 +113,8 @@ export type KnowledgeIndexState = | 'listed-documents' | 'unknown' | 'unreadable' - | 'not-built-here'; + | 'not-built-here' + | 'held'; /** One reading of a source's index (`KnowledgeService.readIndexState`). */ export interface KnowledgeIndexReading { @@ -122,6 +128,23 @@ export interface KnowledgeIndexReading { held?: AdapterIndexStatus; } +/** + * [ADR-0161 K8, the dated note on item 12] The reading of a source while the + * service holds it: no adapter is read, nothing is due. The one spelling of a + * held source's index state; `index_status` answers it in place of + * `KnowledgeService.readIndexState`, which would ask the store. + */ +export function heldIndexReading(sourceId: string): KnowledgeIndexReading { + return { + sourceId, + state: 'held', + due: false, + detail: + 'held: the knowledge service is not enabled on this deployment, so the source is not built, synced or searched, ' + + 'and what its store holds is not read.', + }; +} + /** * Who started a build: the boot's first-build pass, a `knowledge_source` item * that was added or changed while the process runs (`reload`), an diff --git a/packages/services/service-knowledge/src/knowledge-service.ts b/packages/services/service-knowledge/src/knowledge-service.ts index 18477e18481..799d4c309f4 100644 --- a/packages/services/service-knowledge/src/knowledge-service.ts +++ b/packages/services/service-knowledge/src/knowledge-service.ts @@ -1510,8 +1510,10 @@ export class KnowledgeService implements IKnowledgeService { * are held like every other source), and the engine's own write is * admitted, so a shipped source still installs and is held. * - * `options.door` words the sentences for the door that asks (the gates and - * the status and code are the same at both): `save`, the default, for a + * `options.door` words the sentences for the door that asks, and decides + * whether the held refusal above applies (it does at `save`, never at + * `duplicate`; the gates, and their status and code, are the same at + * both): `save`, the default, for a * door that saves one item; `duplicate` for the package duplicate, which * copies a package's sources. Its caller is told the source cannot be * copied and to duplicate the package again, never to save the source, and From 142f3f6659bdae0126d8fdf80a8876ee9409ba0d Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 30 Nov 2026 16:27:57 +0000 Subject: [PATCH 2/3] fix(changeset): name only what this release's CLI prints Claude-Session: https://claude.ai/code/session_01ADHkmPDtfMCw4FJfyFfQ7v Co-authored-by: Claude --- .changeset/38369-held-status.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/38369-held-status.md b/.changeset/38369-held-status.md index 978ca808b15..911535ea70c 100644 --- a/.changeset/38369-held-status.md +++ b/.changeset/38369-held-status.md @@ -8,6 +8,6 @@ feat(service-knowledge): index_status and rebuild say when the knowledge service Clause-②: yes (widening) Metadata-protocol: none -While the boot read a knowledge service the runtime composed as not enabled (no embedder, or the deployment's store not mounted), the `knowledge` settings actions say so. `index_status` answers each source's index as the new state `held` (not due) without asking its store, adds `enablement` — `state: 'not-enabled'`, the `reason` naming each missing half and its remedy, `embedder` / `store` for the missing halves, and `heldSources` — and its message leads with the reason and the held count. `rebuild` is refused (`ok: false`, which the settings door answers 400) with the service's own sentence: "Rebuild of source 'X' is refused: … To enable it, save an embedder provider, then restart." `os knowledge status` and `os knowledge rebuild` print both. A service a host mounts itself, and an enabled one, answer exactly as before. +While the boot read a knowledge service the runtime composed as not enabled (no embedder, or the deployment's store not mounted), the `knowledge` settings actions say so. `index_status` answers each source's index as the new state `held` (not due) without asking its store, adds `enablement` — `state: 'not-enabled'`, the `reason` naming each missing half and its remedy, `embedder` / `store` for the missing halves, and `heldSources` — and its message leads with the reason and the held count. `rebuild` is refused (`ok: false`, which the settings door answers 400) with the service's own sentence: "Rebuild of source 'X' is refused: … To enable it, save an embedder provider, then restart." `os knowledge rebuild` exits 1 with that sentence. A service a host mounts itself, and an enabled one, answer exactly as before. The boot line of a deployment that holds `knowledge_source` items and runs no knowledge service now names the embedder step its save refusal already names: declare `requires: ['knowledge']`, restart, then save an embedder provider and restart again. From 4ebd9ba0f33d2ae11fdaccedc846507e521d4540 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 30 Nov 2026 17:15:18 +0000 Subject: [PATCH 3/3] fix(changeset): grade service-knowledge patch, as Metadata-protocol: none requires Claude-Session: https://claude.ai/code/session_01ADHkmPDtfMCw4FJfyFfQ7v Co-authored-by: Claude --- .changeset/38369-held-status.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/38369-held-status.md b/.changeset/38369-held-status.md index 911535ea70c..6de0fb7e18b 100644 --- a/.changeset/38369-held-status.md +++ b/.changeset/38369-held-status.md @@ -1,5 +1,5 @@ --- -'@objectstack/service-knowledge': minor +'@objectstack/service-knowledge': patch '@objectstack/objectql': patch ---