Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(chronicle): notice reads the configured model after upgrade; remote advisor hides writer ids (#5876)

garrytan62ef145899bb
diff --git a/src/core/advisor/collect-chronicle.ts b/src/core/advisor/collect-chronicle.ts
index cd084425a5..c7c8c1e9f1 100644
--- a/src/core/advisor/collect-chronicle.ts
+++ b/src/core/advisor/collect-chronicle.ts
@@ -41,7 +41,7 @@ async function collectAutoChronicle(ctx: AdvisorContext): Promise<AdvisorFinding
const findings: AdvisorFinding[] = [];
const settings = await readChronicleSettings(ctx.engine);
const stats = await readChronicleLedgerStats(ctx.engine);
- const activity = stats.available ? describeChronicleActivity(stats, settings.autoDailyLimit) : '';
+ const activity = stats.available ? describeChronicleActivity(stats, settings.autoDailyLimit, { nameWriters: ctx.remote === false }) : '';
if (await autoChronicleNeedsAcknowledgement(ctx.engine)) {
findings.push({
id: 'auto_chronicle_default_on',
diff --git a/src/core/chronicle/ledger-stats.ts b/src/core/chronicle/ledger-stats.ts
index f4c0322f67..44f70dbe9c 100644
--- a/src/core/chronicle/ledger-stats.ts
+++ b/src/core/chronicle/ledger-stats.ts
@@ -76,10 +76,14 @@ export async function readChronicleLedgerStats(engine: BrainEngine): Promise<Chr
}
}
-/** One line for doctor/advisor: 24 h usage against the limit, the largest writer's share, 7-day outcomes and spend. */
-export function describeChronicleActivity(stats: ChronicleLedgerStats, dailyLimit: number): string {
+/**
+ * One line for doctor/advisor: 24 h usage against the limit, the largest writer's share, 7-day
+ * outcomes and spend. `nameWriters: false` (remote advisor callers) keeps the share but not who.
+ */
+export function describeChronicleActivity(stats: ChronicleLedgerStats, dailyLimit: number, opts: { nameWriters?: boolean } = {}): string {
const top = stats.principals24h[0];
- const share = top ? `; largest writer ${top.principal} used ${Math.round((top.calls / dailyLimit) * 100)}% of the daily limit` : '';
+ const who = opts.nameWriters === false ? '' : ` ${top?.principal}`;
+ const share = top ? `; largest writer${who} used ${Math.round((top.calls / dailyLimit) * 100)}% of the daily limit` : '';
const reasons = Object.entries(stats.last7d.reasons).slice(0, 4).map(([r, n]) => `${r} ${n}`).join(', ');
const usd = `$${stats.spend7d.knownUsd.toFixed(2)} known spend`;
const unpriced = stats.spend7d.unpricedCalls > 0 ? ` + ${stats.spend7d.unpricedCalls} unpriced call(s)` : '';
diff --git a/src/core/chronicle/upgrade-notice.ts b/src/core/chronicle/upgrade-notice.ts
index 0aa771b78d..b3b4be1c16 100644
--- a/src/core/chronicle/upgrade-notice.ts
+++ b/src/core/chronicle/upgrade-notice.ts
@@ -18,8 +18,10 @@ export interface ChronicleProviderView {
async function providerView(engine: BrainEngine): Promise<ChronicleProviderView> {
try {
- const { getChatModel, isAvailable } = await import('../ai/gateway.ts');
+ const { configureGatewayIfUninitialized, getChatModel, isAvailable } = await import('../ai/gateway.ts');
const { isModelPriceable, loadPricingOverrides } = await import('../budget/budget-tracker.ts');
+ // post-upgrade opens its engine without cli.ts's connect path, so the gateway may be unconfigured.
+ configureGatewayIfUninitialized();
const model = getChatModel();
return { model, priced: isModelPriceable(model, 'chat', await loadPricingOverrides(engine)), chatAvailable: isAvailable('chat') };
} catch {
diff --git a/test/auto-chronicle-surfaces-5876.test.ts b/test/auto-chronicle-surfaces-5876.test.ts
index 75705bbaa7..712c4ca715 100644
--- a/test/auto-chronicle-surfaces-5876.test.ts
+++ b/test/auto-chronicle-surfaces-5876.test.ts
@@ -179,6 +179,16 @@ describe('advisor', () => {
expect(byName(await doctor(), 'auto_chronicle').status).toBe('ok');
});
+ test('remote advisor callers see the largest writer\'s share but not who it is', async () => {
+ await insertChronicleLedgerRow(engine, { slug: 'meetings/a', state: 'extracted', principal: ['oauth_client', 'client-a'], cost: 0.01 });
+ const remote = { engine, remote: true, now: new Date('2026-10-04T12:00:00Z') } as unknown as AdvisorContext;
+ const remoteDetail = (await collectChronicle.collect(remote)).find((f) => f.id === 'auto_chronicle_default_on')!.detail!;
+ expect(remoteDetail).toContain('largest writer used 1% of the daily limit');
+ expect(remoteDetail).not.toContain('client-a');
+ expect((await collectChronicle.collect(advisorCtx())).find((f) => f.id === 'auto_chronicle_default_on')!.detail)
+ .toContain('largest writer oauth_client:client-a used 1%');
+ });
+
test('pending pages with no chat provider warn', async () => {
await insertChronicleLedgerRow(engine, { slug: 'meetings/a', state: 'pending' });
expect((await collectChronicle.collect(advisorCtx())).find((f) => f.id === 'chronicle_chat_unavailable'))
diff --git a/test/chronicle-upgrade-notice-5876.test.ts b/test/chronicle-upgrade-notice-5876.test.ts
index 4f88ca886f..b169b7e3db 100644
--- a/test/chronicle-upgrade-notice-5876.test.ts
+++ b/test/chronicle-upgrade-notice-5876.test.ts
@@ -14,6 +14,11 @@ import { afterAll, beforeAll, beforeEach, describe, expect, test } from 'bun:tes
import { PGLiteEngine } from '../src/core/pglite-engine.ts';
import { CHRONICLE_ACK_KEY, CHRONICLE_NOTICE_SHOWN_KEY } from '../src/core/chronicle/config.ts';
import { autoChronicleUpgradeNotice, printAutoChronicleUpgradeNotice } from '../src/core/chronicle/upgrade-notice.ts';
+import { __unconfigureGatewayForTests, resetGateway } from '../src/core/ai/gateway.ts';
+import { withEnv } from './helpers/with-env.ts';
+import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';
+import { tmpdir } from 'node:os';
+import { join } from 'node:path';
let engine: PGLiteEngine;
const priced = { model: 'anthropic:claude-sonnet-4-6', priced: true, chatAvailable: true };
@@ -40,6 +45,23 @@ describe('auto_chronicle upgrade notice', () => {
expect(text).toContain('No chat provider is configured, so nothing runs');
});
+ test('post-upgrade opens its engine without configuring the gateway: the notice still reads the configured model', async () => {
+ const home = mkdtempSync(join(tmpdir(), 'chronicle-notice-'));
+ mkdirSync(join(home, '.gbrain'));
+ writeFileSync(join(home, '.gbrain', 'config.json'), JSON.stringify({ engine: 'pglite', chat_model: 'anthropic:claude-sonnet-4-6' }));
+ try {
+ await withEnv({ GBRAIN_HOME: home, ANTHROPIC_API_KEY: 'sk-test' }, async () => {
+ __unconfigureGatewayForTests();
+ const text = (await autoChronicleUpgradeNotice(engine))!.join('\n');
+ expect(text).toContain('$50.00/day with anthropic:claude-sonnet-4-6');
+ expect(text).not.toContain('No chat provider is configured');
+ });
+ } finally {
+ resetGateway();
+ rmSync(home, { recursive: true, force: true });
+ }
+ });
+
test('prints once, then never again', async () => {
const lines: string[] = [];
expect(await printAutoChronicleUpgradeNotice(engine, (l) => lines.push(l))).toBe(true);