Skip to content

fix(hub): support Battery numeric array unmarshaling with json/v2 (#2746) - #2748

Merged
henrygd merged 1 commit into
henrygd:mainfrom
aditya-rai-5:fix/battery-json-v2-unmarshal
Nov 5, 2026
Merged

henrygd merged 1 commit into
henrygd:mainfrom
aditya-rai-5:fix/battery-json-v2-unmarshal

Conversation

@aditya-rai-5

Copy link
Copy Markdown
Contributor

📃 Description

Fixes #2746

On systems that report battery status (e.g., laptops), systems.info includes "bat": [percent, state]. When the hub handles requests to /api/beszel/systemd/logs, Record.UnmarshalJSONField("info", &info) uses PocketBase's encoding/json/v2 engine.

Because system.Battery ([2]uint8) only implemented MarshalJSON, json/v2 defaulted to expecting a base64 string for fixed-size byte arrays, failing with:

json: unable to unmarshal JSON array into Go system.Battery within "/bat"

This error was swallowed in getSystemdLogs, causing the endpoint to treat the agent as lacking journal access and silently returning empty logs {"logs": ""}.

This PR:

  1. Implements UnmarshalJSON on *Battery to decode numeric array tuples ([2]uint8) under both encoding/json (v1) and encoding/json/v2.
  2. Extends TestStatsBatteryNumericArrayUnmarshal to test both v1 and v2 unmarshaling for Battery, Stats, and Info.
  3. Logs errors in getSystemdLogs when UnmarshalJSONField fails so deserialization problems aren't silently swallowed.
  4. Adds an API test case in hub_test to verify systemd log requests succeed in parsing info when an agent reports a battery and journal access.

🪵 Changelog

🔧 Fixed

  • Fixed empty systemd logs on battery-reporting systems caused by encoding/json/v2 failing to unmarshal system.Battery numeric arrays.
  • Logged system record unmarshal errors in getSystemdLogs.

➕ Added

  • Added UnmarshalJSON method for system.Battery.
  • Added test cases covering json/v2 unmarshaling for battery and systemd logs retrieval.

@aditya-rai-5
aditya-rai-5 requested a review from henrygd as a code owner November 1, 2026 07:26
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 1, 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-11-01T07:29:19.708616Z c1e7af9 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.

@henrygd henrygd left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@henrygd
henrygd merged commit e0fc988 into henrygd:main Nov 5, 2026
ivanch added a commit to ivanch/haven that referenced this pull request Nov 15, 2026
This PR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [henrygd/beszel-agent](https://github.com/henrygd/beszel) | patch | `0.21.1` → `0.21.2` |

---

### Release Notes

<details>
<summary>henrygd/beszel (henrygd/beszel-agent)</summary>

### [`v0.21.2`](https://github.com/henrygd/beszel/releases/tag/v0.21.2)

[Compare Source](henrygd/beszel@v0.21.1...v0.21.2)

#### What's Changed

- Add an actions menu with alert settings to the system detail page ([#&#8203;2803](henrygd/beszel#2803))
- Add `FAN_SENSORS` to include or exclude fan sensors ([#&#8203;2713](henrygd/beszel#2713))
- Add styled HTML alert emails ([#&#8203;2697](henrygd/beszel#2697))
- Add `no_self_update` build tag to disable hub and agent self-updates ([#&#8203;2724](henrygd/beszel#2724))
- Add warnings for missing automatic login users and trusted proxy configuration ([#&#8203;2824](henrygd/beszel#2824), [#&#8203;2812](henrygd/beszel#2812))
- Add video encode/decode engine usage to GPU metrics when using nvtop ([#&#8203;2749](henrygd/beszel#2749))
- Limit sign-in attempts to 10 per minute per address ([#&#8203;2642](henrygd/beszel#2642))
- Improve GPU collection retries and back off slow or repeatedly failing reads ([#&#8203;2705](henrygd/beszel#2705), [#&#8203;2687](henrygd/beszel#2687), [#&#8203;2709](henrygd/beszel#2709), [#&#8203;2656](henrygd/beszel#2656))
- Fix hub crashes caused by null entries in agent data ([#&#8203;2834](henrygd/beszel#2834))
- Fix agent health checks incorrectly reporting disconnected agents as healthy ([#&#8203;2825](henrygd/beszel#2825))
- Fix agent connections timing out while waiting for a slow hub ([#&#8203;2772](henrygd/beszel#2772))
- Fix container requests being canceled by requests for other systems ([#&#8203;2838](henrygd/beszel#2838))
- Fix agents being able to overwrite another system's container, service, S.M.A.R.T., or ZFS records ([#&#8203;2835](henrygd/beszel#2835))
- Fix non-admin users being able to change system users
- Fix missing permission checks when moving network monitors between systems ([#&#8203;2714](henrygd/beszel#2714))
- Fix container refreshes overlapping the initial load on the All Containers page
- Fix system users being overwritten when editing a system
- Fix network monitors remaining on the old agent after moving to another system ([#&#8203;2739](henrygd/beszel#2739))
- Fix bulk monitor copy and import for URLs containing commas ([#&#8203;2716](henrygd/beszel#2716))
- Fix alerts not all being saved when enabling multiple alerts quickly ([#&#8203;2781](henrygd/beszel#2781))
- Fix automatic login briefly showing the login form and making redundant requests ([#&#8203;2810](henrygd/beszel#2810))
- Fix password validation on the initial setup form ([#&#8203;2744](henrygd/beszel#2744), [#&#8203;2745](henrygd/beszel#2745))
- Fix hub updates failing due to database access, working directory, or SELinux context issues ([#&#8203;2800](henrygd/beszel#2800), [#&#8203;2801](henrygd/beszel#2801), [#&#8203;2794](henrygd/beszel#2794))
- Fix historical averages including records from the previous interval ([#&#8203;2807](henrygd/beszel#2807))
- Fix failed systemd services being omitted when they have never been active ([#&#8203;2776](henrygd/beszel#2776), [#&#8203;2777](henrygd/beszel#2777))
- Fix NVMe S.M.A.R.T. data being lost when large counters exceed 64 bits ([#&#8203;2732](henrygd/beszel#2732))
- Fix degraded RAID1 arrays with remaining redundancy being reported as failed ([#&#8203;2760](henrygd/beszel#2760))
- Fix LXC memory usage incorrectly subtracting the host's ZFS ARC ([#&#8203;2767](henrygd/beszel#2767))
- Fix swap reporting on macOS ([#&#8203;2778](henrygd/beszel#2778))
- Fix container CPU counts to respect assigned CPU sets ([#&#8203;2728](henrygd/beszel#2728))
- Fix AMD GPU memory usage including GTT on devices without unified memory ([#&#8203;2715](henrygd/beszel#2715))
- Fix stale dnf5 metadata in package update checks ([#&#8203;2790](henrygd/beszel#2790))
- Fix battery data decoding with Go's experimental JSON implementation ([#&#8203;2746](henrygd/beszel#2746), [#&#8203;2748](henrygd/beszel#2748))
- Fix the agent's `-k` flag not accepting a key file path ([#&#8203;2764](henrygd/beszel#2764), [#&#8203;2765](henrygd/beszel#2765))
- Fix unreported S.M.A.R.T. power-on hours and cycles showing as zero ([#&#8203;2719](henrygd/beszel#2719))
- Update Go and Go dependencies

#### New Contributors

- [@&#8203;BiFangKNT](https://github.com/BiFangKNT) made their first contribution in [#&#8203;2685](henrygd/beszel#2685)
- [@&#8203;metronom72](https://github.com/metronom72) made their first contribution in [#&#8203;2729](henrygd/beszel#2729)
- [@&#8203;lightsabit](https://github.com/lightsabit) made their first contribution in [#&#8203;2656](henrygd/beszel#2656)
- [@&#8203;cobalt-kite12](https://github.com/cobalt-kite12) made their first contribution in [#&#8203;2687](henrygd/beszel#2687)
- [@&#8203;sghng](https://github.com/sghng) made their first contribution in [#&#8203;2758](henrygd/beszel#2758)
- [@&#8203;aditya-rai-5](https://github.com/aditya-rai-5) made their first contribution in [#&#8203;2748](henrygd/beszel#2748)
- [@&#8203;pcbeingused333](https://github.com/pcbeingused333) made their first contribution in [#&#8203;2715](henrygd/beszel#2715)
- [@&#8203;duongynhi000005-oss](https://github.com/duongynhi000005-oss) made their first contribution in [#&#8203;2714](henrygd/beszel#2714)
- [@&#8203;crispyaus](https://github.com/crispyaus) made their first contribution in [#&#8203;2790](henrygd/beszel#2790)
- [@&#8203;rowschank](https://github.com/rowschank) made their first contribution in [#&#8203;2801](henrygd/beszel#2801)
- [@&#8203;kevin9327](https://github.com/kevin9327) made their first contribution in [#&#8203;2799](henrygd/beszel#2799)
- [@&#8203;Karanvir1729](https://github.com/Karanvir1729) made their first contribution in [#&#8203;2781](henrygd/beszel#2781)
- [@&#8203;m1h4](https://github.com/m1h4) made their first contribution in [#&#8203;2810](henrygd/beszel#2810)
- [@&#8203;ColumbusLabs](https://github.com/ColumbusLabs) made their first contribution in [#&#8203;2732](henrygd/beszel#2732)
- [@&#8203;toothywalrus](https://github.com/toothywalrus) made their first contribution in [#&#8203;2812](henrygd/beszel#2812)
- [@&#8203;HocVoNgThai](https://github.com/HocVoNgThai) made their first contribution in [#&#8203;2716](henrygd/beszel#2716)

**Full Changelog**: <henrygd/beszel@v0.21.1...v0.21.2>

</details>

---

### Configuration

📅 **Schedule**: (UTC)

- Branch creation
  - At any time (no schedule defined)
- Automerge
  - At any time (no schedule defined)

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Mend Renovate CLI](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0NC4xODEuNSIsInVwZGF0ZWRJblZlciI6IjQ0LjE4MS41IiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6W119-->

---------

Co-authored-by: Renovate Bot <bot@renovateapp.com>
Reviewed-on: https://git.ivanch.me/ivanch/haven/pulls/47
ivanch added a commit to ivanch/haven that referenced this pull request Nov 15, 2026
This PR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [ghcr.io/henrygd/beszel/beszel](https://github.com/henrygd/beszel) | patch | `0.21.1` → `0.21.2` |

---

### Release Notes

<details>
<summary>henrygd/beszel (ghcr.io/henrygd/beszel/beszel)</summary>

### [`v0.21.2`](https://github.com/henrygd/beszel/releases/tag/v0.21.2)

[Compare Source](henrygd/beszel@v0.21.1...v0.21.2)

#### What's Changed

- Add an actions menu with alert settings to the system detail page ([#&#8203;2803](henrygd/beszel#2803))
- Add `FAN_SENSORS` to include or exclude fan sensors ([#&#8203;2713](henrygd/beszel#2713))
- Add styled HTML alert emails ([#&#8203;2697](henrygd/beszel#2697))
- Add `no_self_update` build tag to disable hub and agent self-updates ([#&#8203;2724](henrygd/beszel#2724))
- Add warnings for missing automatic login users and trusted proxy configuration ([#&#8203;2824](henrygd/beszel#2824), [#&#8203;2812](henrygd/beszel#2812))
- Add video encode/decode engine usage to GPU metrics when using nvtop ([#&#8203;2749](henrygd/beszel#2749))
- Limit sign-in attempts to 10 per minute per address ([#&#8203;2642](henrygd/beszel#2642))
- Improve GPU collection retries and back off slow or repeatedly failing reads ([#&#8203;2705](henrygd/beszel#2705), [#&#8203;2687](henrygd/beszel#2687), [#&#8203;2709](henrygd/beszel#2709), [#&#8203;2656](henrygd/beszel#2656))
- Fix hub crashes caused by null entries in agent data ([#&#8203;2834](henrygd/beszel#2834))
- Fix agent health checks incorrectly reporting disconnected agents as healthy ([#&#8203;2825](henrygd/beszel#2825))
- Fix agent connections timing out while waiting for a slow hub ([#&#8203;2772](henrygd/beszel#2772))
- Fix container requests being canceled by requests for other systems ([#&#8203;2838](henrygd/beszel#2838))
- Fix agents being able to overwrite another system's container, service, S.M.A.R.T., or ZFS records ([#&#8203;2835](henrygd/beszel#2835))
- Fix non-admin users being able to change system users
- Fix missing permission checks when moving network monitors between systems ([#&#8203;2714](henrygd/beszel#2714))
- Fix container refreshes overlapping the initial load on the All Containers page
- Fix system users being overwritten when editing a system
- Fix network monitors remaining on the old agent after moving to another system ([#&#8203;2739](henrygd/beszel#2739))
- Fix bulk monitor copy and import for URLs containing commas ([#&#8203;2716](henrygd/beszel#2716))
- Fix alerts not all being saved when enabling multiple alerts quickly ([#&#8203;2781](henrygd/beszel#2781))
- Fix automatic login briefly showing the login form and making redundant requests ([#&#8203;2810](henrygd/beszel#2810))
- Fix password validation on the initial setup form ([#&#8203;2744](henrygd/beszel#2744), [#&#8203;2745](henrygd/beszel#2745))
- Fix hub updates failing due to database access, working directory, or SELinux context issues ([#&#8203;2800](henrygd/beszel#2800), [#&#8203;2801](henrygd/beszel#2801), [#&#8203;2794](henrygd/beszel#2794))
- Fix historical averages including records from the previous interval ([#&#8203;2807](henrygd/beszel#2807))
- Fix failed systemd services being omitted when they have never been active ([#&#8203;2776](henrygd/beszel#2776), [#&#8203;2777](henrygd/beszel#2777))
- Fix NVMe S.M.A.R.T. data being lost when large counters exceed 64 bits ([#&#8203;2732](henrygd/beszel#2732))
- Fix degraded RAID1 arrays with remaining redundancy being reported as failed ([#&#8203;2760](henrygd/beszel#2760))
- Fix LXC memory usage incorrectly subtracting the host's ZFS ARC ([#&#8203;2767](henrygd/beszel#2767))
- Fix swap reporting on macOS ([#&#8203;2778](henrygd/beszel#2778))
- Fix container CPU counts to respect assigned CPU sets ([#&#8203;2728](henrygd/beszel#2728))
- Fix AMD GPU memory usage including GTT on devices without unified memory ([#&#8203;2715](henrygd/beszel#2715))
- Fix stale dnf5 metadata in package update checks ([#&#8203;2790](henrygd/beszel#2790))
- Fix battery data decoding with Go's experimental JSON implementation ([#&#8203;2746](henrygd/beszel#2746), [#&#8203;2748](henrygd/beszel#2748))
- Fix the agent's `-k` flag not accepting a key file path ([#&#8203;2764](henrygd/beszel#2764), [#&#8203;2765](henrygd/beszel#2765))
- Fix unreported S.M.A.R.T. power-on hours and cycles showing as zero ([#&#8203;2719](henrygd/beszel#2719))
- Update Go and Go dependencies

#### New Contributors

- [@&#8203;BiFangKNT](https://github.com/BiFangKNT) made their first contribution in [#&#8203;2685](henrygd/beszel#2685)
- [@&#8203;metronom72](https://github.com/metronom72) made their first contribution in [#&#8203;2729](henrygd/beszel#2729)
- [@&#8203;lightsabit](https://github.com/lightsabit) made their first contribution in [#&#8203;2656](henrygd/beszel#2656)
- [@&#8203;cobalt-kite12](https://github.com/cobalt-kite12) made their first contribution in [#&#8203;2687](henrygd/beszel#2687)
- [@&#8203;sghng](https://github.com/sghng) made their first contribution in [#&#8203;2758](henrygd/beszel#2758)
- [@&#8203;aditya-rai-5](https://github.com/aditya-rai-5) made their first contribution in [#&#8203;2748](henrygd/beszel#2748)
- [@&#8203;pcbeingused333](https://github.com/pcbeingused333) made their first contribution in [#&#8203;2715](henrygd/beszel#2715)
- [@&#8203;duongynhi000005-oss](https://github.com/duongynhi000005-oss) made their first contribution in [#&#8203;2714](henrygd/beszel#2714)
- [@&#8203;crispyaus](https://github.com/crispyaus) made their first contribution in [#&#8203;2790](henrygd/beszel#2790)
- [@&#8203;rowschank](https://github.com/rowschank) made their first contribution in [#&#8203;2801](henrygd/beszel#2801)
- [@&#8203;kevin9327](https://github.com/kevin9327) made their first contribution in [#&#8203;2799](henrygd/beszel#2799)
- [@&#8203;Karanvir1729](https://github.com/Karanvir1729) made their first contribution in [#&#8203;2781](henrygd/beszel#2781)
- [@&#8203;m1h4](https://github.com/m1h4) made their first contribution in [#&#8203;2810](henrygd/beszel#2810)
- [@&#8203;ColumbusLabs](https://github.com/ColumbusLabs) made their first contribution in [#&#8203;2732](henrygd/beszel#2732)
- [@&#8203;toothywalrus](https://github.com/toothywalrus) made their first contribution in [#&#8203;2812](henrygd/beszel#2812)
- [@&#8203;HocVoNgThai](https://github.com/HocVoNgThai) made their first contribution in [#&#8203;2716](henrygd/beszel#2716)

**Full Changelog**: <henrygd/beszel@v0.21.1...v0.21.2>

</details>

---

### Configuration

📅 **Schedule**: (UTC)

- Branch creation
  - At any time (no schedule defined)
- Automerge
  - At any time (no schedule defined)

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Mend Renovate CLI](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0NC4xODEuNSIsInVwZGF0ZWRJblZlciI6IjQ0LjE4MS41IiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6W119-->

---------

Co-authored-by: Renovate Bot <bot@renovateapp.com>
Reviewed-on: https://git.ivanch.me/ivanch/haven/pulls/46
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.

Systemd logs always empty on systems with a battery (json/v2 cannot unmarshal Battery)

2 participants