Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix: bound in-flight projection_status requests and give Entra-mode auth failures Entra guidance (#5401, #5137)
garrytan6aa93a9aaee9
diff --git a/src/core/ai/key-warnings.ts b/src/core/ai/key-warnings.tsindex a45a478605..d7dcab23ae 100644--- a/src/core/ai/key-warnings.ts+++ b/src/core/ai/key-warnings.ts@@ -12,7 +12,7 @@import { configPath, loadConfigFileOnly, type GBrainConfig } from '../config.ts';import { catalogueError } from '../error-catalogue.ts';import type { OperationError } from '../ops/contract.ts';-import { providerKeyShadows, providerKeySource, type ProviderKeyShadow } from './provider-env.ts';+import { mergedProviderEnv, providerKeyShadows, providerKeySource, type ProviderKeyShadow } from './provider-env.ts';type Env = Record<string, string | undefined>;const stderrSink = (line: string) => { process.stderr.write(`${line}\n`); };@@ -56,6 +56,10 @@ export function embeddingAuthFailedError(provider: AuthFailedProvider, status: nconst name = credentialEnvName(provider.auth_env);const rejected = `The ${provider.name} embedding provider rejected its key (HTTP ${status})`;const backfill = 'Then run `gbrain embed --stale` to embed what was saved while the key was rejected.';+ if (provider.id === 'azure-openai' && mergedProviderEnv(fileCfg, env).AZURE_OPENAI_USE_ENTRA === '1') {+ return catalogueError('embedding_auth_failed', `${rejected}; Azure Entra mode is on (AZURE_OPENAI_USE_ENTRA), so the rejected credential is the Azure CLI's Entra token, not an API key.`,+ `Run \`az login\` as an identity with the "Cognitive Services OpenAI User" role on the resource, restart the process that reported this, then run \`gbrain embed --stale\`.`);+ }if (!name) return catalogueError('embedding_auth_failed', `${rejected}.`, `Check the ${provider.name} credentials, restart the process that reported this, then run \`gbrain embed --stale\`.`);const source = providerKeySource(fileCfg, env, name);if (source.kind === 'config') {diff --git a/src/core/persistence/ipc.ts b/src/core/persistence/ipc.tsindex 6a018ec7d7..8019e54d45 100644--- a/src/core/persistence/ipc.ts+++ b/src/core/persistence/ipc.ts@@ -212,7 +212,11 @@ export async function startPersistenceIpcServer(}if (record(request) && exactKeys(request, ['version', 'kind']) && request.version === 1 && request.kind === 'projection_status') {if (!provider.projectionStatus) throw new OperationError('unavailable', 'This owner does not report projection status.');- socket.end(responseFrame({ version: 1, ok: true, result: await provider.projectionStatus() }));+ if (active >= PERSISTENCE_IPC_MAX_CONNECTIONS) throw new OperationError('queue_capacity', 'The persistence listener is at capacity; retry shortly.');+ active++;+ admitted = true;+ const status = await provider.projectionStatus();+ if (!socket.destroyed) socket.end(responseFrame({ version: 1, ok: true, result: status }));return;}if (!operationRequest(request) && !administrationRequest(request)) throw new OperationError('invalid_params', 'Invalid persistence request envelope.');diff --git a/test/embedding-key-source.test.ts b/test/embedding-key-source.test.tsindex 848739b2fe..32ff68524b 100644--- a/test/embedding-key-source.test.ts+++ b/test/embedding-key-source.test.ts@@ -96,6 +96,10 @@ describe('doctor embedding_key_source', () => {const azure = embeddingAuthFailedError(getRecipe('azure-openai')!, 401, cfg({ azure_openai_api_key: CONFIG_KEY } as Partial<GBrainConfig>), {}, '/home/example/.gbrain/config.json');expect(azure.message).toContain('the key in effect is azure_openai_api_key in /home/example/.gbrain/config.json (AZURE_OPENAI_API_KEY is not set)');expect(azure.message).not.toContain('AZURE_OPENAI_ENDPOINT');+ const entra = embeddingAuthFailedError(getRecipe('azure-openai')!, 403, cfg({ azure_openai_api_key: CONFIG_KEY } as Partial<GBrainConfig>), { AZURE_OPENAI_USE_ENTRA: '1' }, '/home/example/.gbrain/config.json');+ expect(entra.message).toContain('Azure Entra mode is on (AZURE_OPENAI_USE_ENTRA)');+ expect(entra.suggestion).toContain('az login');+ expect(entra.suggestion).not.toContain('azure_openai_api_key');});test('is ok without a shadow and reports a config-plane embedding key', () => {diff --git a/test/projection-resident-doctor.test.ts b/test/projection-resident-doctor.test.tsindex 44068517af..abe93dbffb 100644--- a/test/projection-resident-doctor.test.ts+++ b/test/projection-resident-doctor.test.ts@@ -62,6 +62,23 @@ test('the resident answers projection_status with counts only; an owner without} finally { old.close(); }});+test('stalled projection_status requests count toward the listener bound and cannot pile up', async () => {+ const socket = persistenceSocketPathForConfig(config)!;+ const stalled = Promise.withResolvers<void>();+ let calls = 0;+ const server = (await startPersistenceIpcServer(socket, provider(async () => { calls++; await stalled.promise; return { pending: 0, failed: 0, oldest_age_seconds: null }; })))!;+ try {+ const abandoned = await Promise.allSettled(Array.from({ length: 8 }, () => requestPersistenceProjectionStatus(socket, 200)));+ expect(abandoned.every(result => result.status === 'rejected')).toBe(true);+ expect(calls).toBe(8);+ await expect(requestPersistenceProjectionStatus(socket)).rejects.toMatchObject({ code: 'queue_capacity' });+ expect(calls).toBe(8);+ stalled.resolve();+ await new Promise(resolve => setTimeout(resolve, 50));+ expect(await requestPersistenceProjectionStatus(socket)).toEqual({ pending: 0, failed: 0, oldest_age_seconds: null });+ } finally { stalled.resolve(); server.close(); }+});+test('doctor reports the resident backlog, its pid and the stop-drain-restart path while the resident holds the brain', async () => {const socket = persistenceSocketPathForConfig(config)!;const server = (await startPersistenceIpcServer(socket, provider(() => projectionBacklog(engine))))!;