Repository navigation
fix: reliably persist execution details for long conversations - #3782
Conversation
llm_execution_details was written with one multi-row insert of the whole conversation. knex compiles that for SQLite to a compound SELECT, which is capped at 500 terms (and the bound variables are capped too), so runs of more than 500 events failed after the execution row was already stored, leaving a valid summary with zero details. Insert in batches of 100 in sequence order, skipping rows already stored under (execution_id, sequence_number) so a repeat never duplicates, and retry a failed insert before giving up. When details still cannot be fully stored, the execution row is kept and the failure is logged as incomplete details instead of a clean success. No schema change or LLM re-run. Co-authored-by: Copilot <[email protected]>
|
/review astra fable |
|
✅ AI Code Review Complete requested by @integry Posted 2 reviews: |
🔍 AI Code Review — astraOverall EvaluationThis PR needs minor changes before merge. The normal recording path addresses the SQLite statement limit and preserves completed batches. The remaining issues are localized to the batch-size override, the retry budget, and one claim-recovery test. ✅ Ordered, idempotent persistence — The recording path writes 100 rows at a time, preserves each event’s original log index, and uses the existing ✅ Diagnosable partial failures — When detail persistence throws after the summary row commits, the error log includes the execution ID and expected detail count. The real-SQLite test exercises this path with a trigger and checks the surviving sequence numbers. Merge blockersEvery finding below was introduced by this PR and must be resolved before merging. F1: 🔴 Remove the unchecked batch-size override
F2: 🔴 Give each failed insert its retry budget
F3: 🔴 Restore exhausted-failure claim coverage
SuggestionsThese are optional follow-ups and are not sent to S1: 🟢 Assert the exact surviving prefixThe trigger rejects sequence 250, so the two completed 100-row batches should leave exactly 200 rows. The current assertion accepts any nonempty contiguous prefix shorter than 600. Checking for 200 rows would also catch loss of a previously committed batch. This is optional because the test already checks prefix ordering and the incomplete-detail diagnostic. ScoreThe fixed-size recording path and SQLite coverage address the original long-run failure. The retry scope, unchecked override, and weakened claim test need localized corrections. All three current-head checks were skipped. Score: 6/10 🤖 Review Details
Copy and edit to choose records from this review: 🤖 Review by ProPR |
🔍 AI Code Review — fableOverall EvaluationThe PR fixes a real, well-diagnosed defect: one multi-row insert of the whole conversation exceeds SQLite's compound-SELECT and bound-variable limits, leaving a summary row with no details. The fix is batched, idempotent inserts with a bounded retry and a distinct "details incomplete" error, and it matches the stated objective. The persistence logic traces correctly through It needs one small change before merge: the additions appear to push ✅ Idempotent batches on the existing unique index — ✅ Retries cannot drift or duplicate — ✅ Real-SQLite coverage of the actual limit — Merge blockersEvery finding below was introduced by this PR and must be resolved before merging. F4: 🔴
|
Keeps llmMetrics.ts within the 400-line max-lines lint gate. Co-authored-by: Copilot <[email protected]>
Addresses review feedback on integry#3782: - Retry budget is per batch, so later batches get their retries and committed batches are not re-sent (F2, S5). - Drop the unchecked batchSize override; batches are always 100 rows (F1, S3). - Claim-recovery test exhausts all attempts and asserts the row claim is retained (F3, S2). - Persistent-failure test asserts exactly the 200-row prefix (S1). - Remove the unread detailsPersisted field (S4). Co-authored-by: Copilot <[email protected]>
|
/review astra fable |
|
✅ AI Code Review Complete requested by @integry Posted 2 reviews: |
🔍 AI Code Review — astraOverall EvaluationThe PR needs one minor change before merge. Ordered batches address the SQLite statement limit, and a failed batch leaves earlier batches available for repair. The remaining gap is the promised ✅ Ordered, idempotent writes — The writer awaits each 100-row batch and uses the existing unique key on ✅ Real SQLite coverage — The new tests check event identity and sequence through 5,000 events. A trigger at sequence 250 also verifies that the first 200 rows survive a persistent failure and that replay can fill the missing rows. Merge blockersEvery finding below was introduced by this PR and must be resolved before merging. F5: 🔴 Return detail completion status
SuggestionsThese are optional follow-ups and are not sent to S7: 🟢 Verify replay preserves existing contentThe repair test supplies different metadata for the already-committed prefix, then checks only sequence numbers. Saving one prefix row before replay and comparing its content and metadata afterward would catch an accidental switch from conflict-ignore to conflict-update. This is optional because the current implementation explicitly uses ScoreThe batching logic and SQLite tests address the original data-loss case. All 14 current checks that ran passed, but the internal result still omits one explicit acceptance criterion. Score: 6/10 🤖 Review Details
Copy and edit to choose records from this review: 🤖 Review by ProPR |
🔍 AI Code Review — fableOverall EvaluationThe PR fixes the verified root cause: a single multi-row insert of the whole conversation exceeded SQLite's compound-SELECT and bound-variable limits, leaving a summary row with no details. Details are now written in ordered batches of 100 with conflict-ignore on the existing unique index, and a failure after the execution row is committed is logged as incomplete details. The change is small, localized, and matches the stated strategy, with one exception: the description says This was a static review only; I ran nothing. The "Full Test Suite" shards were skipped on this head, so I could not confirm that no other suite mocks ✅ Fix addresses the actual limit — ✅ Idempotent without a migration — ✅ Tests exercise the real driver — Merge blockersNo merge blockers. SuggestionsThese are optional follow-ups and are not sent to S8: 🟢 Description mentions a field that does not existThe PR description says that on final failure " S9: 🟢 Retry is immediate and indiscriminate
S10: 🟢 Final error does not locate the failing batchThe "conversation details are incomplete" error logs S11: 🟢 Partial transcripts are indistinguishable to readersBefore this PR a detail failure left zero rows, so S12: 🟢 Confirm other db mocks support
|
|
/fix F5 |
|
✅ Applied the requested follow-up changes in commit a149209
Summary of ChangesApplied F5. All 39 focused persistence and metrics tests passed, including four new SQLite regressions that assert the returned status directly. Core typechecking and lint passed. The separate live Redis suite was stopped because Redis was unavailable. Review digestRisk-tiered paths
Diff size: 2 files changed, +23/−4 lines 🤖 Implementation Details
Undo Changes • View Task Execution 💡 ProPR Slash Commands
🤖 Generated by ProPR |
Applied F5. `persistToDatabase` now returns `detailsPersisted: false` when the execution row commits but a detail batch exhausts its retries. It returns `true` after all batches finish, including for empty or absent logs. A committed row keeps its claim in either case, and `recordLLMMetrics` still returns `Promise<void>`. All 39 focused persistence and metrics tests passed, including four new SQLite regressions that assert the returned status directly. Core typechecking and lint passed. The separate live Redis suite was stopped because Redis was unavailable. PR: integry#3782 Comment by: @integry (ID: 7144008438) Model: GPT-6.2 Astra ProPR-Agent: codex/gpt-6.2-astra
|
/review |
|
✅ AI Code Review Complete requested by @integry Posted 1 review: |
🔍 AI Code Review — codex:gpt-6-astraOverall EvaluationReady to merge within scope. The change directly addresses oversized SQLite inserts with bounded batches, preserves execution summaries on detail failure, and stays proportionate to the objective. ✅ Bounded, idempotent writes — Batches contain at most 100 rows, preserve original sequence numbers, and use the existing unique constraint to skip previously stored details. ✅ Explicit failure reporting — Exhausted retries retain the execution row, return ✅ Relevant regression coverage — Added tests exercise real SQLite migrations, long conversations, transient failures, partial persistence, repeated inserts, and empty logs. This assessment is based on static review of the supplied code. No commands were run, and no current-head check runs were reported. Merge blockersNo merge blockers. SuggestionsThese are optional follow-ups and are not sent to S14: 🟢 Assert repaired rows preserve contentIn ScoreThe implementation satisfies the scoped objective with focused changes and substantial regression coverage. Static review found no merge blockers; test execution remains unverified in this review. Score: 9/10 🤖 Review Details
Copy and edit to choose records from this review: 🤖 Review by ProPR |
|
Verified before merge: merged onto current |
Brings czehentner's OpenCode cost reporting (integry#3780) and execution-detail persistence (integry#3782) into the epic. Conflicts resolved by keeping both sides: reported provider cost and detail persistence from main, compute usage and the runtime abstraction from the epic. Main's OpenCode response builder now types its result from runAgent and wraps it with attachComputeUsage. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Summary
Long agent runs could end with a correct
llm_executionssummary row but zerollm_execution_detailsrows, so the conversation view was empty.Root cause
Verified.
processConversationLog()inserted the entire conversation in onedb('llm_execution_details').insert(detailsArray). For SQLite, knex compiles a multi-row insert into a compoundSELECT … UNION ALL …, which SQLite caps at 500 terms; the bound-variable limit is hit as well. Reproduced againstbetter-sqlite3+ knex with a 14-column table:too many terms in compound SELECTtoo many SQL variablesThe execution row is inserted first, and
persistToDatabase()caught the detail error, logged a generic message and still returned the row as persisted, leaving a summary without details.SQLite persistence strategy
insertConversationDetails()writes in order in batches of 100 (14 columns → 1,400 variables, far below both limits), keeping the originalsequence_number(the log index).onConflict(['execution_id','sequence_number']).ignore(), relying on the existing unique index (no migration). Repeating the call stores only what is missing and never duplicates.PersistedExecution.detailsPersistedisfalse, and an error is logged with the execution id and expected detail count ("execution row persisted but its conversation details are incomplete") instead of a generic persistence failure.Files changed
packages/core/src/utils/llmMetrics.tstest/llmExecutionDetailPersistence.test.ts(new)llmMetricsRecording,llmMetricsClaimRecovery,llmMetricsFailedExecutions) gainedonConflict().ignore().Test coverage
Real SQLite (in-memory, real migrations): 50 / 500 / 5,000 events with order and sequence numbers verified; empty and absent logs; transient failure retried with no duplicates; persistent failure (a trigger) leaves a gap-free prefix and logs incomplete details; repeated inserts do not duplicate; 2,000-row direct insert. Existing
llmMetrics*suites still pass;tscandeslint src/are clean.Limitations
recordLLMMetricsfor the same execution id still skips the row as already persisted.recordLLMMetricsstill returnsvoid, so callers observe the failure through the error log only.