fix(mt#1444): Fix sessionsErrored always-zero in AgentTranscriptIngestService.ingestAll#910
Merged
Conversation
…sult Reviewer-bot flagged on PR #883 that IngestAllResult.sessionsErrored was structurally always zero: ingestSession swallowed failures along three paths (HWM read, stream, upsert) and returned 0, so the outer try/catch in ingestAll never fired. Callers checking sessionsErrored greater than zero would always see zero even when every session failed silently. Adopts spec option (A): change the return shape to a typed IngestSessionResult { ingested: number; error?: Error }. ingestSession still recovers and continues — but the swallowed error surfaces in the return value so ingestAll can count it honestly. Tests: - The existing DB error isolation test now asserts sessionsErrored === 1. - New test: upsert failure on one of three sessions counts exactly one. - New test: HWM-read failure surfaces and is counted, even when the recovery path proceeded (degraded state worth tracking — without HWM, next ingest would re-collect already-ingested lines). - All ingestSession callers updated (3 in adapters, 6 in tests) to use the new typed shape. 11 of 11 tests pass; typecheck 0 errors, lint 0 warnings.
There was a problem hiding this comment.
Independent adversarial review (Chinese-wall)
Reviewer: minsky-reviewer[bot] via openai:gpt-5
Tier: unknown
The reviewer ran but produced no findings. This is not an approval — the model emitted no submit_finding, submit_inline_comment, or conclude_review calls.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes mt#1444:
IngestAllResult.sessionsErroredwas structurally always0becauseingestSessionswallowed all three failure paths (HWM read, stream, upsert) and returned0, so the outer try/catch iningestAllnever fired. Adopts spec option (A): changeingestSessionto return a typed{ ingested: number; error?: Error }so swallowed failures surface to the sweep.Motivation and Context
Reviewer-bot flagged this on PR #883 (review). The existing "DB error isolation" test explicitly asserted
sessionsErrored === 0with a comment acknowledging the swallowing — meaning callers checkingsessionsErrored > 0to detect failures would always see zero even when every session failed silently. This is a correctness bug for any monitoring/alerting layer downstream of the ingest sweep.Design
The spec offered two options. Option (A) preserves error visibility without breaking sweep semantics —
ingestSessionstill recovers and continues; the swallowed error just surfaces via the return value. Theerrorfield is optional and is set only when a swallow path was hit; success returns{ ingested: N }with noerror.HWM-read failure semantics: even when the recovery path proceeds (we read the HWM as null and may successfully upsert), the error is surfaced. Rationale documented in code: without an HWM, the next ingest would re-collect already-ingested lines (the upsert appends via JSONB-array-concat), so a recovered-from HWM error is a degraded state worth counting.
Key Changes
src/domain/transcripts/agent-transcript-ingest-service.ts:IngestSessionResultinterface:{ ingested: number; error?: Error }ingestSessionreturn type changed fromPromise<number>toPromise<IngestSessionResult>ingestAllincrementssessionsErroredonresult.error !== undefined; the defensive outer catch remains for unexpected throwssrc/adapters/shared/commands/transcripts.ts: single call site updated to readresult.ingestedand propagatesessionsErrored: result.error ? 1 : 0to the MCP/CLI responseSpec criteria mapping
ingestSessionreturns a typed result distinguishing success from caught failureIngestSessionResultinterface; signature changeingestAllincrementssessionsErroredfor every swallowed failure (HWM, stream, upsert)ingestAllchecksresult.error !== undefinedsessionsErrored === 1validate_typecheckandvalidate_lintcleansessionsErrored = 1,totalIngested = 2 sessions worthsessionsErroredTesting
11/11 tests pass on
agent-transcript-ingest-service.test.ts(was 8 — added 3 new acceptance tests, kept all existing assertions strict).Out of Scope
sessionsErroredcount.🤖 Generated with Claude Code