Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix: Bun+Windows write-through EEXIST, non-Anthropic --max-cost pricing, dream-page exclusion in enrich (#2407) (#3316)

Time Attakcca04874c8fd6
diff --git a/src/core/budget/budget-tracker.ts b/src/core/budget/budget-tracker.ts
index fd59d8213a..b51de3cf40 100644
--- a/src/core/budget/budget-tracker.ts
+++ b/src/core/budget/budget-tracker.ts
@@ -32,6 +32,7 @@ import { mkdirSync, appendFileSync } from 'node:fs';
import { dirname } from 'node:path';
import { gbrainPath } from '../config.ts';
import { ANTHROPIC_PRICING, type ModelPricing } from '../anthropic-pricing.ts';
+import { canonicalLookup } from '../model-pricing.ts';
import { EMBEDDING_PRICING, lookupEmbeddingPrice } from '../embedding-pricing.ts';
import { splitProviderModelId } from '../model-id.ts';
import { isoWeekFilename, resolveAuditDir } from '../audit-week-file.ts';
@@ -213,6 +214,12 @@ function lookupPricing(modelId: string, kind: BudgetKind): ModelPricing | null {
if (kind === 'rerank' && providerId && FREE_LOCAL_RERANK_PROVIDERS.has(providerId)) {
return { input: 0, output: 0 };
}
+ // Fall back to the full canonical pricing table so non-Anthropic chat
+ // models with a known price (openai:*, google:*, deepseek:*) resolve under
+ // --max-cost instead of TX2 no_pricing hard-failing at $0. ANTHROPIC_PRICING
+ // above is only the bare-keyed Claude view.
+ const canon = canonicalLookup(modelId);
+ if (canon) return canon;
return null;
}
diff --git a/src/core/pglite-engine.ts b/src/core/pglite-engine.ts
index c29b82887d..0af4abc574 100644
--- a/src/core/pglite-engine.ts
+++ b/src/core/pglite-engine.ts
@@ -6007,6 +6007,9 @@ export class PGLiteEngine implements BrainEngine {
);
}
+ // Exclude dream/synthesize-generated pages (parity with postgres-engine).
+ where.push(`(p.frontmatter ->> 'dream_generated') IS DISTINCT FROM 'true'`);
+
const orderKey = ENRICH_ORDER_SQL[opts.order] ? opts.order : 'inbound-links';
const orderBy = ENRICH_ORDER_SQL[orderKey];
diff --git a/src/core/postgres-engine.ts b/src/core/postgres-engine.ts
index 55dbf9aeab..396c487374 100644
--- a/src/core/postgres-engine.ts
+++ b/src/core/postgres-engine.ts
@@ -6293,6 +6293,12 @@ export class PostgresEngine implements BrainEngine {
)`
: sql``;
+ // Exclude dream/synthesize-generated pages (reflections, originals, cycle
+ // logs carrying frontmatter dream_generated:true). enrich develops ENTITY
+ // stubs; running it on a generated essay/log creates circular self-citation
+ // and drops the H1. IS DISTINCT FROM 'true' keeps NULL/'false' rows.
+ const dreamCondition = sql`AND (p.frontmatter ->> 'dream_generated') IS DISTINCT FROM 'true'`;
+
// Whitelisted ORDER BY (no injection — enum maps to a literal fragment).
const orderKey = ENRICH_ORDER_SQL[opts.order] ? opts.order : 'inbound-links';
const orderBy = sql.unsafe(ENRICH_ORDER_SQL[orderKey]);
@@ -6316,6 +6322,7 @@ export class PostgresEngine implements BrainEngine {
AND (char_length(p.compiled_truth) + char_length(COALESCE(p.timeline, ''))) < ${threshold}
${sourceCondition}
${recencyCondition}
+ ${dreamCondition}
ORDER BY ${orderBy}
LIMIT ${limit}
`;
diff --git a/src/core/write-through.ts b/src/core/write-through.ts
index e8ff4e71eb..4639648902 100644
--- a/src/core/write-through.ts
+++ b/src/core/write-through.ts
@@ -174,7 +174,11 @@ export async function writePageThrough(
}
}
- mkdirSync(dirname(filePath), { recursive: true });
+ // On Bun + Windows, mkdirSync(dir, { recursive: true }) can still throw
+ // EEXIST when the directory already exists (POSIX no-ops it). That aborts
+ // the put_page / enrich / capture write-through whenever the prefix dir
+ // already exists, silently leaving the DB and the .md file plane out of sync.
+ if (!existsSync(dir)) mkdirSync(dir, { recursive: true });
// Atomic write: unique temp sibling + rename. Unique name (pid + random)
// so two concurrent saves to the same target can't clobber each other's