dbt-monthly-channel-revenue: consecutive_growth_months ground truth is off by one against the ticket's worked example - #9
Open
genesis-gh-jlangseth wants to merge 1 commit into
Conversation
…s off by one against the ticket's own worked example
instruction.md:155 works the column out as [NULL,10,25,-5,15,30] -> [0,1,2,0,1,2],
but ALL_ROWS_GROUND_TRUTH stores every streak one higher: across the 51 rows the
value counts are {0:23, 2:18, 3:6, 4:3, 5:1} -- the value 1 never appears, which
the ticket's rule makes impossible. Recomputing the column from the table's own
revenue_mom_pct (position 5) disagrees on 28 of 51 rows, every one by exactly +1;
all 18 run-starts are stored as 2.
Root cause is solve.sh:597-601, whose reset-group running sum includes the current
row, so the streak-breaking month consumes row_number() = 1 and the first genuinely
positive month is handed 2. Subtracting one from the island position reproduces the
ticket's sequence on 51 of 51 rows. Row 2062 follows: at consec 2 the 'Invest
Heavily' rule (>= 3) no longer fires and 'Scale Up' does.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RBfQ5F7ZCz68Qu24ssExw1
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.
The frozen ground truth for
consecutive_growth_monthsindbt-monthly-channel-revenueis onehigher than the value the task's own
instruction.mddefines and works out by example, so a buildthat follows the ticket fails
test_all_rows_consecutive_growth. The root cause is a window framein the reference
solve.sh. This PR corrects the reference, the fixture, and the onestrategic_recommendationlabel that follows from it.Everything below is reproducible from files in this repository alone — no database, no Snowflake
account. All line references are at
a3278ad102829a6084dde086244a0ef665a8011c(master).dbt-monthly-channel-revenue— the frozen ground truth forconsecutive_growth_monthsis one higher than the ticket's own worked exampleWhat the ticket says
tasks/dbt-monthly-channel-revenue/instruction.md:151-155:The worked example on the last line is unambiguous: the first month of a growth run scores 1.
What the ground truth stores
tasks/dbt-monthly-channel-revenue/tests/test_outputs.py, positions 7 (consecutive_growth_months)of the tuples documented at
:2013. The smallest instance is two adjacent lines:WEB's January
revenue_mom_pctisNone, so January is0— correct. February is the channel'sfirst positive month, and the ticket's example prints
1for that position. The fixture stores2.Reproduction (no database needed)
Recomputing the column from the ground-truth table's own
revenue_mom_pct(position 5) underthe rule at
:151-155, on the file as shipped:Three things fall out of that:
1never appears in the fixture. Eighteen rows carry2, and under the ticket'srule a streak must pass through 1 to reach 2. That alone is not satisfiable by any build that
implements
:151-155.and every single one disagrees by exactly
+1.month) and every one of them is stored as
2.The full WEB channel makes the shift plain:
revenue_mom_pctWhere the
+1comes fromThe mechanism is in the task's own reference.
solution/solve.sh:597-601builds the reset groupwith a running sum whose frame includes the current row:
so the streak-breaking month increments the counter at its own row and therefore opens the next
island, consuming
row_number() = 1.:634-640then masks that row back to0:case when has_positive_growth = 0 then 0 else row_number() over ( partition by channel, growth_group order by month_start ) end as consecutive_growth_monthswhich leaves the first genuinely positive month of every run holding
2.Your own file already records the ticket's values
tests/test_outputs.py:377-381:Those are the ticket's numbers, for the same two cells
ALL_ROWS_GROUND_TRUTHstores as2and3. That constant is defined and never consumed by any test, so it grades nothing; it is cited asauthored intent, not as a failing assertion.
Why the behavioural tests don't catch it
The three streak tests —
test_consecutive_growth_first_month_zero(:897),test_consecutive_growth_resets_on_decline(:911),test_consecutive_growth_increases(:926)— are satisfied by both readings. The first month is 0 either way, resets land on 0 either way, and
the value increases within a run either way. Only the frozen table discriminates, and it encodes
the shift.
The change
Three hunks, all in this one commit. They must land together.
1.
solution/solve.sh:636-640— subtract the reset row from the island position:else row_number() over ( partition by channel, growth_group order by month_start - ) + ) - 1 end as consecutive_growth_monthsSimulating the reference's window logic against the ground truth's own
revenue_mom_pctsequences: as shipped it matches the ticket rule on 23 of 51 rows; with
- 1it matches on51 of 51. (Excluding the reset row from the group-boundary frame instead —
rows between unbounded preceding and 1 preceding— gives the same answer, but returns NULL on a channel'sfirst row, so I went with the arithmetic form.)
2.
tests/test_outputs.py:2015-2065— subtract 1 from the 28 non-zeroconsecutive_growth_monthsvalues inALL_ROWS_GROUND_TRUTH. After the change the value countsare
{0: 23, 1: 18, 2: 6, 3: 3, 4: 1}and the recomputation above reports0 51 {}.3.
tests/test_outputs.py:2062—'Invest Heavily'→'Scale Up'.This one is a consequence, not a separate opinion, and it's worth showing the work. I re-derived
strategic_recommendationfor all 51 rows from the rules atinstruction.md:252-261: against thevalues as stored, the table reproduces itself on 51 of 51 rows, so the derivation is faithful.
Applying the same rules with the corrected streaks, exactly one row changes:
At
consec = 2the'Invest Heavily'rule (momentum >= 80 AND efficiency >= 70 AND consecutive_growth_months >= 3) no longer fires, and the next rule in evaluation order(
momentum >= 70 AND market_share_pct >= 20, with momentum 88 and share 33.03) does. The other two'Invest Heavily'rows go4 → 3and are unaffected — and both still satisfytest_invest_heavily_criteria(:1340), which I checked. The three'Maintain'rows go3 → 2,2 → 1,2 → 1, all still>= 1, so that rule's rows are unaffected too.I also bumped
EXPECTED_STRATEGIC_RECOMMENDATION_COUNTS(:257) from'Scale Up': 13 / 'Invest Heavily': 3to14 / 2to keep it consistent with the table. LikeCONSECUTIVE_GROWTH_CHECKS, that constant is defined once and consumed nowhere, so it gradesnothing either way — it would simply have gone stale. Happy to drop that hunk to keep the diff to
the graded surface.
Blast radius
Two of the 95 tests fail for a ticket-faithful submission, from this single root cause:
test_all_rows_consecutive_growth(:2195) directly, andtest_all_rows_strategic_recommendation(:2161) through the propagation above.Validation
Run in fresh containers from
ghcr.io/snowflake-labs/data-eng-bench-base:1.0.0withDB_TYPE=duckdb:bash /solution/solve.shfollowed by the task's owntests/test.sh, for eachpairing of reference and suite.
solution/solve.shtests/test_outputs.pytest_all_rows_consecutive_growth—Row 3 (2024-02-01, WEB): expected 1, got 2;test_all_rows_strategic_recommendation—Row 47 (2024-12-01, MOBILE): expected 'Scale Up', got 'Invest Heavily'The two failing tests in the cross pairings are exactly the two named under Blast radius, and the
failing cells are exactly the two the reproduction above predicts. No other test moves in any
pairing.
Found while running this benchmark at volume and root-causing persistent failures: an agent
solution that implemented
:151-155as written returned1for('2024-02-01', 'WEB')andfailed
test_all_rows_consecutive_growthon exactly that cell.