Repository navigation
fix(kraken): count a recovered standing-charge 404 once and catch undecodable REST bodies (#5584) - #5641
Conversation
…ecodable REST bodies (#5584) Mirror the rates path's guard in async_fetch_standing_charges: a 404/410 whose GraphQL applicableStandingCharges fallback succeeds no longer bumps failures_total, and a fallback that already counted its own failure is not counted twice. Add ValueError (JSONDecodeError) to the REST except clauses in _fetch_rates_rest and async_fetch_standing_charges so a 200 with a malformed body is logged and counted instead of escaping run(). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
springfall2008
left a comment
There was a problem hiding this comment.
Automated comment from the triage bot.
Reviewed 82e05be (PR head, based on main 697c44c): 1 finding posted inline, nothing else in the body. Otherwise sound.
What was verified by reading the PR's tree (nothing executed, no tests run):
- The count-once guard added around the standing-charges GraphQL fallback matches the existing rates-path guard (
apps/predbat/kraken.py:970-977) and is correct for everyasync_graphql_query()outcome: a fallback that counts its own failure is not counted twice, an empty-but-uncounted fallback counts once, and a recovered 404/410 counts zero. It also compensates the oneasync_graphql_query()Nonereturn that does not increment (apps/predbat/kraken.py:413, a 200 whose body has nodata). - The
ValueErroraddition catchesjson.JSONDecodeErrorin both REST paths. In_fetch_rates_rest()the(None, None)return is the existing network-error sentinel and is counted once inasync_fetch_rates()(apps/predbat/kraken.py:982-984); on the authenticated-retry path the existing handling (apps/predbat/kraken.py:948-954) keeps the earlier 404/410 status so the GraphQL fallback still runs. - Moving the
Warnlog and failure count out of the inner response block keeps every non-recovered non-200 counted exactly once (429/500/503 land onapps/predbat/kraken.py:1086-1088), preserving the behaviour the transient-error test pins. - The new tests are collected automatically:
run_kraken_tests()(apps/predbat/tests/test_kraken.py:2426) discoverstest_*functions viadir(), so noTEST_REGISTRYchange is needed. They mutate no shared fixture state. The red/green claims in the PR body are consistent with the code as written. failures_totalis diagnostic-only (anaccount_statusattribute, not a liveness input), so no docs change is warranted for the counter's corrected semantics; thedocs/components.mdwording stays true.- #5636 is still open, so the PR body's merge-conflict note about
results[0]stands.
The one remaining exposure in the same class as this PR's fix is posted inline.
|
Automated reply from the triage bot (PR cleanup run). Nothing has been pushed. Branch sync: already up to date with Inline finding (r4319741971, a 200 whose JSON is not an object): checked against the code and it holds.
Why it wasn't pushed: The review thread above has no reply yet. It will get one when the change is pushed. |
|
Automated cleanup failed to complete for this PR. Reason: The run exited cleanly but left 2 file(s) with uncommitted changes, so its fixes were never pushed. They are stashed in the bot's clone before the next flow runs. Failed at: |
…re-accounting-5584
…led fetch Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…re-accounting-5584
…es) and refresh entries fixed on main Folded: GH#5686 (retention negative-delta), GH#5690 (dp2 dull-day calibration), GH#5691 (sigenergy onboard codes), GH#5693 (db row + now_utc_exact), GH#5694/springfall2008#5697 (.seconds wrap), GH#5695 (dead-tz checklist, post-springfall2008#5696), 5670/5699 (gateway EV plan/status wiring), GH#5702 (poll-trim), GH#5704 (FoxESS Back-up hold trap), GH#5705 (predheat test harness), GH#5706 (slow-charge cancels + ? marker), GH#5683 (template-sensor name/unique_id), GH#5688 (sharpen only). Merge-refresh on main: springfall2008#5617, springfall2008#5622, springfall2008#5623, springfall2008#5639, springfall2008#5641, springfall2008#5646, springfall2008#5696, springfall2008#5697, springfall2008#5705, springfall2008#5725, springfall2008#5727, springfall2008#5735, springfall2008#5737, springfall2008#5750, springfall2008#5754, springfall2008#4745; fixes a PR-number typo in the HA-write row. Co-Authored-By: Claude Code <noreply@anthropic.com>
This is an automated draft PR generated from issue #5584 — a maintainer should review it before merging.
Fixes #5584 (points 1 and 2; point 3 is the duplicate tracked in #5573 / draft PR #5636 and is deliberately not touched here)
Summary
async_fetch_standing_charges()used to bumpfailures_totalon every non-200, before checking whether the status was the expected 404/410. For E.ON Next TOU tariffs, where theapplicableStandingChargesGraphQL fallback works, that meant one extra failure every cycle with nothing wrong. The fix uses the guard the rates path already has (async_fetch_rates, fromed8db21a): take a snapshot offailures_totalbefore the fallback, and add one only if the fallback returnsNonewithout having counted a failure itself. TheWarn: ... Standing charges HTTPlog now fires only on the paths that really fail. The expected 404 logs only the existing info line about falling back._fetch_rates_rest()andasync_fetch_standing_charges()now catchValueErroras well as(aiohttp.ClientError, asyncio.TimeoutError).json.JSONDecodeErroris a subclass ofValueError. The GraphQL path in the same file (async_graphql_query) already catches it this way. Before this change, a 200 whose body claimed to be JSON but didn't parse escapedrun().ComponentBase.start()caught it, but the rest of that cycle was skipped (dispatches, sensor publishing, import/export wiring), and startup backoff kicked in on thefirstpath. Now the bad body is logged and counted like any other failed fetch. In_fetch_rates_restit returns the existing(None, None)network-error result, soasync_fetch_rateshandles it the way it already handles network errors.Testing
coverage/run_pre_commit: all hooks passed (ruff, black, cspell, markdownlint, …), and the quick suite it runs endedAll tests passed (4 slow tests skipped).tools/triage_test.sh kraken: passes with the fix.kraken.py(git stash push -u -- apps/predbat/kraken.py). The kraken runner stops at its first failure, so I re-ran it once per failure, temporarily disabling the test that had just failed (renames reverted before committing). Without the fix, each of the four new behaviour tests failed:test_fetch_rates_undecodable_200_is_counted_not_raised:JSONDecodeError: Expecting valuetest_fetch_standing_charges_404_graphql_failure_counts_once_not_twice:got 2test_fetch_standing_charges_404_recovered_by_graphql_is_not_a_failure:got 1test_fetch_standing_charges_undecodable_200_is_counted_not_raised:JSONDecodeError: Expecting valuetest_fetch_standing_charges_404_graphql_empty_counts_one_failure, and a newfailures_total == 1assertion added to the existingtest_fetch_standing_charges_transient_error_does_not_fall_back_to_graphql(429/500/503).Notes
async_fetch_ratesand once inasync_fetch_standing_charges. I kept the copies separate instead of adding a helper, because each is three lines and a shared helper would mean changing the rates path too, which this issue doesn't need.results[0]pick just below the hunk changed here, so there could be a small textual merge conflict depending on which merges first. The two changes don't depend on each other's logic.AttributeErroratdata.get(...). The issue didn't report that case, so I didn't widen the change for it.async_fetch_standing_chargesand_fetch_rates_resteach have one direct caller, both inside the Krakenrunflow, so risk is LOW.detect_changesalso reports low risk.🤖 Generated with Claude Code