Skip to content

feat(p987): report why frames fail to decode - #230

Merged
BK1031 merged 1 commit into
mainfrom
bk1031/p987-decode-logging
Aug 29, 2026
Merged

feat(p987): report why frames fail to decode#230
BK1031 merged 1 commit into
mainfrom
bk1031/p987-decode-logging

Conversation

@BK1031

@BK1031 BK1031 commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

Debugging "the 987 is publishing CAN frames, they're landing in storage, but nothing appears live" turned out to be near-impossible: a frame that fails to decode produces no signals, HandleMessage returns early, and the only record is a status field on the stored row. No log, no counter.

  • Count every decode outcome (ok, unknown_can_id, decode_error, invalid_timestamp)
  • Log each distinct (bus, can id, reason) once on first sight, so a new unknown id shows up immediately
  • Roll repeats up every 30s into a single line with decoded/undecodable totals and the loudest offenders, capped at 12 kinds

Rate matters here — frames arrive at a few hundred per second, so a line per failure would bury the log and out-write the disk. The totals matter as much as the reasons: "0 decoded, 4000 undecodable" and "nothing arriving at all" are indistinguishable from the live path today.

Also folds the per-frame invalid-timestamp warning into the same counter, and pulls the status strings into constants so the metadata blob and the reporter can't drift.

Verified against the real failure modes

Published the CAN id from the car's own stack trace plus an over-length frame:

[DECODE] pcan 0x140 decode_error: invalid data length, expected 4 bytes, got 8
[DECODE] pcan 0x66C unknown_can_id: no decoder registered for can id 0x66C on bus pcan
[DECODE] 30s: 40 decoded, 80 undecodable — pcan/0x66C unknown_can_id ×40 pcan/0x140 decode_error ×40

Both are live concerns on the 987, not hypotheticals. 0x66C is on the car and absent from the DBC — which by its own header was decoded from a capture of 35 ids but defines only 30. And FillFromBytes requires an exact length match where the DBC decoder it replaced accepted anything at or over the declared length, so any message whose real DLC exceeds its DBC length now fails outright.

A frame that produces no signals never reaches the live path — it is
stored with a status in its metadata and dropped. That is the right
behaviour, but it was entirely silent, so "frames are arriving and
nothing shows up live" could only be diagnosed by querying ClickHouse.

Count every decode outcome and report it. Each distinct (bus, can id,
reason) logs once when first seen, so a new unknown id is visible
immediately; repeats roll up every 30s into one line carrying the decoded
and undecodable totals plus the worst offenders. Frames arrive at a few
hundred per second, so a line per failure would bury the log and out-write
the disk.

The totals matter as much as the reasons: "0 decoded, 4000 undecodable"
and "nothing arriving at all" look identical from the live path, and now
they don't.

Also replaces the per-frame invalid-timestamp warning with the same
counter, and pulls the status strings into constants so the metadata blob
and the reporter cannot drift apart.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Aug 29, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-08-29T20:37:47.302938Z 9c43c85 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@BK1031
BK1031 merged commit b43365f into main Aug 29, 2026
22 checks passed
@BK1031
BK1031 deleted the bk1031/p987-decode-logging branch August 29, 2026 20:37

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9c43c85bef

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +30 to +34
type decodeKey struct {
bus string
canID int
status string
}

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 Badge Partition decode reports by vehicle

When multiple p987 vehicles publish through this service, this key and the global success/failure counters merge their outcomes because vehicleID is discarded before reporting. A healthy vehicle's decoded frames can therefore mask that another vehicle has zero successful decodes, while the first warning cannot identify which vehicle failed. Since the subscribed topic and upload-key validation are both vehicle-specific, include the vehicle ID in the report key, totals, and log output.

Useful? React with 👍 / 👎.

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