Skip to content

Guard Slurry Ctech/Cseason share formulas against zero-sum input#627

Open
zaucker wants to merge 1 commit into
oposs:mainfrom
zaucker:Alfam2DivByZero
Open

Guard Slurry Ctech/Cseason share formulas against zero-sum input#627
zaucker wants to merge 1 commit into
oposs:mainfrom
zaucker:Alfam2DivByZero

Conversation

@zaucker
Copy link
Copy Markdown
Contributor

@zaucker zaucker commented May 9, 2026

Each per-tech share output in Application::Slurry::Ctech (5 outputs) and each per-season share output in Application::Slurry::Cseason (2 outputs, non-Kantonal_LU branch) divided an input by the sum of its sibling inputs. When the user hadn't filled the inputs yet — typical for fresh datasets and integration-test fixtures — the sum was 0, division produced a 0/0 Rat that Model.rakumod stores as the literal string 'ERROR: division by 0', and any downstream formula reading that output (notably Application::Slurry::Alfam2::er_alfam2*) died trying to coerce that string to a number.

Add an explicit Out(sum) > 0 ? In(x)/Out(sum) : 0 guard. Behavior unchanged when shares actually sum to a positive number; just stops the cascade when they don't. The existing soft writeLog warning in share_apptech_sum (when the sum isn't ~100) and the model's validation layer still flag the under-filled state.

Application::SolidManure::Cseason already divides by 100 directly, so it's not affected. Verified end-to-end against a dataset with all five Ctech share inputs and both Cseason season inputs at 0: calc previously crashed at er_alfam2_share_bc; now completes with ~97KB of output.

Each per-tech share output in Application::Slurry::Ctech (5 outputs)
and each per-season share output in Application::Slurry::Cseason
(2 outputs, non-Kantonal_LU branch) divided an input by the sum of
its sibling inputs. When the user hadn't filled the inputs yet —
typical for fresh datasets and integration-test fixtures — the sum
was 0, division produced a 0/0 Rat that Model.rakumod stores as the
literal string `'ERROR: division by 0'`, and any downstream formula
reading that output (notably Application::Slurry::Alfam2::er_alfam2*)
died trying to coerce that string to a number.

Add an explicit `Out(sum) > 0 ? In(x)/Out(sum) : 0` guard. Behavior
unchanged when shares actually sum to a positive number; just stops
the cascade when they don't. The existing soft `writeLog` warning in
share_apptech_sum (when the sum isn't ~100) and the model's
validation layer still flag the under-filled state.

Application::SolidManure::Cseason already divides by 100 directly,
so it's not affected. Verified end-to-end against a dataset with
all five Ctech share inputs and both Cseason season inputs at 0:
calc previously crashed at er_alfam2_share_bc; now completes with
~97KB of output.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@zaucker zaucker requested a review from ChHaeni May 9, 2026 10:02
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