Skip to content

fix: Jev legs no longer take stage headlines - #8

Merged
BeLazy167 merged 2 commits into
mainfrom
fix/jev-headline
Sep 19, 2026
Merged

BeLazy167 merged 2 commits into
mainfrom
fix/jev-headline

Conversation

@BeLazy167

@BeLazy167 BeLazy167 commented Sep 19, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • foldAuxTokens let a Jev leg claim the bucket Model/Provider — the UI labeled 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 MergeStageTokenEntry SQL merge and the recordIntentTokens/recordConventionTokens restamps.

Test plan

  • TestFoldAuxTokens_MixedBucketSemantics updated: non-Jev leg auto-promotes over Jev headline; Jev cannot steal it back
  • go build ./... && go vet ./... && go test ./internal/pipeline/ ./internal/store/... green

Summary 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.

  • Non-Jev legs now take the headline from a Jev holder across foldAuxTokens, the MergeStageTokenEntry SQL merge, and the recordIntentTokens/recordConventionTokens restamps.
  • The SQL merge only promotes the incoming model when the entry carries model-bearing spend, matching the zero-spend early return in foldAuxTokens.
  • Updates TestFoldAuxTokens_MixedBucketSemantics to cover auto-promotion, prevent Jev from reclaiming the headline, and check Provider alongside Model.

Written for commit e06398a. Summary will update on new commits.

Review in cubic

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.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 5 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread backend/internal/pipeline/types.go Resolved
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.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>

@BeLazy167
BeLazy167 merged commit 6e163ea into main Sep 19, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant