Skip to content

Leave out a Volvo's energy-state when it answers a plain 404 - #434

Merged
vcanuel merged 1 commit into
mainfrom
fix/energy-state-missing-endpoint
Nov 19, 2026
Merged

vcanuel merged 1 commit into
mainfrom
fix/energy-state-missing-endpoint

Conversation

@vcanuel

@vcanuel vcanuel commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

A Volvo without the Energy API (a combustion or mild-hybrid car) answers energy-state with a plain 404. The collector recorded it as the vehicle's failure (not_found) at every poll, newer than its read_at, and spent a call each time.

  • energy-state's plain 404 (KindNotFound, energyMissing) now takes the optional endpoints' path in fetchFailed: left out for a details interval, logged once, no failure told.
  • The market's refusal, a 404 on the same endpoint but KindMarket (does not belong to allowed markets), keeps its own path and still sets market_refused_at.
  • The charging state comes from energy-state alone: once it is missing, it is cleared, so that a vehicle seen charging does not stay in the charging mode, polled every minute.
  • AGENTS.md: the optional endpoints' line says so.

A not_found failure already stored stays until another failure replaces it (a zero failure keeps the stored one, as before).

Closes #433

How it was tested

  • TestFailures: a vehicle whose energy-state answers a plain 404 over 25 hours is called twice for it, has no failure, no market marked, one log line; a vehicle seen charging whose energy-state then answers 404 goes back to parked, its charging state unknown. Both fail without the change (mutation checked); the existing market-refused cases pass unchanged.

  • task unit-go (fmt-check, lint, tests without PostgreSQL, govulncheck, build).

  • task unit passes (unit-go; the front end is untouched)

  • The API's diff (api/openapi.yaml, internal/api/testdata/) is intended, or there is none

  • Texts in English, French, German, Italian, Dutch, Norwegian, Spanish and Swedish, if the interface changed

  • No real VIN, token, API key or position, fixtures included

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • A missing energy-state endpoint is now handled as unavailable rather than as a vehicle failure. Collection continues, and charging status remains unknown when energy data cannot be retrieved.
    • If a vehicle was previously reported as charging, a subsequent missing energy-state response clears that activity and reports the vehicle as parked.
    • Market-specific errors continue to be handled separately.

A Volvo without the Energy API (a combustion or mild-hybrid car) answers
energy-state with a plain 404. It was recorded as the vehicle's failure
at every poll, newer than its latest read, and a call spent each time.
It now takes the optional endpoints' path: left out for a details
interval, logged once, no failure. The market's refusal, a 404 there
too but KindMarket, still marks the market.

The charging state comes from energy-state alone: once it is missing,
none is known, so that a vehicle seen charging does not stay in the
charging mode.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@coderabbitai

coderabbitai Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The collector now treats a plain EnergyState 404 as a missing endpoint and retries at the details interval. If the endpoint had indicated charging, the collector clears that state. Market-specific 404 responses remain classified separately.

Changes: EnergyState missing-endpoint handling

Layer / File(s) Summary
Classify and handle missing EnergyState
internal/collector/collector.go
energyMissing matches only EnergyState errors with KindNotFound. fetchFailed schedules a retry at the details interval and clears charging state when needed.
Verify and document missing-endpoint behavior
internal/collector/collector_test.go, AGENTS.md
Tests cover retry timing, failure and market status, and clearing a prior charging state. The documentation distinguishes a plain EnergyState 404 from a market-specific 404.

Severity of issue fixed: Medium

Merge Risk: Minimal · up to ff012

A plain energy-state 404 is now treated as a missing optional endpoint. It is skipped for a details interval, logged once, and no failure is recorded. Market-specific 404 responses keep their existing handling. The change is small and easy to revert, and no actionable merge risk remains.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "Leave out a Volvo's energy-state when it answers a plain 404" describes the main change: a plain 404 from the Volvo energy-state endpoint is now skipped as a missing optional endpoint inste…
Description check Passed The description explains the problem (a non-Energy-API Volvo answers energy-state with a plain 404 that was recorded as not_found at every poll), lists the behavior changes (optional-endpoint path in …
Linked Issues check Passed [#433] Requirement 1: a plain 404 on energy-state must use the missing-endpoint path. internal/collector/collector.go adds energyMissing(ep, apiErr), which matches volvo.EnergyState with KindNotFound,…
Out of Scope Changes check Passed All changes map to #433 or support it. collector.go: energyMissing helper and the fetchFailed branch implement the requested behavior. The added charging-state clearing applies only to the missing ene…
Full details: Title check

Explanation

The title "Leave out a Volvo's energy-state when it answers a plain 404" describes the main change: a plain 404 from the Volvo energy-state endpoint is now skipped as a missing optional endpoint instead of being recorded as a failure. It is imperative and in English, but it does not follow the requested "Add/Fix ..." style exactly; the phrasing "Leave out" is imperative and acceptable, and the title is specific and descriptive.

Full details: Description check

Explanation

The description explains the problem (a non-Energy-API Volvo answers energy-state with a plain 404 that was recorded as not_found at every poll), lists the behavior changes (optional-endpoint path in fetchFailed, KindMarket path preserved, charging state cleared, AGENTS.md update, stored failure handling), gives a test plan, and references Closes #433. Template checklist items are present. The 'How it was tested' section lists task unit-go but the template's 'task unit' checkbox is ticked with a parenthetical clarification; the description is mostly complete.

Full details: Linked Issues check

Explanation

[#433] Requirement 1: a plain 404 on energy-state must use the missing-endpoint path. internal/collector/collector.go adds energyMissing(ep, apiErr), which matches volvo.EnergyState with KindNotFound, and adds it to the condition in fetchFailed. That branch sets vs.missing[Endpoint(ep)] to now plus detailsInterval, and logs once. It returns before vs.failure is set, so no failure is recorded and last_failure is not refreshed. Requirement 2: a test verifies this. TestFailures ('energy-state missing: no failure, tried again at the details' pace') runs 25 hours of polls and asserts energy-state is called exactly twice, no Failure.At is set, no market is recorded, and the log line appears once. The market refusal is kept apart. energyMissing requires KindNotFound, so a KindMarket 404 falls through to endpointRefused, as the issue requires. The existing market-refused cases are reported unchanged. The PR also clears the charging state when energy-state is missing (#433 does not require this; it supports the parked-state correctness of the change). Residual uncertainty: the classification of the market 404 as KindMarket is in the volvo package, which I did not inspect; the verdict relies on the PR's stated test results for that case.

Full details: Out of Scope Changes check

Explanation

All changes map to #433 or support it. collector.go: energyMissing helper and the fetchFailed branch implement the requested behavior. The added charging-state clearing applies only to the missing energy-state path and is needed so a vehicle seen charging does not stay in charging mode; it is closely tied to the same endpoint. collector_test.go: the scriptedAPI bodies field supports the new charging test, and both new subtests cover the issue's acceptance criteria. AGENTS.md: a one-line update documenting the new optional-endpoint behavior, which supports the change. No unrelated files or behavior changes appear in the reviewed diff for these files.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 29b9fc8 and ff01253.

Files selected for processing: 3

  • AGENTS.md
  • internal/collector/collector.go
  • internal/collector/collector_test.go

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@vcanuel
vcanuel merged commit eb97676 into main Nov 19, 2026
8 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.

Collector: a Volvo without the Energy API fails on energy-state at every poll

1 participant