Repository navigation
Merge main into the runtime epic (OpenCode cost + detail persistence) - #3959
Conversation
…tence OpenCode step_finish events carry the provider's actual cost in part.cost, but the parser dropped it and the metrics pipeline fell back to catalog pricing, which custom LiteLLM model ids do not have. The result was a zero llm_executions cost and a NULL llm_logs cost. Parse per-step costs (counted once per part id) and cumulative result totals (replace, never add), carry the value as providerCostUsd through AgentExecutionResult, ClaudeCodeResponse and ClaudeResult, and prefer a valid reported cost over the catalog estimate. Missing and invalid costs fall back to the existing behaviour; a reported zero is kept. Co-authored-by: Copilot <[email protected]>
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]>
- Propagate providerCostUsd through AnalysisResult, review metrics, and suppressLlmLog analysis callers - Avoid overriding catalog pricing with partial step-cost subtotals or letting a zero cumulative summary erase positive step costs - Refactor OpenCodeAgent.executeTask, applyOpenCodeCost, and calculateCost to satisfy ESLint complexity and max-lines rules - Add regression tests for partial/cumulative cost edge cases, review metrics, and OpenCodeAgent executeTask/analyze wiring Co-authored-by: Copilot <[email protected]>
Summary miners suppress the agent's own log and write one llm_logs row per batch, so the provider cost returned on AnalysisResult was dropped. Sum it across every retry and fallback call; when any call returns no cost, leave it unset so the catalog estimate still applies instead of a partial sum. Adds real-SQLite tests asserting llm_logs.cost_usd for summed retries, partial coverage, an explicit zero, and a failed keyword extraction call. Co-authored-by: Copilot <[email protected]>
Keeps llmMetrics.ts within the 400-line max-lines lint gate. Co-authored-by: Copilot <[email protected]>
Addresses review feedback on #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]>
Applied F4–F7 for PR #3780. - OpenCode sums deduplicated, valid step costs when no cumulative total is available. A valid cumulative total takes precedence, including `$0`. - Synthetic routing returns the combined cost of all physical analysis attempts to all four callers. If any attempt’s cost is unknown, the combined total is unknown. - File and directory batches mark cost coverage incomplete when analysis rejects. A later parsing failure preserves any cost the analysis already reported. All six targeted test suites passed. Core type checking and linting for the changed source files passed. The LLM Log preview shows the verified `$0.750` failover total. Separate observations outside the selected fixes: the LLM Logs API maps stored zero costs to `null`, the routing details display raw model IDs, and PR review comments still calculate cost from catalog pricing. PR: #3780 Comment by: @integry (ID: 7138343005) Model: GPT-6.2 Sol ProPR-Agent: codex/gpt-6.2-sol
F8 is fixed: when a synthetic route runs out of members after every attempt reported a cost, the summed cost now reaches the caller's log instead of being dropped.
## What changed
- **Routing** (`syntheticRoutingService.ts`, `syntheticRoutingTypes.ts`): `SyntheticRoutingSession.analyze` records the accumulated cost on the `SyntheticPoolExhaustedError`. It does so only when at least one attempt ran in that call and every attempt reported a valid cost; a missing cost or a thrown attempt still leaves it unknown.
- **Keyword extraction and semantic scoring**: their failure logs now read the cost from the exhaustion error.
- **File and directory batches** (`analyzeWithProviderCost` in `summaryMinerMetrics.ts`): the tracker adds the exhaustion error's cost instead of marking the total unknown, so a priced fallback afterwards yields the full sum.
## One addition beyond the literal finding
When a member's failure reason contains a retryable-looking word such as "timeout", the batch retry re-enters the already exhausted route. That re-entry runs no attempt, but the tracker treated it as an unknown-cost call and discarded the total again. The error now also carries the number of attempts that ran, and the tracker skips a zero-attempt exhaustion. Retry and fallback behaviour is unchanged.
## Verification
- `test/summaryMinerBatchFallback.test.ts` passes 44/44; the 9 new regressions fail with the source change reverted.
- New regressions cover:
- fully priced exhaustion for all four callers ($0.25 + $0.50 logged as $0.75).
- exhaustion followed by a priced fallback for file and directory batches ($0.875).
- exhaustion with a missing or thrown attempt cost (stays unknown).
- an all-zero total.
- Core `tsc --noEmit` and `eslint src/ --max-warnings 0` are clean. To stay under the 400-line lint limit in `syntheticRoutingService.ts`, I merged its two imports from `syntheticRoutingTypes.js` into one.
- `planFileGeneration`, `opencodeCostReporting`, `llmMetricsProviderCost` and `reviewResultMetricsReasoningLevel` pass.
- `opencodeExecutionLog` has one failing test, with or without this change: it cannot create a temp directory under the read-only `/tmp/git-processor` in this container.
No visual preview: the change only affects stored cost values on a failure path.
## Separate observation (not changed)
`withRetry` treats a pool-exhaustion error as retryable whenever a member's failure reason matches its message patterns ("timeout", "connection", …), so an exhausted route gets pointlessly re-entered up to three times before fallback.
PR: #3780
Comment by: @integry (ID: 7141747175)
Model: Claude Fable 5.2
ProPR-Agent: claude/claude-fable-5-2
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: #3782 Comment by: @integry (ID: 7144008438) Model: GPT-6.2 Astra ProPR-Agent: codex/gpt-6.2-astra
F9 and F10 are both fixed, with regressions that fail on the previous code and pass now. Core `tsc --noEmit` and `eslint src/ --max-warnings 0` are clean, and the summary-miner, OpenCode, capacity and synthetic-routing suites I ran all pass. ## F9: known spend across capacity waits - **Selection-time wait:** a capacity error raised while selecting the next member now carries the call's attempt count and accumulated cost. It is the same error object, so its capacity-error identity is unchanged. - **Tracker:** a wait with no attempt behind it is ignored, and a wait after priced attempts adds their total. Both file and directory batch logging now keep the full sum when a later retry succeeds. - **Same defect in sibling paths, also corrected:** - A capacity error thrown by the physical member itself (admission wait) was passed through unannotated; it now carries the prior spend too. - `OpenCodeAgent.analyze` returns a capacity wait as a failed result rather than throwing. The routing session now treats that as zero spend, not unknown spend. - Keyword extraction and semantic scoring read the same carried cost, so they pick this up without their own change. The cost-summing logic moved into two small helpers in `syntheticRoutingTypes.ts` to keep `syntheticRoutingService.ts` under the 400-line and complexity lint gates. Regressions in `test/summaryMinerBatchFallback.test.ts` (9 new cases): - wait at selection and at admission after a `$0.25` attempt. - wait before the first attempt. - wait returned as a failed result. - file and directory batches where a retry succeeds after the wait (`0.75` after a priced attempt, `0.5` after none). - a direct agent with no routing session. ## F10: cost through post-execution verification In `OpenCodeAgent.executeTask`, verification now runs on the completed response before the log is written. If it throws, that same response is marked failed with the verification message, keeping its cost, tokens and session id, and the log is persisted once. The regression in `test/opencodeExecutionLog.test.ts` asserts one failed log with `costUsd` 0.75 and a returned failure with the same `providerCostUsd`. ## Separate observations (not changed) - The session only arms selection-time capacity deferral for the first selection, so the F9 trace (a selection-time wait after a priced attempt) is not reachable through the built-in selector today. The regression simulates it by overriding `select`; the admission-wait and failed-result paths are the ones that occur in practice. - In this container, the existing analyze test in `opencodeExecutionLog.test.ts` only passes with `OPENCODE_ANALYSIS_ROOT` pointed at a writable directory, because `/tmp/git-processor` is read-only here. That is environmental, not caused by this change. No visual preview: the change is not user-visible. PR: #3780 Comment by: @integry (ID: 7144025768) Model: Claude Fable 5.2 ProPR-Agent: claude/claude-fable-5-2
Automatically resolved merge conflicts after merging target branch into PR branch. Resolved conflicts in: - packages/core/src/agents/types.ts - packages/core/src/utils/llmMetrics.ts - src/jobs/prCommentJobUtils.ts PR: #3780 Model: Claude Opus 5.5
…ence fix: reliably persist execution details for long conversations
F11 is fixed: a capacity wait that a direct agent returns as a failed result no longer marks the batch's known cost as incomplete.
## What changed
- **`summaryMinerMetrics.ts`**: `analyzeWithProviderCost` now runs returned results from direct agents through `analysisAttemptCost`. A failed result that only waited for capacity and reports no cost is treated as "no provider reached", the same as the thrown form.
- **`summaryMinerBatch.ts` / `summaryMinerDirectoryBatch.ts`**: both callers pass a new `routed` flag (`!!routingSession`). Routed results are taken as reported, because the routing session has already classified its attempts. Reclassifying them would let a capacity result hide an earlier unpriced attempt.
## Regressions added (`test/summaryMinerBatchFallback.test.ts`)
- File and directory batch: a priced attempt followed by a direct agent returning a capacity wait logs the priced attempt's cost (0.25) instead of `NULL`.
- Tracker level: returned capacity wait, then a priced retry, gives 0.5.
- The existing thrown capacity wait test now also covers the directory batch.
- Guards: a non-capacity failed result still leaves the total unknown, and a routed capacity result without a total stays unknown.
The suite passes 59/59. With the fix reverted, the three new returned-result tests fail. Core `tsc --noEmit` and eslint on the touched source files are clean, and `opencodeCostReporting.test.ts` passes 14/14.
## Independent discovery (not changed)
The finding's step 4 is not reachable through the batches as written. Once the batch turns the returned failure into a plain `Error`, its message ("Timed out waiting for agent capacity…") matches no retry pattern, so the batch fails instead of retrying; only the thrown form is retried, via the error name. That is why the batch-level regression uses the reachable order (priced attempt first, capacity wait second) and the wait-then-priced-retry order is covered at tracker level. Whether a returned capacity wait should be retried like the thrown one is a separate behaviour question, left alone here.
No visual preview: the change is not visible in the UI.
PR: #3780
Comment by: @integry (ID: 7296908608)
Model: Claude Fable 5.2
ProPR-Agent: claude/claude-fable-5-2
fix: preserve OpenCode provider-reported costs in metrics
Brings czehentner's OpenCode cost reporting (#3780) and execution-detail persistence (#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]>
|
/review |
|
✅ AI Code Review Complete requested by @integry Posted 1 review: |
🔍 AI Code Review — codex:gpt-6-astraOverall EvaluationThis PR combines provider-cost reporting with runtime compute metrics and improves conversation-detail persistence. It needs a localized correctness fix before merge: incomplete OpenCode step costs can become an authoritative run total. ✅ Preserves reported zero — Cost propagation uses explicit undefined checks, retaining zero through analysis results and metrics adapters. ✅ Retry-safe detail batches — Conversation inserts use bounded batches and the existing unique execution/sequence key to avoid duplicates during retries. ✅ Retains execution metadata — OpenCode verification failures preserve the completed result’s cost, tokens, and compute usage. This review used static analysis of the supplied diff and context; no commands were run. The supplied current-head status has no failures and nine pending checks. Merge blockersEvery finding below was introduced by this PR and must be resolved before merging. F1: 🔴 Partial costs override whole-run estimates
SuggestionsThese are optional follow-ups and are not sent to S1: 🟢 Remove duplicate cost assignments
ScoreThe implementation has substantial targeted coverage and preserves the main merged data paths, but authoritative cost reporting still accepts incomplete totals. Pending checks are not themselves a blocker. Score: 6/10 🤖 Review Details
Copy and edit to choose records from this review: 🤖 Review by ProPR |
Checks FailedValidation failed during setup, tests, CLI packaging, linting, or build checks. View Logs |
|
CI failed: Validate Changes Please investigate and fix this CI failure.
Failure evidence
|
…he merge Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Merged at 6/10 with the maintainer's OK. F1 is not introduced by this merge: it's in the OpenCode cost parser that came from |
Unblocks #3774 (epic → main), which conflicted after #3780 and #3782 landed on
main. ProPR's automatic resolution refused to run: its local epic branch on gitfix.dev has 6 unpushed commits.Resolved conflicts (7 files): both sides kept.
OpenCodeAgent.ts: main'sbuildExecutionResponse/reportExecutionOutcome(reported cost, verification once per run), wrapped with the epic'sattachComputeUsage. Itsresulttype now comes fromrunAgent, sinceexecuteDockerCommandno longer exists on the epic.failedAgentExecution.ts,processGoalJob.ts,prCommentJobUtils.ts: bothcomputeUsageandproviderCostUsd.llmMetrics.types.ts: oneproviderCostUsdfield (Pi and OpenCode share it) pluscomputeUsage.llmMetrics.ts: the epic's sharednormalizeStoredReasoningLevelplus main'sdetailsPersisted.test/opencodeExecutionLog.test.ts: both imports.Checked locally (node:22): core and root
tsc --noEmitare clean.opencodeExecutionLog9/9,opencodeCostReporting14/14,llmMetricsProviderCost5/5,llmExecutionDetailPersistence13/13,summaryMinerBatchFallback59/59.🤖 Generated with Claude Code