Skip to content

fix(agent): launch at login from the Flatpak through the Background portal - #2734

Open
vintoware wants to merge 3 commits into
AprilNEA:masterfrom
vintoware:fix/flatpak-autostart-portal
Open

vintoware wants to merge 3 commits into
AprilNEA:masterfrom
vintoware:fix/flatpak-autostart-portal

Conversation

@vintoware

@vintoware vintoware commented Dec 3, 2026 •

Copy link
Copy Markdown

Summary

Settings → General → Launch at login does nothing in the Flatpak. The agent's Linux autostart runs systemctl --user enable, which the sandbox doesn't have:

WARN openlogi_agent::autostart::linux: systemctl --user enable openlogi-agent.service failed to spawn: No such file or directory (os error 2)

It also writes the unit to the sandbox's $XDG_DATA_HOME (~/.var/app/org.openlogi.OpenLogi/data/systemd/user/), which the host's systemd never reads. So the setting is saved as on, but the agent is never started at login.

In a Flatpak, the agent now asks the XDG Background portal instead. RequestBackground with autostart: true and the agent as commandline makes the host write ~/.config/autostart/org.openlogi.OpenLogi.desktop (flatpak run --command=/app/bin/openlogi-agent org.openlogi.OpenLogi). With autostart: false, the host removes that file.

Changes

  • core: new openlogi_core::sandbox::is_flatpak() (behind the fs feature) is now the one place that checks for /.flatpak-info. A new ast-grep guard (core-flatpak-sandbox-owner) flags any other check.
  • permissions: udev::rules_manager calls is_flatpak() instead of checking the file itself.
  • agent:
    • autostart::linux::reconcile sends Flatpak builds to a new autostart/linux/portal.rs, through reconcile_in, which takes the sandbox answer and both routes as arguments so the routing is testable.
    • The systemd arm's claim-marker helpers now take the marker path and the enable/disable step (claim_enablement_at / withdraw_enablement_at), so the portal path uses the same ownership rules. When the setting is off, the agent only contacts the portal to remove an autostart it created. A user who never turned it on never sees a background-permission prompt.
    • The withdraw step reports Done, Failed or Pending, and only Done drops the marker. A portal removal is Pending until the portal confirms it, so a removal that is refused, fails, or is never answered keeps the marker and is asked for again.
    • Only the D-Bus call itself is awaited. Some desktops show a dialog, and reconcile runs at agent startup and inside reload_config, neither of which can wait for the user. The portal's Response is handled on a helper thread. That thread also keeps the bus connection open until the answer arrives, because xdg-desktop-portal cancels a request when its sender leaves the bus.
    • The portal's requests are one Requests state (Idle, Pending with a request id, Confirmed). Reconcile and the response thread change it under one lock. Only the answer to the latest request settles it: a confirmed removal clears the marker, a refusal goes back to Idle, and an answer to a superseded request changes nothing.
    • A request already pending or confirmed for the same state isn't sent again, so repeated settings saves can't stack dialogs.
  • docs: INSTALL-linux.md covers the Flatpak in its Flatpak and Autostart sections.

Like Windows, this is login launch only: there is no equivalent of Restart=on-failure.

Testing

On Fedora 45 aarch64, KDE Plasma 6.8, xdg-desktop-portal 1.22.1 + xdg-desktop-portal-kde 6.8.4:

  • cargo fmt --all -- --check
  • RUSTFLAGS="-D warnings" cargo clippy --workspace --exclude openlogi-ui --exclude openlogi-desktop --exclude openlogi-overlay --all-targets -- -D warnings
  • RUSTFLAGS="-D warnings" cargo test --workspace --exclude openlogi-ui --exclude openlogi-desktop --exclude openlogi-overlay
  • RUSTDOCFLAGS="-D warnings" cargo doc --workspace --no-deps --document-private-items --exclude openlogi-ui --exclude openlogi-desktop --exclude openlogi-overlay --exclude openlogi-agent
  • ast-grep scan passes. Reverting the udev.rs call site makes the new guard fail.
  • Not run locally: the three GPUI crates. This machine is missing a C++ toolchain for freetype-sys, so CI's lanes for those crates are the check. They only gain an extra pub mod in openlogi-core.

The follow-up commit (marker kept until the portal confirms) was checked with cargo fmt, cargo clippy -p openlogi-agent --all-targets -- -D warnings, cargo test -p openlogi-agent --bin openlogi-agent autostart (46 pass), and ast-grep scan.

New regression tests, none needing a session bus:

  • a_flatpak_reconciles_through_the_portal_and_not_systemd: the Flatpak case reaches only the portal, the other case only systemd.
  • disabling_without_a_claim_sends_nothing, enabling_claims_and_asks_for_the_agent_at_login: the portal path keeps the claim rules.
  • a_withdrawn_claim_is_dropped_only_once_the_portal_confirms, a_refused_removal_is_asked_for_again, a_pending_request_is_not_repeated, a_stale_removal_answer_keeps_the_newer_claim: the request state and marker transitions.
  • withdrawing_without_a_claim_runs_nothing, a_claim_is_dropped_only_by_a_completed_withdrawal, only_a_completed_uncontradicted_response_is_granted.

Counter-proof: with the Flatpak branch disabled in reconcile_in, a_flatpak_reconciles_through_the_portal_and_not_systemd fails. With a pending portal removal counted as done (the original marker bug), a_withdrawn_claim_is_dropped_only_once_the_portal_confirms and a_refused_removal_is_asked_for_again fail.

Runtime: built openlogi-agent for aarch64-unknown-linux-musl and ran it inside the installed v0.9.0 Flatpak (flatpak run --filesystem=… --command=…/openlogi-agent org.openlogi.OpenLogi). This was before the follow-up commit:

  1. launch_at_login = true: KDE granted the request without a dialog, and the agent logged Background portal answered requested=true autostart=Some(true). ~/.config/autostart/org.openlogi.OpenLogi.desktop appeared with X-Flatpak=org.openlogi.OpenLogi, and the autostart.enabled marker was recorded.
  2. launch_at_login = false: the portal answered autostart=Some(false), the autostart file was removed, and the marker was cleared.
  3. launch_at_login = false with no marker: the agent made no portal call and logged autostart enablement was not made by OpenLogi; leaving it alone.

Not tested yet: an actual login on a real .flatpak bundle, GNOME's first-run "allow background" dialog, and a runtime pass of the follow-up commit.

`openlogi_permissions::udev` probed `/.flatpak-info` itself. The agent's
autostart is about to branch on the same question, so the probe moves to
`openlogi_core::sandbox::is_flatpak` before a second copy appears, with an
ast-grep guard against probing the file anywhere else.
…ortal

Inside the Flatpak the toggle never worked. The systemd arm ran
`systemctl --user enable`, which the sandbox does not have, and wrote its
unit into the sandbox's `$XDG_DATA_HOME` (`~/.var/app/<id>/data`), which
the host's systemd never reads.

In a Flatpak the agent now asks the XDG Background portal instead:
`RequestBackground` with `autostart` and the agent as `commandline`, which
has the host write (or, with `autostart` cleared, remove)
`~/.config/autostart/org.openlogi.OpenLogi.desktop`. It shares the systemd
arm's enablement claim, so a disabled setting only talks to the portal to
withdraw an autostart this app asked for, and a user who never enabled it
is never shown a background-permission prompt.

Only the request is awaited. The user's answer is logged from a helper
thread, which also keeps the bus connection open until then, since the
portal cancels a request whose sender leaves the bus.
@greptile-apps

greptile-apps Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Confidence Score: 4/5RetriggerView in Greptile

[Medium impact] The behavior change is limited to Linux launch-at-login, mainly for Flatpak users.

The code addresses the marker-loss bug, but the required regression-test counter-proof remains outstanding before merge.

Summary

The PR routes Flatpak login launch through the Background portal instead of systemd.

  • Flatpak agents can now start at login through the desktop portal.
  • The core library now owns the Flatpak check used by Linux integrations.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    Idle -->|Request sent| Pending
    Pending -->|Same state requested; no new request| Pending
    Pending -->|Latest request refused| Idle
    Pending -->|Latest request granted| Confirmed
    Confirmed -->|Opposite state requested| Pending
    Confirmed -->|Same state requested; no new request| Confirmed
    Confirmed -.-> Note[Confirmed removal clears the marker. Older answers do not change state.]
Loading

Reviews (2) · Last reviewed commit: "fix(agent): keep the Flatpak autostart c..." · Reviewed by Greptile

…s removal

The portal route dropped the enablement marker as soon as the removal
request was accepted. A removal the portal then refused, failed, or never
answered left autostart on with no claim, so no later reconcile withdrew it.

The withdraw step now reports Done, Failed, or Pending, and a pending
removal keeps the claim. The portal's requests live in one Requests state
(Idle, Pending with a request id, Confirmed) that reconcile and the response
thread change under one lock. The answer to the latest request alone settles
it: a confirmed removal drops the claim, a refusal returns to Idle so the
next reconcile asks again, and an answer to a superseded request changes
nothing.

Reconcile's Flatpak dispatch goes through reconcile_in, which takes the
sandbox answer and both routes as arguments, so tests now cover the routing,
the withdrawal outcomes, and the portal state transitions. Reverting the
dispatch or the deferred marker clear fails them.

This branch has not been deployed

No deployments
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