Repository navigation
fix: Jev legs no longer take stage headlines - #8
Conversation
foldAuxTokens let a Jev leg claim the bucket Model/Provider — the UI then labels a mostly-LLM stage 'jev-1.13.0'. Non-Jev legs now take the headline from a Jev holder; Jev labels a bucket only when it did all the work. Same rule applied to the SQL merge and the recordIntent/recordConvention restamps.
There was a problem hiding this comment.
All reported issues were addressed across 5 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
Cubic follow-ups: SQL CASE now requires model-bearing spend like foldAuxTokens' zero-spend early return; header comments reflect the non-Jev promotion rule; test asserts Provider alongside Model.
There was a problem hiding this comment.
2 issues found across 4 files (changes from recent commits).
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="backend/internal/pipeline/types.go">
<violation number="1" location="backend/internal/pipeline/types.go:556">
P2: The comment claims the foldAuxTokens aux contract survives the MergeStageTokenEntry merge, but for the auto_resolve path it does not. resolveCandidates folds one leg per AddressedJudge call into a pass-local bucket with its full per-call aux ledger, then persistAsyncStageTokens (orchestrator.go:1442-1443) writes that summed bucket as a single `entry`; reviews.sql appends `jsonb_build_array(entry - 'aux')`, which strips the nested legs and keeps only the envelope (summed scalars + headline model). In a Jev+LLM mixed push the Jev legs never reach the DB, so Jev spend is attributed to the envelope's (LLM) headline in the stats/models view — the exact misattribution the comment says cannot happen. foldAuxTokens flattens nested legs (`append(bucket.Aux, spend.Aux...)`); the SQL merge should do the same (append `entry->'aux'` legs instead of dropping them) for bucket entries.</violation>
</file>
<file name="backend/internal/store/sqlc/query/reviews.sql">
<violation number="1" location="backend/internal/store/sqlc/query/reviews.sql:285">
P3: The new zero-spend guard in MergeStageTokenEntry is the only behavioral change in this batch, but nothing in the repo executes the query: pipeline tests are intentionally DB-less (token_persistence_test.go header states "Tests here are intentionally DB-less"), crosspr_stage_integration_test.go's fakeCrossPRStore only records params without running SQL, and a store-package test for the merge does not exist. The touched TestFoldAuxTokens_MixedBucketSemantics pins pre-existing Go foldAuxTokens behavior (its zero-spend early return predates this delta; only the comments and the provider assertion changed there). The parity claim in the updated comments ("Merge semantics (matches foldAuxTokens)") can therefore regress undetected. Add a test that runs the query — or extracts/asserts its headlining predicates — covering at least: a zero-spend model-bearing entry must not stamp model/provider, and a non-Jev entry must restamp a bucket held by a Jev (typesafe) stamp.</violation>
</file>
Tip: Review your code locally with the cubic CLI to iterate faster.
Re-trigger cubic
| // First-writer headline (matches the MergeStageTokenEntry COALESCE): the | ||
| // bucket label names a deciding leg, and Aux records every call's | ||
| // provenance so a Jev+LLM mix never misattributes either side's spend. | ||
| // Headline semantics match foldAuxTokens (and the MergeStageTokenEntry |
There was a problem hiding this comment.
P2: The comment claims the foldAuxTokens aux contract survives the MergeStageTokenEntry merge, but for the auto_resolve path it does not. resolveCandidates folds one leg per AddressedJudge call into a pass-local bucket with its full per-call aux ledger, then persistAsyncStageTokens (orchestrator.go:1442-1443) writes that summed bucket as a single entry; reviews.sql appends jsonb_build_array(entry - 'aux'), which strips the nested legs and keeps only the envelope (summed scalars + headline model). In a Jev+LLM mixed push the Jev legs never reach the DB, so Jev spend is attributed to the envelope's (LLM) headline in the stats/models view — the exact misattribution the comment says cannot happen. foldAuxTokens flattens nested legs (append(bucket.Aux, spend.Aux...)); the SQL merge should do the same (append entry->'aux' legs instead of dropping them) for bucket entries.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At backend/internal/pipeline/types.go, line 556:
<comment>The comment claims the foldAuxTokens aux contract survives the MergeStageTokenEntry merge, but for the auto_resolve path it does not. resolveCandidates folds one leg per AddressedJudge call into a pass-local bucket with its full per-call aux ledger, then persistAsyncStageTokens (orchestrator.go:1442-1443) writes that summed bucket as a single `entry`; reviews.sql appends `jsonb_build_array(entry - 'aux')`, which strips the nested legs and keeps only the envelope (summed scalars + headline model). In a Jev+LLM mixed push the Jev legs never reach the DB, so Jev spend is attributed to the envelope's (LLM) headline in the stats/models view — the exact misattribution the comment says cannot happen. foldAuxTokens flattens nested legs (`append(bucket.Aux, spend.Aux...)`); the SQL merge should do the same (append `entry->'aux'` legs instead of dropping them) for bucket entries.</comment>
<file context>
@@ -553,9 +553,10 @@ func foldAuxTokens(bucket *StageTokens, spend StageTokens) {
- // First-writer headline (matches the MergeStageTokenEntry COALESCE): the
- // bucket label names a deciding leg, and Aux records every call's
- // provenance so a Jev+LLM mix never misattributes either side's spend.
+ // Headline semantics match foldAuxTokens (and the MergeStageTokenEntry
+ // merge): the label names the substantive leg — a non-Jev leg takes it
+ // from a Jev holder — and Aux records every call's provenance so a
</file context>
| CASE | ||
| WHEN NULLIF(sqlc.arg(entry)::jsonb ->> 'model', '') IS NOT NULL | ||
| AND ( | ||
| COALESCE((sqlc.arg(entry)::jsonb ->> 'total_tokens')::bigint, 0) <> 0 |
There was a problem hiding this comment.
P3: The new zero-spend guard in MergeStageTokenEntry is the only behavioral change in this batch, but nothing in the repo executes the query: pipeline tests are intentionally DB-less (token_persistence_test.go header states "Tests here are intentionally DB-less"), crosspr_stage_integration_test.go's fakeCrossPRStore only records params without running SQL, and a store-package test for the merge does not exist. The touched TestFoldAuxTokens_MixedBucketSemantics pins pre-existing Go foldAuxTokens behavior (its zero-spend early return predates this delta; only the comments and the provider assertion changed there). The parity claim in the updated comments ("Merge semantics (matches foldAuxTokens)") can therefore regress undetected. Add a test that runs the query — or extracts/asserts its headlining predicates — covering at least: a zero-spend model-bearing entry must not stamp model/provider, and a non-Jev entry must restamp a bucket held by a Jev (typesafe) stamp.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At backend/internal/store/sqlc/query/reviews.sql, line 285:
<comment>The new zero-spend guard in MergeStageTokenEntry is the only behavioral change in this batch, but nothing in the repo executes the query: pipeline tests are intentionally DB-less (token_persistence_test.go header states "Tests here are intentionally DB-less"), crosspr_stage_integration_test.go's fakeCrossPRStore only records params without running SQL, and a store-package test for the merge does not exist. The touched TestFoldAuxTokens_MixedBucketSemantics pins pre-existing Go foldAuxTokens behavior (its zero-spend early return predates this delta; only the comments and the provider assertion changed there). The parity claim in the updated comments ("Merge semantics (matches foldAuxTokens)") can therefore regress undetected. Add a test that runs the query — or extracts/asserts its headlining predicates — covering at least: a zero-spend model-bearing entry must not stamp model/provider, and a non-Jev entry must restamp a bucket held by a Jev (typesafe) stamp.</comment>
<file context>
@@ -277,6 +281,10 @@ SET token_usage = jsonb_set(
CASE
WHEN NULLIF(sqlc.arg(entry)::jsonb ->> 'model', '') IS NOT NULL
+ AND (
+ COALESCE((sqlc.arg(entry)::jsonb ->> 'total_tokens')::bigint, 0) <> 0
+ OR COALESCE((sqlc.arg(entry)::jsonb ->> 'cost')::float8, 0) <> 0
+ )
</file context>
Summary
foldAuxTokenslet a Jev leg claim the bucketModel/Provider— the UI labeled a mostly-LLM stagejev-1.13.0.MergeStageTokenEntrySQL merge and therecordIntentTokens/recordConventionTokensrestamps.Test plan
TestFoldAuxTokens_MixedBucketSemanticsupdated: non-Jev leg auto-promotes over Jev headline; Jev cannot steal it backgo build ./... && go vet ./... && go test ./internal/pipeline/ ./internal/store/...greenSummary by cubic
Jev legs no longer take stage headline labels when a bucket also carries LLM spend; Jev labels a bucket only when it did all the work.
foldAuxTokens, theMergeStageTokenEntrySQL merge, and therecordIntentTokens/recordConventionTokensrestamps.foldAuxTokens.TestFoldAuxTokens_MixedBucketSemanticsto cover auto-promotion, prevent Jev from reclaiming the headline, and check Provider alongside Model.Written for commit e06398a. Summary will update on new commits.