Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

feat(decide): status reports the conflict slot's 7-day no_entity skip share (#5836)

garrytanb41094ebbd3d
diff --git a/docs/architecture/key-files/core-decide.md b/docs/architecture/key-files/core-decide.md
index 3ff299883c..fb915355d8 100644
--- a/docs/architecture/key-files/core-decide.md
+++ b/docs/architecture/key-files/core-decide.md
@@ -82,6 +82,6 @@ The capability contract (API, providers, egress, extension points) is `docs/arch
- `src/eval/brainbench/know-to-ask-dataset.ts` — `gbrain decide dataset --slot recall_needed --from know-to-ask <dir>` (`fixtures/` + `gold/`): one item per gold user turn, label `should_retrieve`, the reflex state replayed through the shipped path on a seeded in-memory brain (`slice` reflex:fired/silent, `protected` = identity hit), split by fixture, holdouts skipped.
-- `src/commands/decide.ts` (+ `src/commands/decide/{calibrate,receipts,probe-query}.ts`, dispatch `src/cli/commands/decide.ts`) — `gbrain decide` status/probe/enable/disable/calibrate/qualify/calibrations/dataset/receipts; help and the key-only probe run without a brain; `enable` refuses unless the effective mode would be the requested one, writes the pinned id and consent, and owns S1's reranker keys so `disable` restores only what it still owns; `registerDecideSubcommand` for slot lanes; `enable --recommended` pins the default provider on a brain with none, and calibrate/qualify send the production request (`productionRequest`: S3 co-packs S5's questions when injection rides the S3 request, so the recorded `pack_shape` is the one sent; `test/decide/evidence-copack-calibration.serial.test.ts`). Tests: `test/decide/cli.serial.test.ts`; the operator guide's quickstart (`docs/guides/system-one.md`) is executed against a fixture transport by `test/decide/quickstart-doc.serial.test.ts`, and `test/decide/docs-sync.test.ts` pins its troubleshooting anchors to `REFUSAL_CATALOG`.
+- `src/commands/decide.ts` (+ `src/commands/decide/{calibrate,receipts,probe-query}.ts`, dispatch `src/cli/commands/decide.ts`) — `gbrain decide` status/probe/enable/disable/calibrate/qualify/calibrations/dataset/receipts; status carries the conflict slot's 7-day share of `no_entity` skip receipts (`no_entity_7d`, from `conflictNoEntityShare` in `store.ts`) and, when non-zero, a `gbrain facts relink --dry-run` hint line (`test/decide/status-no-entity.serial.test.ts`); help and the key-only probe run without a brain; `enable` refuses unless the effective mode would be the requested one, writes the pinned id and consent, and owns S1's reranker keys so `disable` restores only what it still owns; `registerDecideSubcommand` for slot lanes; `enable --recommended` pins the default provider on a brain with none, and calibrate/qualify send the production request (`productionRequest`: S3 co-packs S5's questions when injection rides the S3 request, so the recorded `pack_shape` is the one sent; `test/decide/evidence-copack-calibration.serial.test.ts`). Tests: `test/decide/cli.serial.test.ts`; the operator guide's quickstart (`docs/guides/system-one.md`) is executed against a fixture transport by `test/decide/quickstart-doc.serial.test.ts`, and `test/decide/docs-sync.test.ts` pins its troubleshooting anchors to `REFUSAL_CATALOG`.
- `src/commands/doctor/checks/decide.ts` — `decide_health`: key, alias, inactive slots with cause and fix, drift, alias rollouts, 24 h error rate over 5%, exhausted budget, retired pinned model, `force_on`. Tests: `test/doctor-decide-health.test.ts`.
diff --git a/src/commands/decide.ts b/src/commands/decide.ts
index dad0bc7127..0a00afd440 100644
--- a/src/commands/decide.ts
+++ b/src/commands/decide.ts
@@ -28,8 +28,8 @@ import { REFUSAL_CATALOG, SLOT_PLAIN_NAMES, refusalLine } from '../core/ai/decid
import { toWireQuestion } from '../core/ai/decide/providers/typesafe.ts';
import { SLOT_SPECS } from '../core/ai/decide/slots.ts';
import {
- dailySpend, deleteDecideState, flushDecideWrites, getDecideState, listCalibrations, recentResolvedModels, setDecideState, slotUsage,
- type CalibrationRow,
+ conflictNoEntityShare, dailySpend, deleteDecideState, flushDecideWrites, getDecideState, listCalibrations, recentResolvedModels, setDecideState,
+ slotUsage, type CalibrationRow,
} from '../core/ai/decide/store.ts';
import { DECIDE_SLOTS, DecideError, EVIDENCE_CLASSES, type DecideQuestion, type DecideSlot } from '../core/ai/decide/types.ts';
import { usageCostUsd } from '../core/budget/reservation-cost.ts';
@@ -186,7 +186,10 @@ function costPer1k(slot: DecideSlot, provider: string, usage?: { decisions: numb
// ---------------------------------------------------------------------------
export async function buildStatus(engine: BrainEngine, state: DecideState) {
- const [spend, usage] = await Promise.all([dailySpend(engine).catch(() => ({ total: 0, remote: 0 })), slotUsage(engine, 24).catch(() => [])]);
+ const [spend, usage, noEntity] = await Promise.all([
+ dailySpend(engine).catch(() => ({ total: 0, remote: 0 })), slotUsage(engine, 24).catch(() => []),
+ conflictNoEntityShare(engine).catch(() => ({ skipped: 0, receipts: 0, share: 0 })),
+ ]);
const slots = DECIDE_SLOTS.map((slot) => {
const p = policyFor(state, slot);
const u = usage.find((x) => x.slot === slot);
@@ -204,6 +207,7 @@ export async function buildStatus(engine: BrainEngine, state: DecideState) {
cost_per_1k: { ...costPer1k(slot, p.provider, u), unit: COST_UNITS[slot]?.unit ?? 'units' },
effective_line: effectiveModeLine(p),
...(state.cfg.slots[slot].keyDefault ? { key_default: true, opt_out: keyDefaultOptOut(slot) } : {}),
+ ...(slot === 'conflict' ? { no_entity_7d: noEntity } : {}),
};
});
return {
@@ -247,6 +251,9 @@ async function cmdStatus(engine: BrainEngine, args: string[]): Promise<number> {
console.log(` ${s.slot.padEnd(14)} ${s.readiness}${threshold}${cost}${activity}${s.wired ? '' : ' (not available in this build)'}`);
if (s.force_on) console.log(` WARN: decide.slots.${s.slot}.force_on bypasses the action-precision gate`);
if (s.newer_reference) console.log(` newer reference available: ${s.newer_reference} (gbrain decide calibrations adopt ${s.newer_reference})`);
+ if (s.no_entity_7d && s.no_entity_7d.skipped > 0) {
+ console.log(` ${(s.no_entity_7d.share * 100).toFixed(1)}% of conflict receipts in 7 days (${s.no_entity_7d.skipped} of ${s.no_entity_7d.receipts}) skipped a fact with no entity (no_entity); link them: gbrain facts relink --dry-run`);
+ }
if (s.opt_out) console.log(` on by default because a TypeSafe key is present (sends ${SLOT_SPECS[s.slot].egressClasses.map((c) => CLASS_TEXT[c]).join(', ')} to TypeSafe); opt out: ${s.opt_out}`);
}
const lines = status.slots.map((s) => s.effective_line).filter(Boolean);
diff --git a/src/core/ai/decide/store.ts b/src/core/ai/decide/store.ts
index af065a0db5..4c741255ca 100644
--- a/src/core/ai/decide/store.ts
+++ b/src/core/ai/decide/store.ts
@@ -414,6 +414,19 @@ export async function slotUsage(engine: BrainEngine, sinceHours = 24): Promise<S
return rows.map((r) => ({ slot: String(r.slot), decisions: Number(r.decisions), rows: Number(r.rows), input_tokens: Number(r.input_tokens), errors: Number(r.errors), skipped: Number(r.skipped), egress: Number(r.egress) }));
}
+/** Conflict receipts in the window and how many were fact-level `no_entity` skips (facts the sweep cannot judge). */
+export async function conflictNoEntityShare(engine: BrainEngine, sinceHours = 24 * 7): Promise<{ skipped: number; receipts: number; share: number }> {
+ const [row] = await engine.executeRaw<{ receipts: number | string; skipped: number | string }>(
+ `SELECT COUNT(*)::int AS receipts,
+ COUNT(*) FILTER (WHERE outcome = 'skipped' AND error_reason = 'no_entity')::int AS skipped
+ FROM decision_receipts WHERE slot = 'conflict' AND created_at >= now() - ($1::int * interval '1 hour')`,
+ [sinceHours],
+ );
+ const receipts = Number(row?.receipts ?? 0);
+ const skipped = Number(row?.skipped ?? 0);
+ return { skipped, receipts, share: receipts > 0 ? Number((skipped / receipts).toFixed(4)) : 0 };
+}
+
export interface ReplayReceipt {
decision_id: string;
answer_value: number | null;
diff --git a/test/decide/status-no-entity.serial.test.ts b/test/decide/status-no-entity.serial.test.ts
new file mode 100644
index 0000000000..7bc562210b
--- /dev/null
+++ b/test/decide/status-no-entity.serial.test.ts
@@ -0,0 +1,66 @@
+/**
+ * #5836 `gbrain decide status`: the conflict slot reports the 7-day share of
+ * conflict receipts skipped with reason `no_entity` (facts the sweep cannot
+ * judge until they are linked) as JSON (`no_entity_7d`) and, when non-zero,
+ * as a human line with the `gbrain facts relink --dry-run` hint. Receipts of
+ * other slots and older than 7 days do not count.
+ * Serial: captures console.log.
+ */
+import { afterAll, beforeAll, beforeEach, describe, expect, test } from 'bun:test';
+import { PGLiteEngine } from '../../src/core/pglite-engine.ts';
+import { resetPgliteState } from '../helpers/reset-pglite.ts';
+import { runDecideCommand } from '../../src/commands/decide.ts';
+
+let engine: PGLiteEngine;
+
+beforeAll(async () => {
+ engine = new PGLiteEngine();
+ await engine.connect({});
+ await engine.initSchema();
+});
+
+afterAll(async () => {
+ await engine.disconnect();
+});
+
+beforeEach(async () => {
+ await resetPgliteState(engine);
+});
+
+async function receipt(slot: string, outcome: string, reason: string | null, daysAgo = 0) {
+ await engine.executeRaw(
+ `INSERT INTO decision_receipts (decision_id, created_at, slot, mode, provider, outcome, error_reason, call_site, lane)
+ VALUES (md5(random()::text), now() - ($4::int * interval '1 day'), $1, 'on', 'typesafe:jev-1.13.0', $2, $3, 'sweep', 'background')`,
+ [slot, outcome, reason, daysAgo]);
+}
+
+async function status(args: string[]): Promise<string> {
+ const out: string[] = [];
+ const log = console.log;
+ console.log = (...a: unknown[]) => { out.push(a.join(' ')); };
+ try { expect(await runDecideCommand(engine, ['status', ...args])).toBe(0); } finally { console.log = log; }
+ return out.join('\n');
+}
+
+describe('decide status: conflict no_entity share', () => {
+ test('JSON field and human hint count only 7-day conflict no_entity skips', async () => {
+ for (let i = 0; i < 3; i++) await receipt('conflict', 'skipped', 'no_entity');
+ await receipt('conflict', 'skipped', 'no_embedding');
+ await receipt('conflict', 'proposal', null);
+ await receipt('conflict', 'skipped', 'no_entity', 8);
+ await receipt('evidence', 'skipped', 'no_entity');
+ const json = JSON.parse(await status(['--json']));
+ const conflict = json.slots.find((s: { slot: string }) => s.slot === 'conflict');
+ expect(conflict.no_entity_7d).toEqual({ skipped: 3, receipts: 5, share: 0.6 });
+ expect(json.slots.filter((s: Record<string, unknown>) => 'no_entity_7d' in s).map((s: { slot: string }) => s.slot)).toEqual(['conflict']);
+ const human = await status([]);
+ expect(human).toContain('60.0% of conflict receipts in 7 days (3 of 5) skipped a fact with no entity (no_entity); link them: gbrain facts relink --dry-run');
+ });
+
+ test('zero no_entity skips: JSON reports zero and no hint line is printed', async () => {
+ await receipt('conflict', 'proposal', null);
+ const json = JSON.parse(await status(['--json']));
+ expect(json.slots.find((s: { slot: string }) => s.slot === 'conflict').no_entity_7d).toEqual({ skipped: 0, receipts: 1, share: 0 });
+ expect(await status([])).not.toContain('facts relink');
+ });
+});
diff --git a/test/fixtures/goldens/decide/status-keyless-all-off.json b/test/fixtures/goldens/decide/status-keyless-all-off.json
index 6b9186ef58..100032b37c 100644
--- a/test/fixtures/goldens/decide/status-keyless-all-off.json
+++ b/test/fixtures/goldens/decide/status-keyless-all-off.json
@@ -286,6 +286,11 @@
"mode": "off",
"model": null,
"newer_reference": null,
+ "no_entity_7d": {
+ "receipts": 0,
+ "share": 0,
+ "skipped": 0
+ },
"plain": "contradiction",
"provider": "none",
"readiness": "off",