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

* fix(write-through): guard mkdir against EEXIST on Bun+Windows

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

* fix(budget): resolve non-Anthropic model pricing via canonical table under --max-cost

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

* fix(enrich): exclude dream-generated pages from thin candidates

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
nguyenchiviet
2026-07-23 05:03:54 -07:00
committed by GitHub
co-authored by Claude Opus 4.8
parent 503f61e6e4
commit 2941e17798
4 changed files with 23 additions and 1 deletions
+7
View File
@@ -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';
@@ -201,6 +202,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;
}
+3
View File
@@ -5962,6 +5962,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];
+7
View File
@@ -6255,6 +6255,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]);
@@ -6278,6 +6284,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}
`;
+6 -1
View File
@@ -146,7 +146,12 @@ export async function writePageThrough(
frontmatterOverrides: opts.frontmatterOverrides,
});
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.
const targetDir = dirname(filePath);
if (!existsSync(targetDir)) mkdirSync(targetDir, { 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