Skip to content

fix(flatpak): a helper that cannot lock keeps a newer background answer - #114

Merged
bketelsen merged 3 commits into
mainfrom
irulan/112-helper-lock-failure
Oct 28, 2026
Merged

bketelsen merged 3 commits into
mainfrom
irulan/112-helper-lock-failure

Conversation

@frostyard-machines

@frostyard-machines frostyard-machines commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #112 (plan 0008, G2 follow-up).

The bug. When frostnotes-request-background cannot take background.lock, it wrote its failure to background.json without the lock. An older failure could replace a newer helper's answer, and the Settings row "Desktop permission" then stayed on "Asking the desktop…" until Settings closed.

The fix. An unlocked failure never writes background.json:

  • It reads the counter (background-gen) when it writes, and writes background-failure-<generation>.json atomically in the same directory. It removes failures of lower generations.
  • A helper that holds the lock and wrote its answer removes failures up to its generation.
  • The shell (background.rs, state()) reads the answer and the failure of the highest number, and shows the newer one; an answer wins a tie. Only the exact name background-failure-<digits>.json counts.

So no writer without the lock can replace a newer message. (A first version checked the answer before it replaced it; the cross-review showed that check-then-replace still raced. This commit replaces it.)

Tests. internal/packagecheck/background_helper_test.go runs the real helper with python3 and a lock path that is a directory: background.json stays byte for byte, the failure file has the current counter, and lower failures go. Rust unit tests in background.rs cover the choice and the exact name.

Docs. docs/design/app.md (The Flatpak, Background activity) and ADR-0033 (Proposed, edited in place).

Checks. make check passes locally. The Rust compiles and runs only in CI (App shell job): there is no nsl machine on the agents' host.

When the request helper cannot take its lock, it reads the counter when it
writes its failure, and does not replace an answer in background.json whose
generation is at least that counter. An older failure could hide a newer
answer, and the Settings row 'Desktop permission' then stayed on 'Asking the
desktop…' (ADR-0033).

Fixes #112
A helper that could not take the lock wrote its failure to
background.json, so it could replace a newer answer and leave the
Settings row on "Asking the desktop…" (issue #112).

It now writes background-failure-<generation>.json beside the answer,
and removes the failures below its generation. A helper that did take
the lock removes, after it wrote its answer, the failures up to its
generation. The shell reads the answer and the failures, and shows the
newer of the two; an answer wins a tie.

The helper's lock failure has Go tests in internal/packagecheck, and
the shell's choice has Rust unit tests. ADR-0033 and the design doc
say so.
A failure that could not be written still removed the failures of lower
generations, so the shell lost the last message it had.

The unlocked path now removes them only after write_outcome wrote its
own failure. A Go test makes the write fail: the failure's path is a
directory. The docs say the order too.
@frostyard-machines frostyard-machines added the ready-for-human Reviewed, CI green: ready for Brian to review and merge label Oct 28, 2026
@bketelsen
bketelsen merged commit fca0d1c into main Oct 28, 2026
9 checks passed
@bketelsen
bketelsen deleted the irulan/112-helper-lock-failure branch October 28, 2026 19:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-human Reviewed, CI green: ready for Brian to review and merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Settings: 'Desktop permission' can stick on 'Asking the desktop…' after a helper lock failure

2 participants