Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
refactor(ingest): fold file diagnostics in applyFileDiagnostics (E-N4 follow-up)
time-attack9a64f6a596c1
diff --git a/scripts/function-size-baseline.tsv b/scripts/function-size-baseline.tsvindex bdbc617b5b..12a05e4414 100644--- a/scripts/function-size-baseline.tsv+++ b/scripts/function-size-baseline.tsv@@ -59,6 +59,5 @@ src/core/skillopt/orchestrator.ts runOptimizationLoop 704 seed: W5 baseline, refsrc/core/skillopt/orchestrator.ts runOptimizationLoop>withBudgetTracker(#1) 405 seed: W5 baseline, refactor wave 1 (decomposition deferred to wave 2, plan D1)src/core/sources-ops.ts addSource 317 seed: W5 baseline, refactor wave 1 (decomposition deferred to wave 2, plan D1)src/core/think/index.ts runThink 450 seed: W5 baseline, refactor wave 1 (decomposition deferred to wave 2, plan D1)-src/core/transcripts/ingest.ts runTranscriptsIngest 317 seed: W5 baseline, refactor wave 1 (decomposition deferred to wave 2, plan D1)src/core/workspace-push.ts workspacePush 312 seed: W5 baseline, refactor wave 1 (decomposition deferred to wave 2, plan D1)src/mcp/http-transport.ts startHttpTransport 409 seed: W5 baseline, refactor wave 1 (decomposition deferred to wave 2, plan D1); +1 cat40 cost wave C1 (garrytan/gbrain-evals#57 follow-ups): dispatch resultRows from X-Gbrain-Client / mcp.result_rows (logic in mcp/result-rows.ts)diff --git a/src/core/transcripts/ingest.ts b/src/core/transcripts/ingest.tsindex b7c2f0f097..15328a7e61 100644--- a/src/core/transcripts/ingest.ts+++ b/src/core/transcripts/ingest.ts@@ -30,7 +30,7 @@import type { BrainEngine } from '../engine.ts';import { importFromContent } from '../import-file.ts';import { canonicalJson } from '../remediation-step.ts';-import type { TranscriptAdapter, TranscriptFormat } from './types.ts';+import type { FileDiagnostics, TranscriptAdapter, TranscriptFormat } from './types.ts';import { detectAdapter } from './detect.ts';import {loadImportRedactionPatterns,@@ -437,44 +437,7 @@ export async function runTranscriptsIngest(step = await gen.next();}- if (step.done && step.value) {- const diag = step.value;- fileOutcome.skippedLines = diag.skippedLines;- if (diag.bytesRead > 0 && diag.sessions === 0 && !diag.expectedEmpty) {- fileOutcome.drift = true;- result.driftFiles++;- // A drifting file may hold sessions a fixed parser will surface- // later (torn hermes copy, transient format break) — the shared- // watermark must not advance past it. expectedEmpty (a grok- // tool/reasoning-only session) is understood, not drifted.- result.cleanScan = false;- }- if (diag.userTurnsMissing && !fileOutcome.drift) {- // E-N4: assistant turns parsed but not one user turn — the shape- // #5163 hid behind (a host renamed its user-turn record). The- // session still imports, but the file is drift: the watermark holds- // so a fixed parser re-reads it.- fileOutcome.drift = true;- fileOutcome.userTurnsMissing = true;- result.driftFiles++;- result.cleanScan = false;- }- if (diag.skippedLines > 0) {- // Malformed lines can be DROPPED RECORDS (an actively-appended- // file read mid-write, corruption) — freeze the watermark so a- // later repair with an older timestamp is still picked up.- // Re-scans stay cheap via content-hash skip.- result.cleanScan = false;- }- if (diag.truncated) {- // A bounded read (codex head+tail over an over-budget rollout)- // skipped a window of the file — advancing the since-watermark- // over that unscanned window would drop its sessions permanently.- fileOutcome.truncated = true;- result.truncatedFiles++;- result.cleanScan = false;- }- }+ if (step.done && step.value) applyFileDiagnostics(step.value, fileOutcome, result);} catch (err) {if (err instanceof Error && err.message.startsWith(RUN_ABORT_MARKER)) throw err;fileOutcome.error = err instanceof Error ? err.message : String(err);@@ -522,3 +485,42 @@ async function adoptExistingBaseSlug(engine: BrainEngine, sourceId: string, rendrendered.baseSlug = existing.slug;for (const part of rendered.parts) part.slug = part.part === 1 ? existing.slug : `${existing.slug}-p${part.part}`;}++/** Fold one file's adapter diagnostics into its outcome and the run result (drift, skipped lines, truncation). */+function applyFileDiagnostics(diag: FileDiagnostics, fileOutcome: IngestFileOutcome, result: TranscriptsIngestResult): void {+ fileOutcome.skippedLines = diag.skippedLines;+ if (diag.bytesRead > 0 && diag.sessions === 0 && !diag.expectedEmpty) {+ fileOutcome.drift = true;+ result.driftFiles++;+ // A drifting file may hold sessions a fixed parser will surface+ // later (torn hermes copy, transient format break) — the shared+ // watermark must not advance past it. expectedEmpty (a grok+ // tool/reasoning-only session) is understood, not drifted.+ result.cleanScan = false;+ }+ if (diag.userTurnsMissing && !fileOutcome.drift) {+ // E-N4: assistant turns parsed but not one user turn — the shape+ // #5163 hid behind (a host renamed its user-turn record). The+ // session still imports, but the file is drift: the watermark holds+ // so a fixed parser re-reads it.+ fileOutcome.drift = true;+ fileOutcome.userTurnsMissing = true;+ result.driftFiles++;+ result.cleanScan = false;+ }+ if (diag.skippedLines > 0) {+ // Malformed lines can be DROPPED RECORDS (an actively-appended+ // file read mid-write, corruption) — freeze the watermark so a+ // later repair with an older timestamp is still picked up.+ // Re-scans stay cheap via content-hash skip.+ result.cleanScan = false;+ }+ if (diag.truncated) {+ // A bounded read (codex head+tail over an over-budget rollout)+ // skipped a window of the file — advancing the since-watermark+ // over that unscanned window would drop its sessions permanently.+ fileOutcome.truncated = true;+ result.truncatedFiles++;+ result.cleanScan = false;+ }+}