Repository navigation
Run pipeline: cost only added, security findings kept, early failures said, multi-repo PRs paired - #346
Merged
Conversation
…ever sets a total Resume, CI-fix and continuation invocations SET the run's tokens and cost from a usage restored from the checkpoint (7-day TTL) or started at zero, wiping what earlier invocations recorded. Each run write now ADDs what this invocation used since its last write (TokenUsage::unrecorded/mark_recorded); failures add through RunFailure::add. A source test refuses a SET of these fields on run records.
…tells the ticket A run record write that was refused left the ticket with no answer, and a panic in the passes left the run 'running' until the stuck-run sweep called it a timeout during an unknown pass. The start failure now keeps a minimal record when the full one is refused, fails it with a plain reason and the SDK cause, tells the ticket either way and releases the ticket lock; a panic becomes an ordinary failure with a reason.
… and the PR held a draft With under four minutes left the security fix was skipped and the PR opened with the findings nowhere, and a security check that errored counted as a pass. The check's result is now a verdict (passed, findings, not checked); an error is never a pass. Findings there's no time to fix park a security fix round (run_round::Kind::SecurityFix) that runs on the PR in a fresh invocation with its own budget and re-checks when it lands. Whatever is still open is listed under the PR's Open items with a mark, and the PR is not marked ready while one is listed; the re-check removes them when it passes. The multi-repo path re-checks after its fix and lists what's left.
… and number always pair The run record kept repo as the run's repository but pr_number and branch from the first pull request, which could be in another repository, and the fallback lookups matched a PR number or branch name in any repository. Each pull request is now stored whole (prs: repo, pr_number, branch, url), the record's repo/pr_number/branch/pr_url come from one of them (the one in the run's repository when there is one), and lookups use repository-qualified keys (pr_keys, branch_keys), with older records matched by URL. A closed or merged PR of a multi-repo run that isn't the record's own gets its outcome on its entry, and is scored and learned from with its own repository. The runs API returns prs.
nambok
added a commit
that referenced
this pull request
Nov 13, 2026
…st tokens per merged PR (#662) * Analytics: token use by part, kind of work and model, and a tokens-per-merged-PR that counts only the runs behind merged PRs The tile divided every run's tokens by the merged pull requests and compared periods whose run records were written differently (before #346 a resume or CI fix SET a run's tokens, dropping earlier invocations). - common::usage: UsageSlice, slices() over the per-feature and per-model counters every call already writes, total_slice(), price_known(), and work_kind (each feature in exactly one kind of work). - GET /api/analytics gains token_use: the period's total by part with cost, by day, by kind of work and by model (cache hit share, whether the price is known) from the meter's DAY# items; tokens per merged PR from the runs started in the period whose pull request merged, also by kind of run; run tokens by how the work ended; the heaviest runs and pull requests. - A number is compared with the period before only when both were recorded the same way: the metered total when per-call counting covers the period before, run-record numbers when it starts on or after the day run records became complete. Otherwise previous is null and the reason is named. - GET /api/usage gains models (tokens by part and cache hit rate per model); docs/api/openapi.json regenerated. No new storage: the breakdown counters already exist per day, and nothing before per-call counting can be split by kind or model. * Token use: tokens only in the analytics answer Analytics shows tokens, not money, so token_use carries no cost: the cost fields, the per-PR cost, the previous cost and price_known are gone, with common::usage::price_known, which nothing else used. A test asserts the answer names no cost or price.
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
Four run-pipeline bugs from the production audit, each checked against the code first: a run's cost written back to near zero, security findings dropped under time pressure, a ticket run that failed early without saying so, and multi-repo run records that paired one repository with another repository's PR.
Changes
SET cost_usd = :c(and the token fields) from a usage restored from the checkpoint, which has a 7-day TTL, or started at zero. Once the checkpoint expired, the earlier cost was overwritten. Now every run write ADDs what this invocation used since its last write (TokenUsage::unrecorded/mark_recorded), and failures add throughRunFailure::add. Resume no longer restores usage from the checkpoint. A source test refuses anySEToftokens_in,tokens_out,cache_read_tokens,cache_write_tokensorcost_usdon run records.run_round::Kind::SecurityFix). It runs on the PR in a fresh invocation with its own budget (the rounds from Plan check before the PR; fix rounds get their own budget, push once, and never fail an open PR; generated files are regenerated #331) and re-checks security when it lands.orchestrate_ticketto failing the run before any error return.prs: repo, pr_number, branch, url), and the record'srepo,pr_number,branchandpr_urlall come from one of them: the PR in the run's own repo when there is one.pr_keys,branch_keys). Older records are matched by URL.prs, anddocs/api/openapi.jsonis regenerated.Verification
cargo fmt --all --check,cargo clippy --workspace --all-targets -D warningsandcargo test --workspace(common 1223, gateway 585, worker 770) pass on this branch.run_writes_add_only_what_is_not_yet_recorded,run_records_never_set_tokens_or_cost,a_failure_adds_its_usage_to_the_recordan_error_is_not_a_pass,findings_become_open_items,the_description_holds_security_items_until_they_are_fixeda_start_failure_is_plain_and_keeps_the_cause,a_panic_becomes_a_reason,orchestrate_ticket_fails_the_run_before_returning_an_errorrun_prs: primary pairing, repository-qualified keys, reading older records, finding a PR by repository and numberpython3 -m unittest discover -s lambda/testspasses. The stuck-run sweep knows the new round kind.