Skip to content

feat(backend): redesign HardwareMonitorUpdate for multi-GPU (#1298)#1332

Merged
shm11C3 merged 10 commits into
developfrom
feat/redesign-gpu-update-event
Apr 11, 2026
Merged

feat(backend): redesign HardwareMonitorUpdate for multi-GPU (#1298)#1332
shm11C3 merged 10 commits into
developfrom
feat/redesign-gpu-update-event

Conversation

@shm11C3

@shm11C3 shm11C3 commented Apr 6, 2026

Copy link
Copy Markdown
Owner

Summary

  • Add GpuMonitorData struct with gpu_id, gpu_name, and per-GPU metrics
  • Replace 6 flat GPU fields in HardwareMonitorUpdate with gpus: Vec
  • Add gpu_id field to GpuSample with platform-specific conventions:
    • Windows NVAPI: nvapi:, ADL: pci:::, PDH: pdh:
    • Linux: pci: or drm:card
    • macOS: iokit:
  • Key gpu_usage_histories/gpu_temperature_histories by gpu_id instead of name
  • Fix gpu_usage_history to read from per-GPU HashMap (accepts gpu_id param)
  • Remove dead gpu_history field from HardwareMonitorState
  • Extract build_gpu_payloads() pure function from emit_hardware_update()
  • Remove GpuCapabilities struct (Option fields communicate availability)
  • Apply temperature unit conversion per-GPU
  • Add gpu_id column to GPU_DATA_ARCHIVE (migration v5)
  • Add gpu_name_map to MonitorResources for archive gpu_id→name lookup
  • Add 24 new tests (236→260), all passing

Related Issues

Close #1298

Type of Change

  • Bug fix (fix/ branch)
  • New feature (feat/ branch)
  • Refactoring (refactor/ branch)
  • Documentation (docs/ branch)
  • Dependencies update
  • Other (chore/ branch)

Screenshots / Videos

Test Plan

  • Manual testing
  • Unit tests

Checklist

  • Self-reviewed the code
  • Linting and formatting pass (npm run lint && npm run format / cargo tauri-lint && cargo tauri-fmt)
  • Tests pass (npm test / cargo tauri-test)
  • No new warnings or errors

Summary by CodeRabbit

  • New Features

    • Multi‑GPU support: monitoring now reports an array of per‑GPU entries with independent usage, temperature, and metadata; includes GPU identifier→name mapping.
  • Database

    • GPU archive schema updated to store GPU identifiers for accurate historical association.
  • API

    • GPU history retrieval accepts a GPU identifier to fetch per‑GPU histories.
  • Tests

    • Expanded coverage for multi‑GPU scenarios, identifier handling, migrations, and history behavior.

shm11C3 added 2 commits April 7, 2026 01:23
- Add GpuMonitorData struct with gpu_id, gpu_name, and per-GPU metrics
- Replace 6 flat GPU fields in HardwareMonitorUpdate with gpus: Vec<GpuMonitorData>
- Add gpu_id field to GpuSample with platform-specific conventions:
  - Windows NVAPI: nvapi:<name>, ADL: pci:<bus>:<device>:<function>, PDH: pdh:<name>
  - Linux: pci:<bdf> or drm:card<id>
  - macOS: iokit:<name>
- Key gpu_usage_histories/gpu_temperature_histories by gpu_id instead of name
- Fix gpu_usage_history to read from per-GPU HashMap (accepts gpu_id param)
- Remove dead gpu_history field from HardwareMonitorState
- Extract build_gpu_payloads() pure function from emit_hardware_update()
- Remove GpuCapabilities struct (Option fields communicate availability)
- Apply temperature unit conversion per-GPU
- Add gpu_id column to GPU_DATA_ARCHIVE (migration v5)
- Add gpu_name_map to MonitorResources for archive gpu_id→name lookup
- Add 24 new tests (236→260), all passing
Copilot AI review requested due to automatic review settings April 6, 2026 16:24
@coderabbitai

coderabbitai Bot commented Apr 6, 2026

Copy link
Copy Markdown
Contributor

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: c5ac050b-cacf-4fc9-be37-f45496f041e1

📥 Commits

Reviewing files that changed from the base of the PR and between e7ce010 and d1495d0.

📒 Files selected for processing (1)
  • src/features/hardware/hooks/useHardwareEventListener.test.ts

📝 Walkthrough

Walkthrough

Implements multi‑GPU support: adds per‑GPU IDs and GpuMonitorData, changes HardwareMonitorUpdate to carry gpus: Vec<GpuMonitorData>, rekeys histories/archives by gpu_id, updates get_gpu_usage_history to accept gpu_id, adds DB migration for gpu_id, and wires a gpu_id→name map through monitoring and archive paths.

Changes

Cohort / File(s) Summary
Core GPU Models
src-tauri/src/models/hardware.rs, src-tauri/src/models/hardware_archive.rs
Add GpuMonitorData; replace flat GPU fields in HardwareMonitorUpdate with gpus: Vec<GpuMonitorData>; remove gpu_history from HardwareMonitorState; add optional gpu_id to archive GpuData; add gpu_name_map to MonitorResources.
Sampling & Histories
src-tauri/src/services/monitoring_service.rs, src-tauri/src/workers/system_monitor.rs
Add gpu_id to GpuSample; populate platform-specific gpu_id; key gpu_*_histories by gpu_id; build per‑GPU payloads and emit multi‑GPU updates; populate gpu_name_map.
Commands & Frontend Bindings
src-tauri/src/commands/hardware.rs, src/rspc/bindings.ts, src/features/hardware/hooks/useHardwareEventListener.ts
get_gpu_usage_history now accepts gpu_id; TS bindings/types updated to GpuMonitorData and gpus[]; frontend listener updated to consume gpus and pick first GPU for existing atoms.
Archival & Database
src-tauri/src/services/archive_service.rs, src-tauri/src/infrastructure/database/gpu_archive.rs, src-tauri/src/infrastructure/database/migration.rs
Wire gpu_name_map into archive collector; archive INSERT includes gpu_id; add migration v5 ALTER TABLE GPU_DATA_ARCHIVE ADD COLUMN gpu_id TEXT;.
App State Wiring
src-tauri/src/lib.rs
Remove shared gpu_history VecDeque from app state; add and wire gpu_name_map: Arc<Mutex<HashMap<...>>> into HardwareMonitorState, monitor and archive controllers.
Tests & Frontend Tests
src-tauri/..., src/features/hardware/hooks/useHardwareEventListener.test.ts
Update/add tests for GpuMonitorData serialization, gpu_id-keyed histories, archive name fallback, migration presence/sequencing, and frontend listener changes.

Sequence Diagram

sequenceDiagram
    participant Drivers as Drivers (OS/Platform)
    participant MS as MonitoringService
    participant SM as SystemMonitor
    participant AS as ArchiveService
    participant DB as Database
    participant UI as Frontend UI

    Drivers->>MS: sample GPUs -> Vec<GpuSample { gpu_id, name, metrics }>
    MS->>MS: update_gpu_histories(key=gpu_id) & update gpu_name_map
    MS->>SM: deliver gpu samples
    SM->>SM: build_gpu_payloads -> Vec<GpuMonitorData>
    SM->>UI: emit_hardware_update(payload with gpus[])
    UI->>UI: consume payload.gpus (select primary GPU for UI atoms)
    SM->>AS: archive_current_snapshot(gpus keyed by gpu_id + gpu_name_map)
    AS->>DB: insert GPU archive rows (include gpu_id)
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related issues

Possibly related PRs

Poem

🐰
I hopped through code and midnight logs,
gave every GPU its tidy cogs.
IDs and names in ordered rows,
histories grow where data flows.
Multi‑GPU — tiny happy hops!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: a redesign of HardwareMonitorUpdate to support multi-GPU representation.
Description check ✅ Passed The description provides a solid summary of changes with specific details about GpuMonitorData, gpu_id conventions, database migrations, and test coverage. The template sections (type of change, test plan, checklist) are left incomplete.
Linked Issues check ✅ Passed All coding requirements from #1298 are met: GpuMonitorData struct added, HardwareMonitorUpdate redesigned, emit_hardware_update rewritten for multi-GPU, gpu_id added to GpuSample with platform conventions, gpu_usage_histories keyed by gpu_id, dead gpu_history removed, build_gpu_payloads extracted, GpuCapabilities removed, database migration v5 added with gpu_id column, and gpu_name_map for archive lookups.
Out of Scope Changes check ✅ Passed All changes are directly aligned with redesigning HardwareMonitorUpdate for multi-GPU support per #1298; no out-of-scope modifications detected.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/redesign-gpu-update-event

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions Bot added rust Pull requests that update Rust code feature labels Apr 6, 2026
@github-actions

github-actions Bot commented Apr 6, 2026

Copy link
Copy Markdown
Contributor

Rust Backend Coverage Report

Coverage Details
Filename                                         Regions    Missed Regions     Cover   Functions  Missed Functions  Executed       Lines      Missed Lines     Cover    Branches   Missed Branches     Cover
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
_tests/commands/background_image_test.rs              39                 0   100.00%           6                 0   100.00%          21                 0   100.00%           0                 0         -
_tests/commands/settings_test.rs                     220                 0   100.00%          18                 0   100.00%         167                 0   100.00%           0                 0         -
commands/background_image.rs                          22                 7    68.18%          11                 5    54.55%          19                 7    63.16%           0                 0         -
commands/hardware.rs                                  66                66     0.00%          20                20     0.00%          66                66     0.00%           0                 0         -
commands/settings.rs                                 544               544     0.00%          97                97     0.00%         463               463     0.00%           0                 0         -
commands/system.rs                                     6                 6     0.00%           3                 3     0.00%           5                 5     0.00%           0                 0         -
commands/ui.rs                                        17                17     0.00%           2                 2     0.00%          13                13     0.00%           0                 0         -
commands/updater.rs                                   97                97     0.00%          15                15     0.00%          66                66     0.00%           0                 0         -
enums/error.rs                                       105                 0   100.00%           8                 0   100.00%          89                 0   100.00%           0                 0         -
enums/hardware.rs                                    188                 1    99.47%          15                 0   100.00%         114                 0   100.00%           0                 0         -
enums/settings.rs                                    415                 6    98.55%          24                 0   100.00%         279                 0   100.00%           0                 0         -
infrastructure/database/db.rs                         21                21     0.00%           2                 2     0.00%          12                12     0.00%           0                 0         -
infrastructure/database/gpu_archive.rs                51                51     0.00%           4                 4     0.00%          18                18     0.00%           0                 0         -
infrastructure/database/hardware_archive.rs           41                41     0.00%           4                 4     0.00%          21                21     0.00%           0                 0         -
infrastructure/database/migration.rs                  54                 1    98.15%           7                 0   100.00%          74                 0   100.00%           0                 0         -
infrastructure/database/process_stats.rs              41                41     0.00%           4                 4     0.00%          29                29     0.00%           0                 0         -
infrastructure/providers/linux/dmidecode.rs          229                15    93.45%          16                 3    81.25%         319                14    95.61%           0                 0         -
infrastructure/providers/linux/drm_sys.rs            205               156    23.90%          21                14    33.33%         126                93    26.19%           0                 0         -
infrastructure/providers/linux/hwmon.rs              119                94    21.01%           8                 6    25.00%          68                56    17.65%           0                 0         -
infrastructure/providers/linux/kernel.rs             165                22    86.67%          19                 2    89.47%         161                 8    95.03%           0                 0         -
infrastructure/providers/linux/lspci.rs               83                20    75.90%           8                 2    75.00%          50                11    78.00%           0                 0         -
infrastructure/providers/linux/net_sys.rs            171               171     0.00%          13                13     0.00%          93                93     0.00%           0                 0         -
infrastructure/providers/linux/procfs.rs             261                24    90.80%          25                 3    88.00%         222                19    91.44%           0                 0         -
infrastructure/providers/sysinfo_provider.rs          54                54     0.00%           2                 2     0.00%          45                45     0.00%           0                 0         -
lib.rs                                               211               211     0.00%           5                 5     0.00%         115               115     0.00%           0                 0         -
main.rs                                                3                 3     0.00%           1                 1     0.00%           3                 3     0.00%           0                 0         -
models/hardware.rs                                   292                 0   100.00%          19                 0   100.00%         175                 0   100.00%           0                 0         -
models/hardware_archive.rs                             3                 0   100.00%           1                 0   100.00%           7                 0   100.00%           0                 0         -
models/settings.rs                                   301                 0   100.00%          17                 0   100.00%         264                 0   100.00%           0                 0         -
platform/factory.rs                                   18                18     0.00%           4                 4     0.00%          15                15     0.00%           0                 0         -
platform/linux/cache.rs                               53                53     0.00%           4                 4     0.00%          38                38     0.00%           0                 0         -
platform/linux/gpu.rs                                143               143     0.00%          14                14     0.00%         105               105     0.00%           0                 0         -
platform/linux/memory.rs                              43                43     0.00%           6                 6     0.00%          41                41     0.00%           0                 0         -
platform/linux/mod.rs                                 34                34     0.00%          11                11     0.00%          70                70     0.00%           0                 0         -
platform/linux/network.rs                              4                 4     0.00%           1                 1     0.00%           4                 4     0.00%           0                 0         -
services/archive_service.rs                         1234               155    87.44%          93                15    83.87%         694               135    80.55%           0                 0         -
services/background_image_service.rs                 165                96    41.82%          16                10    37.50%          93                59    36.56%           0                 0         -
services/cpu_service.rs                               32                32     0.00%           4                 4     0.00%          15                15     0.00%           0                 0         -
services/gpu_service.rs                               37                37     0.00%          10                10     0.00%          31                31     0.00%           0                 0         -
services/hardware_service.rs                          67                67     0.00%           5                 5     0.00%          43                43     0.00%           0                 0         -
services/language_service.rs                         101                 0   100.00%          18                 0   100.00%          57                 0   100.00%           0                 0         -
services/memory_service.rs                            22                22     0.00%           4                 4     0.00%          15                15     0.00%           0                 0         -
services/monitoring_service.rs                      1114               161    85.55%          75                19    74.67%         574               104    81.88%           0                 0         -
services/motherboard_service.rs                       10                10     0.00%           3                 3     0.00%           7                 7     0.00%           0                 0         -
services/network_service.rs                            9                 9     0.00%           1                 1     0.00%           7                 7     0.00%           0                 0         -
services/process_service.rs                           86                86     0.00%           5                 5     0.00%          50                50     0.00%           0                 0         -
services/settings_service.rs                         338               158    53.25%          34                16    52.94%         288               148    48.61%           0                 0         -
services/system_service.rs                            22                22     0.00%           2                 2     0.00%          12                12     0.00%           0                 0         -
services/ui_service.rs                                45                45     0.00%           8                 8     0.00%          36                36     0.00%           0                 0         -
utils/color.rs                                        66                 1    98.48%           4                 0   100.00%          26                 0   100.00%           0                 0         -
utils/file.rs                                        224                 5    97.77%          14                 0   100.00%         144                 4    97.22%           0                 0         -
utils/formatter.rs                                   195                 8    95.90%          16                 0   100.00%         160                12    92.50%           0                 0         -
utils/ip.rs                                           65                 0   100.00%           5                 0   100.00%          33                 0   100.00%           0                 0         -
utils/logger.rs                                       71                71     0.00%           1                 1     0.00%          38                38     0.00%           0                 0         -
utils/rounding.rs                                     68                 0   100.00%           7                 0   100.00%          41                 0   100.00%           0                 0         -
utils/tauri.rs                                       138                 0   100.00%          17                 0   100.00%          82                 0   100.00%           0                 0         -
workers/hardware_archive.rs                           52                52     0.00%           6                 6     0.00%          36                36     0.00%           0                 0         -
workers/mod.rs                                        24                24     0.00%           2                 2     0.00%          16                16     0.00%           0                 0         -
workers/system_monitor.rs                            261                97    62.84%          18                 6    66.67%         150                66    56.00%           0                 0         -
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
TOTAL                                               8765              3122    64.38%         803               364    54.67%        6025              2264    62.42%           0                 0         -

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR redesigns the backend hardware monitoring payload and related history/archive plumbing to properly support multiple GPUs by introducing a per-GPU data structure and keying GPU histories by a stable-ish gpu_id rather than GPU name.

Changes:

  • Introduces GpuMonitorData and updates HardwareMonitorUpdate to emit gpus: Vec<GpuMonitorData> instead of flat single-GPU fields.
  • Adds gpu_id to GpuSample, rekeys GPU histories by gpu_id, and updates the get_gpu_usage_history command accordingly.
  • Extends GPU archive persistence with a new gpu_id column + inserts gpu_id and maintains a gpu_id → gpu_name map for archive naming.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src-tauri/src/workers/system_monitor.rs Builds per-GPU payloads and emits multi-GPU HardwareMonitorUpdate; adds unit tests for payload building.
src-tauri/src/services/monitoring_service.rs Adds gpu_id to GpuSample, rekeys histories to gpu_id, and updates GPU usage history lookup + tests.
src-tauri/src/services/archive_service.rs Archives GPU metrics by gpu_id and uses a gpu_id → gpu_name map for naming.
src-tauri/src/models/hardware.rs Adds GpuMonitorData, updates HardwareMonitorUpdate, removes dead single-GPU history field, adds serialization tests.
src-tauri/src/models/hardware_archive.rs Adds gpu_id to archived GPU model and adds gpu_name_map to shared monitor resources.
src-tauri/src/lib.rs Wires up the new gpu_name_map resource and removes the unused GPU history buffer initialization.
src-tauri/src/infrastructure/database/migration.rs Adds migration v5 to add gpu_id column and introduces migration-related unit tests.
src-tauri/src/infrastructure/database/gpu_archive.rs Inserts gpu_id into GPU_DATA_ARCHIVE.
src-tauri/src/commands/hardware.rs Updates get_gpu_usage_history command signature to accept gpu_id.

Comment thread src-tauri/src/services/monitoring_service.rs
Comment thread src-tauri/src/commands/hardware.rs
Comment thread src-tauri/src/infrastructure/database/migration.rs

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src-tauri/src/services/monitoring_service.rs (1)

119-127: ⚠️ Potential issue | 🔴 Critical

Use gpu.gpu_id() instead of GPU model name to ensure unique identifiers for identical NVIDIA GPUs.

The code currently assigns gpu_id as nvapi:{name} where name is gpu.full_name() (e.g., "NVIDIA GeForce RTX 4090"). This approach produces duplicate IDs for systems with multiple identical NVIDIA GPUs, causing their usage histories to be merged into a single entry.

The PhysicalGpu reference has access to gpu_id() -> Result<u32>, which returns NVAPI's unique per-GPU identifier. This method is already used elsewhere in the codebase (see nvapi_provider.rs:187 in get_nvidia_gpu_info). Update line 120 to use gpu.gpu_id() instead:

gpu_id: format!("nvapi:{}", gpu.gpu_id().unwrap_or(0))

This ensures each physical GPU gets a unique identifier regardless of model name, maintaining separate history tracking for multi-GPU systems.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src-tauri/src/services/monitoring_service.rs` around lines 119 - 127, The
GpuSample currently uses the GPU model name for gpu_id which yields duplicate
IDs for identical NVIDIA cards; update the GpuSample construction to use the
NVAPI per-GPU identifier by calling gpu.gpu_id() (e.g., format!("nvapi:{}",
gpu.gpu_id().unwrap_or(0))) so each PhysicalGpu gets a unique gpu_id; change the
gpu_id field in the GpuSample creation (the block that builds GpuSample with
name/usage/temperature/dedicated_memory_kb/cooler_level/source) to format the id
from gpu.gpu_id() instead of using the model name.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src-tauri/src/commands/hardware.rs`:
- Around line 186-194: The command get_gpu_usage_history signature changed to
include gpu_id but its doc comment and the TypeScript binding were not updated;
add/update the function doc comment to document the new gpu_id parameter,
annotate the function with #[specta::specta] (or ensure it is included in the
specta export) so the new signature is picked up, then regenerate the TypeScript
bindings so the frontend typing reflects (gpu_id: string, seconds: number) and
update any frontend callers to pass the gpu_id argument accordingly.

In `@src-tauri/src/models/hardware.rs`:
- Around line 20-27: The frontend listener in useHardwareEventListener is still
destructuring old flat GPU fields (gpuUsage, gpuName, gpuTemperature, gpuSource,
gpuDedicatedMemoryUsageKb, gpuCoolerLevel) but the backend now emits
HardwareMonitorUpdate with gpus: Vec<GpuMonitorData>; update the event handler
to iterate/map over event.gpus, extract the required properties from each
GpuMonitorData object, and feed those mapped values into the existing
merge/history/fan-temperature logic instead of relying on the old flat
destructured variables; remove the old flat destructuring and replace usages
with the mapped per-GPU data so all downstream functions (history tracking,
temperature display, fan updates) receive the correct shape.

---

Outside diff comments:
In `@src-tauri/src/services/monitoring_service.rs`:
- Around line 119-127: The GpuSample currently uses the GPU model name for
gpu_id which yields duplicate IDs for identical NVIDIA cards; update the
GpuSample construction to use the NVAPI per-GPU identifier by calling
gpu.gpu_id() (e.g., format!("nvapi:{}", gpu.gpu_id().unwrap_or(0))) so each
PhysicalGpu gets a unique gpu_id; change the gpu_id field in the GpuSample
creation (the block that builds GpuSample with
name/usage/temperature/dedicated_memory_kb/cooler_level/source) to format the id
from gpu.gpu_id() instead of using the model name.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: f11f9af5-a8bd-476c-b295-90d85db6e225

📥 Commits

Reviewing files that changed from the base of the PR and between 147fc1b and 06a4cb2.

📒 Files selected for processing (9)
  • src-tauri/src/commands/hardware.rs
  • src-tauri/src/infrastructure/database/gpu_archive.rs
  • src-tauri/src/infrastructure/database/migration.rs
  • src-tauri/src/lib.rs
  • src-tauri/src/models/hardware.rs
  • src-tauri/src/models/hardware_archive.rs
  • src-tauri/src/services/archive_service.rs
  • src-tauri/src/services/monitoring_service.rs
  • src-tauri/src/workers/system_monitor.rs

Comment thread src-tauri/src/commands/hardware.rs
Comment thread src-tauri/src/models/hardware.rs
shm11C3 added 4 commits April 7, 2026 01:41
gpu_id was derived from the GPU model name, which produces duplicate
IDs when multiple identical GPUs are installed. Use gpu.gpu_id()
to ensure each physical GPU gets a unique identifier.
Update useHardwareEventListener to handle the new gpus array in
HardwareMonitorUpdate. Uses gpus[0] to maintain single-GPU display
until full multi-GPU frontend support is implemented (#1299).

Also includes regenerated TypeScript bindings for the updated
backend types.
shm11C3 added 2 commits April 11, 2026 19:00
Update makePayload helper and all GPU-related test cases to use the
new gpus array structure instead of flat GPU fields.
@github-actions

github-actions Bot commented Apr 11, 2026

Copy link
Copy Markdown
Contributor

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 99.1% (🎯 60%) 991 / 1000
🔵 Statements 98.87% (🎯 60%) 1052 / 1064
🔵 Functions 98.79% (🎯 60%) 245 / 248
🔵 Branches 94.03% (🎯 60%) 331 / 352
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
src/features/hardware/hooks/useHardwareEventListener.ts 100% 100% 100% 100%
Generated in workflow #2655 for commit d1495d0 by the Vitest Coverage Report Action

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
src/features/hardware/hooks/useHardwareEventListener.ts (1)

56-69: Consider handling empty gpus array explicitly.

The code handles the case when gpus[0] is undefined via ?? null, but when gpus is an empty array, gpuSource is explicitly set to null (line 69) while other GPU-related atoms like gpuHistory, gpuTemp, gpuDedicatedMemory, and gpuFanSpeed retain their previous values. This creates an inconsistent state where the source shows "no GPU" but stale metrics persist.

Consider resetting all GPU atoms when no GPU data is available:

♻️ Suggested improvement
      // TODO: Multi-GPU support (`#1299`) — for now use the first GPU
      const gpu = gpus[0] ?? null;

      setCpuHistory((prev) => padHistory([...prev, cpuUsage]));
      setMemoryHistory((prev) => padHistory([...prev, memoryUsage]));

-     if (gpu?.gpuUsage != null) {
-       setGpuHistory((prev) => padHistory([...prev, gpu.gpuUsage as number]));
-     }
+     if (gpu?.gpuUsage != null) {
+       setGpuHistory((prev) => padHistory([...prev, gpu.gpuUsage as number]));
+     } else if (!gpu) {
+       // No GPU available - could optionally clear history or push null
+     }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/features/hardware/hooks/useHardwareEventListener.ts` around lines 56 -
69, The current handler only nulls gpuUsageSource when gpus is empty but leaves
stale GPU atoms (gpuHistory, gpuTemp, gpuDedicatedMemory, gpuFanSpeed)
unchanged; update the logic in useHardwareEventListener where gpus and gpu are
derived so that when gpus.length === 0 (or gpu is null) you explicitly reset
setGpuHistory to an empty/padded history, setGpuTemp to an empty array,
setGpuDedicatedMemory to null/0 (matching your atom type), setGpuFanSpeed to
null/0, and setGpuUsageSource to null so all GPU-related state is consistent;
otherwise keep the existing per-field updates (setGpuHistory, setGpuTemp,
setGpuDedicatedMemory, setGpuFanSpeed, setGpuUsageSource) when a gpu is present.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/features/hardware/hooks/useHardwareEventListener.ts`:
- Around line 56-69: The current handler only nulls gpuUsageSource when gpus is
empty but leaves stale GPU atoms (gpuHistory, gpuTemp, gpuDedicatedMemory,
gpuFanSpeed) unchanged; update the logic in useHardwareEventListener where gpus
and gpu are derived so that when gpus.length === 0 (or gpu is null) you
explicitly reset setGpuHistory to an empty/padded history, setGpuTemp to an
empty array, setGpuDedicatedMemory to null/0 (matching your atom type),
setGpuFanSpeed to null/0, and setGpuUsageSource to null so all GPU-related state
is consistent; otherwise keep the existing per-field updates (setGpuHistory,
setGpuTemp, setGpuDedicatedMemory, setGpuFanSpeed, setGpuUsageSource) when a gpu
is present.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: 00f84af5-d5f0-4fdc-8fea-3d31739d5cce

📥 Commits

Reviewing files that changed from the base of the PR and between 06a4cb2 and e7ce010.

📒 Files selected for processing (4)
  • src-tauri/src/commands/hardware.rs
  • src-tauri/src/services/monitoring_service.rs
  • src/features/hardware/hooks/useHardwareEventListener.ts
  • src/rspc/bindings.ts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature frontend rust Pull requests that update Rust code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Backend] Redesign HardwareMonitorUpdate event payload for multi-GPU

2 participants