Skip to content

feat(cardwired): internal applications list for smart mode - #162

Merged
luytan merged 16 commits into
mainfrom
cardwire-fdo-whitelist
Aug 7, 2026
Merged

feat(cardwired): internal applications list for smart mode#162
luytan merged 16 commits into
mainfrom
cardwire-fdo-whitelist

Conversation

@luytan

@luytan luytan commented Aug 7, 2026

Copy link
Copy Markdown
Member

Description

Please include a summary of the changes and if applicable, a related issue.

If this PR introduce a new feature, explain your motivations

Fixes # (issue)

TODO

  • Copy-Paste this line

Checklist:

  • My code follows the style guidelines of this project (cargo fmt)
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the mdBook documentation
  • My changes generate no new warnings (clippy/clang)
  • New and existing unit tests pass locally with my changes (either use nix flake check or wait for the ci)

@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@luytan, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 13 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 4d5774c6-682a-4087-8342-fd35bfe1a02f

📥 Commits

Reviewing files that changed from the base of the PR and between b74b8bc and 45fa920.

📒 Files selected for processing (2)
  • crates/cardwire-daemon/src/analyzer/dynamic_analysis.rs
  • crates/cardwire-daemon/src/analyzer/models.rs
📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • Added persistent SQLite storage for application metadata and GPU policies.
    • Added blocked and allowed GPU policy states.
    • Added D-Bus methods to view and update application policies.
    • Improved application identification across desktop apps, Flatpak, Steam, Wine/Proton, Java, and wrapped processes.
    • Newly detected applications are automatically recorded as blocked.
    • Added richer desktop metadata, including display names and icons.
  • Documentation

    • Updated analyzer documentation covering evaluation order, storage, discovery, and overrides.

Walkthrough

The daemon now stores application metadata and GPU policies in SQLite. The analyzer discovers application identities from desktop entries, process data, and Steam environments. D-Bus methods expose policy reads and validated updates.

Changes

Application policy analysis

Layer / File(s) Summary
SQLite policy storage
Cargo.toml, crates/cardwire-daemon/Cargo.toml, crates/cardwire-daemon/src/file/*
Added bundled rusqlite, the app_policies database, GPU policy conversions, metadata storage, cache loading, asynchronous inserts, reads, and updates.
Application metadata and process discovery
crates/cardwire-daemon/src/analyzer/static_analysis.rs, crates/cardwire-daemon/src/analyzer/dynamic_analysis.rs, crates/cardwire-daemon/src/analyzer/helpers.rs, crates/cardwire-daemon/src/analyzer/mod.rs
Added desktop metadata aliases, Steam app ID extraction, /proc process helpers, and shared analyzer exports.
Database-aware analyzer evaluation
crates/cardwire-daemon/src/analyzer/models.rs, crates/cardwire-daemon/src/analyzer/README.md
Updated analyzer construction and evaluation to use GPU variables, cached policies, desktop metadata, Steam fallback discovery, and persistence for new blocked applications.
D-Bus policy operations and daemon wiring
crates/cardwire-daemon/src/interface/smart.rs, crates/cardwire-daemon/src/models.rs, crates/cardwire-daemon/src/file/state.rs
Added asynchronous policy read and update methods. The daemon now passes the database, policy cache, and metadata sender to the relevant components. STATE_PATH is publicly exported.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant DaemonManager
  participant CardwireDatabase
  participant SmartPolicyInterface
  participant CardwireAnalyzer
  DaemonManager->>CardwireDatabase: Build database and load policy cache
  DaemonManager->>SmartPolicyInterface: Pass database handle
  DaemonManager->>CardwireAnalyzer: Pass policy cache and metadata sender
  SmartPolicyInterface->>CardwireDatabase: Read or update application policies
  CardwireAnalyzer->>CardwireDatabase: Persist newly discovered applications
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 3 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description contains only the uncompleted template and omits the change summary, motivation, issue reference, and checklist status. Add a concrete summary, explain the feature motivation, provide an issue reference or state that none applies, and mark completed checklist items.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the addition of an internal applications list for Cardwire smart mode.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

@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: 5

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@crates/cardwire-daemon/src/analyzer/models.rs`:
- Around line 303-308: Update the GpuPolicy::Forced branch in the policy match
to stop returning hardcoded GPU ID 1. Until the policy model and schema carry a
target GPU ID, reject Forced by returning None; otherwise persist and return the
stored target ID while preserving the existing Blocked and Allowed behavior.

In `@crates/cardwire-daemon/src/analyzer/static_analysis.rs`:
- Around line 108-129: Update the Exec argument loop in the static analyzer to
scan all parts for a steam://rungameid/ URI before applying the wrapper-binary
stop condition. Ensure commands such as “steam steam://rungameid/<id>” extract
and insert the Steam app metadata, while retaining the existing wrapper handling
when no URI is present.

In `@crates/cardwire-daemon/src/file/sql.rs`:
- Around line 85-105: Make queued policy inserts report their SQLite outcome:
update the channel and worker around spawn_blocking in sql.rs to return success
or failure for each request, then in analyzer/models.rs update the cache only
after success and remove or retry the pending entry on failure. Apply changes at
crates/cardwire-daemon/src/file/sql.rs lines 85-105 and
crates/cardwire-daemon/src/analyzer/models.rs lines 336-354, preserving the
existing insert behavior and ensuring failed writes do not permanently block
applications.

In `@crates/cardwire-daemon/src/interface/smart.rs`:
- Around line 153-172: Update set_app_policies to serialize the entire policy
update using a dedicated policy-update lock: acquire it before the blocking
database update and hold it through the cache replacement. Add or reuse a
separate mutex field on the owning type, without using the cache RwLock as the
transaction lock, so database and cache updates remain ordered consistently.
- Around line 157-170: Ensure the persistence flow in discover_app acknowledges
completion of the queued SQLite insert before exposing the app in db_cache, so
update_policy cannot run against an unpersisted entry. Add an acknowledgement
path and await it before cache publication, or retry update_policy after
persistence completes; preserve the existing zero-row failure behavior once
persistence has finished.
🪄 Autofix

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: ASSERTIVE

Plan: Pro Plus

Run ID: eda21409-eead-400e-9fc6-0d371abb4421

📥 Commits

Reviewing files that changed from the base of the PR and between a1d1387 and 937a7a3.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (14)
  • .gitignore
  • Cargo.toml
  • crates/cardwire-daemon/Cargo.toml
  • crates/cardwire-daemon/src/analyzer/README.md
  • crates/cardwire-daemon/src/analyzer/dynamic_analysis.rs
  • crates/cardwire-daemon/src/analyzer/helpers.rs
  • crates/cardwire-daemon/src/analyzer/mod.rs
  • crates/cardwire-daemon/src/analyzer/models.rs
  • crates/cardwire-daemon/src/analyzer/static_analysis.rs
  • crates/cardwire-daemon/src/file/mod.rs
  • crates/cardwire-daemon/src/file/sql.rs
  • crates/cardwire-daemon/src/file/state.rs
  • crates/cardwire-daemon/src/interface/smart.rs
  • crates/cardwire-daemon/src/models.rs

Comment thread crates/cardwire-daemon/src/analyzer/models.rs Outdated
Comment thread crates/cardwire-daemon/src/analyzer/static_analysis.rs Outdated
Comment thread crates/cardwire-daemon/src/file/sql.rs Outdated
Comment thread crates/cardwire-daemon/src/interface/smart.rs
Comment thread crates/cardwire-daemon/src/interface/smart.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: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@crates/cardwire-daemon/src/analyzer/models.rs`:
- Around line 338-362: Update discover_app to maintain a separate in-flight
lookup-name guard alongside db_cache, allowing only one database persistence
request for each unknown application at a time. Check and register the name
before sending through db_tx, skip duplicate discoveries while pending, and
remove the pending entry after every reply, send failure, or other exit path;
keep committed GpuPolicy values in db_cache.
🪄 Autofix

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: ASSERTIVE

Plan: Pro Plus

Run ID: 50c4ad3f-4bff-4e36-901f-bb47071098b3

📥 Commits

Reviewing files that changed from the base of the PR and between 937a7a3 and ebe3392.

📒 Files selected for processing (4)
  • crates/cardwire-daemon/src/analyzer/models.rs
  • crates/cardwire-daemon/src/analyzer/static_analysis.rs
  • crates/cardwire-daemon/src/file/sql.rs
  • crates/cardwire-daemon/src/interface/smart.rs

Comment thread crates/cardwire-daemon/src/analyzer/models.rs
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