Skip to content
This repository was archived by the owner on Nov 15, 2026. It is now read-only.

fix(desktop): stop readd when the GNOME session ends - #83

Merged
bketelsen merged 4 commits into
mainfrom
irulan/readd-exits-at-logout
Nov 13, 2026
Merged

bketelsen merged 4 commits into
mainfrom
irulan/readd-exits-at-logout

Conversation

@frostyard-machines

@frostyard-machines frostyard-machines commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Summary

readd in local mode now stops when the GNOME session ends, also when lingering or another session keeps the user's systemd instance (Fixes #81).

  • internal/gnomesession (new): Watch connects to the session bus at the given address, adds a match rule for NameOwnerChanged on org.gnome.SessionManager, then asks the name's owner. Its channel closes when that owner leaves the bus, or the bus connection ends. With no owner, it returns ErrNoSession.
  • cmd/readd: in desktop and local mode, before readd serves, watchSession watches DBUS_SESSION_BUS_ADDRESS. When the session ends, readd stops as daemon.shutdown stops it (workers end, the database closes, the lock is released) and exits 0. With no bus address, no GNOME session, or an unreachable bus, readd logs it once and runs as before. Lodge's readd is unchanged.
  • Flatpak: finish-args gain --talk-name=org.gnome.SessionManager, and no other permission. internal/packagecheck tests the list.
  • github.com/godbus/dbus/v5 v5.2.4 (pure Go), only in internal/gnomesession and the test helper internal/bustest; go-sources.json regenerated.
  • Setup is bounded: Watch parses the unix: address itself, dials the socket, and gives the dial, authentication, Hello, the match rule and the owner lookup 10 s, which readd's own stop can end sooner. The bound is a context that closes the socket: the socket never takes a deadline, so no deadline can end a running watch. Its errors never carry the address or the socket path (only an errno, a deadline, a bus error name or a fixed text).
  • internal/bustest (new, tests only): a private dbus-daemon on a temporary socket; the tests never touch the machine's session bus. The Go tests now need dbus-daemon on PATH (CI's ubuntu-24.04 has it).
  • ADR-0009 records the permission and amends ADR-0008 in part; the overview, docs/README.md and AGENTS.md follow.

Why org.gnome.SessionManager and not logind

Both need a talk permission; Flatpak has no see-only finish-arg.

  • --system-talk-name=org.freedesktop.login1 is on the system bus. It reaches every user's sessions and the machine's power actions (PowerOff, Reboot, Suspend), which polkit allows an active session without a password on most distributions. logind also counts an SSH session as a session, so readd would have to tell session types apart.
  • --talk-name=org.gnome.SessionManager is 1 name on the user's own session bus, owned by gnome-session for the life of the graphical session. Its methods are not all limited to that session: Logout ends it, and Shutdown and Reboot ask for a shutdown or reboot of the machine. readd calls none of them: only AddMatch and GetNameOwner on the bus itself, and it does not register as a session client, so it never delays a logout.
  • On a desktop that is not GNOME, nothing changes. ADR-0009 lists the Inhibit portal's CreateMonitor as a rejected alternative for now.

Risk tier

Risk tier: 3 — risk:high (L1 paths). Each matched path, and why the change is safe:

  • packaging/flatpak/org.frostyard.Frostread.json (L1, sandbox permissions): adds exactly 1 finish-arg, --talk-name=org.gnome.SessionManager, a session-bus talk permission to 1 name. No file system, device, network or system-bus change. TestFlatpakManifest pins the full list.
  • packaging/flatpak/go-sources.json (L1, offline sources): generated by make flatpak-sources; the only change is the godbus v5.2.4 module entries, with their checksums from the Go module proxy.
  • cmd/readd/main.go (L1, sockets and the lock): no socket, mode or lock change. The new code only cancels runCtx (the same stop that daemon.shutdown uses), so the existing ordered stop runs. The bus connection is a client connection; readd still listens only on its private socket.
  • cmd/readd/desktop_test.go (L1): 2 new tests; no existing test changed.
  • internal/packagecheck/flatpak_manifest_test.go (L2): adds the new finish-arg to the expected list.

Docs housekeeping

  • New docs started from their category's TEMPLATE.md (ADR-0009)
  • Every new doc indexed in docs/README.md
  • Cross-links added in both directions (ADR-0009 ↔ ADR-0008 status line, ADR-0009 ↔ design/overview.md)
  • New significant decision recorded as an ADR first, in this PR
  • New or edited ADRs are fact-only: context, decision and consequences
  • Conformance aliases and canonical symlinks are unchanged

Verification

  • make check green (host)
  • make race green
  • make cross green
  • make flatpak-sources run; only go-sources.json changed
  • make vulncheck: No vulnerabilities found.
  • Revert test: in a scratch worktree at the PR head, git checkout origin/main -- cmd/readd/main.go packaging/flatpak/org.frostyard.Frostread.json, then go test -count=1 -run 'TestDesktopStopsWhenTheGNOMESessionEnds|TestFlatpakManifest' ./cmd/readd/ ./internal/packagecheck/:
    • TestDesktopStopsWhenTheGNOMESessionEnds: desktop_test.go:321: readd did not stop when the GNOME session ended
    • TestFlatpakManifest: finish-args = [... --share=network], want [... --share=network --talk-name=org.gnome.SessionManager]
  • Blocking review points fixed (cross-review of 151ea63, findings 1 and 2), each with a guard and 1 .memory/corrections.jsonl line. Revert test in a scratch worktree at 1e77089: with the deadline and context.AfterFunc removed, and the dial error formatted raw:
    • TestWatchBoundsAPeerThatNeverAnswers: watch did not return: the setup is unbounded
    • TestWatchEndsWhenTheContextEndsDuringSetup: watch outlived its context: the setup does not take it
    • TestWatchReportsNoAddress/a_socket_nothing_serves: the error carries the address: gnomesession: connect: dial unix .../frostread-secret-bus-path-7f3a ...
    • TestDesktopLogsNoBusAddress: readd's log carries the bus address
  • Blocking review point fixed (re-review of 1e77089, finding 1: a socket deadline could fire in godbus's reader after the setup answered). No deterministic test reaches that race, so the guard is an AGENTS.md rule (Code conventions) and 1 .memory/corrections.jsonl line. TestWatchOutlivesItsSetupBound guards against a deadline that stays set.

Not checked here: a logout through Flatpak's D-Bus proxy on a real GNOME desktop. The next release's clean-install gate (plan 0002, Phase 10) must check it: with an SSH session open to the desktop, log out of GNOME, and confirm that readd's log shows "the GNOME session ended; readd stops" and flatpak ps shows no readd instance.

Cross-review

  • Reviewer: openai/gpt-6.1-sol. Coders: deepseek/deepseek-flash (Go code and tests), anthropic/claude-opus-5-5 (docs). Base c0da796eeeaa658faba55ce224b95de671dc6c07.
  • Initial review of 151ea63: Not ready. 2 blocking findings (unbounded D-Bus setup; the bus socket path in readd's warning) and 2 low (cancellation could read as a session end; ADR wording on Shutdown/Reboot). All 4 were fixed in 1e77089.
  • Re-review 1 of 1e77089: Not ready. 1 blocking finding (a socket deadline could fire in godbus's reader after setup) and 1 low (the setup callback stayed registered after a failure). Both were fixed in 08be219.
  • Re-review 2 of 08be219: Ready, Blocking: none, no new findings.
  • CI is green at 08be219, the Flatpak (build and test) job included.

readd in local mode watches gnome-session's org.gnome.SessionManager on
the session bus, and stops in order when its owner leaves the bus or the
bus connection ends. The Flatpak gains --talk-name=org.gnome.SessionManager
for it. ADR-0009 records the permission and amends ADR-0008 in part.

Fixes #81
@github-actions github-actions Bot added level:L1 Read every line risk:high Touches a path in .github/risk-paths.json (core ADR-0068) labels Nov 13, 2026
@frostyard-machines
frostyard-machines force-pushed the irulan/readd-exits-at-logout branch from f4d0c21 to 151ea63 Compare November 13, 2026 16:28
…rors

dbus.Connect ran authentication and Hello with no deadline and no
context: a bus that accepts and never answers held readd's start and
its lock. Watch now dials the unix socket itself, with a 10 s deadline
that readd's context also ends. Its errors keep only an errno, a
deadline, a bus error's name or a fixed text: a net error prints the
socket path, and readd logs the error. A signal that comes with the
caller's stop no longer reads as the session's end. ADR-0009 names the
bound, and states that gnome-session's methods include a shutdown or
reboot of the machine.
…ocket

A deadline on the socket could fire in godbus's reader after the owner
lookup answered, and close the connection after the setup returned:
the watch would read that as the session's end. The setup now has a
context of its own (the dial included) whose end closes the socket,
and the setup succeeds only when context.AfterFunc's stop says the
close never ran. Every failure deregisters the close.
@frostyard-machines frostyard-machines added the ready-for-human Reviewed, CI green: ready for Brian to review and merge label Nov 13, 2026
@bketelsen
bketelsen merged commit 7b06231 into main Nov 13, 2026
13 checks passed
@bketelsen
bketelsen deleted the irulan/readd-exits-at-logout branch November 13, 2026 16:57
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

level:L1 Read every line ready-for-human Reviewed, CI green: ready for Brian to review and merge risk:high Touches a path in .github/risk-paths.json (core ADR-0068)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

readd in local mode keeps polling after logout while the user's systemd instance runs

2 participants