Skip to content

watch service: pin the install environment into the unit, verify the systemd path live - #21

Merged
Microck merged 4 commits into
mainfrom
feat/watch-service-verify
Sep 16, 2026
Merged

Microck merged 4 commits into
mainfrom
feat/watch-service-verify

Conversation

@Microck

@Microck Microck commented Sep 16, 2026 •

Copy link
Copy Markdown
Owner

issue #5 was mostly about proving the scheduled checks actually survive the terminal closing, not about writing new features. so i went and ran it for real on this box, and the running of it turned up one bug that mattered plus a few that would have bitten on the platforms i cannot run.

the bug the live run found

a scheduler starts a job with a bare environment. the unit pinned the log path (absolute) but nothing else, so the CLI inside the timer re-resolved its own paths from whatever environment systemd happened to hand it. anyone who sets XDG_DATA_HOME, XDG_STATE_HOME or WALLAPOP_CONFIG in their shell got a timer reading a different, empty state database: no watches, no events, no error, an empty log. silent no-op.

the unit now writes those variables in as they stood at install time, plus the three base-URL overrides. WALLAPOP_SESSION_TOKEN is deliberately not written, a unit file is world-readable.

[Service]
Type=oneshot
Environment="XDG_STATE_HOME=/home/u/state"
ExecStart="/usr/local/bin/wallapop" watch check --all --profile default --format jsonl

three more, from reading rather than running

  • ExecStart is word-split by systemd, so a binary path with a space produced a unit that failed on every single trigger. the executable is quoted now.
  • the launchd plist interpolated paths and URLs raw. one & and the plist stops parsing, and a launchd agent that does not parse just never runs, quietly. every value is XML-escaped now.
  • lingerEnabled read $USER, which a scheduled or su'd process may not have. empty name, loginctl fails, and every status line claims linger is off. it reads the passwd database now.

unit rendering moved into three pure functions (systemdUnits, launchdPlist, schtasksCreate) so the macOS and windows shapes are testable from linux. new tests parse the plist and check the keys launchd needs, and pin the schtasks line exactly.

what was verified live

linux, systemd 249, against internal/fakewallapop, 30s interval, real units in ~/.config/systemd/user:

  • install writes both units, daemon-reloads, enable --nows. systemctl --user is-enabled says enabled, is-active says active, and the timer appears in list-timers.
  • it fired on install and then every 30s for the ~4 minutes i watched it, each start and finish in the journal and the latest in last_run.
  • Events from the scheduled runs reached the log, the Event history (watch events) and the Watch's Sinks (an exec sink that appended every event it was handed, 3 deliveries from scheduled runs, on top of the one from sink test).
  • status reported active with last_run matching the journal, doctor reported schedule: active.
  • log cap: padded the log past 1 MiB, the next scheduled run renamed it to .log.1 and the run after that started a fresh .log. two files, bounded.
  • uninstall printed removed, and afterwards: no unit files, no timer in list-timers, nothing in list-unit-files, no log, no .log.1. status and doctor both say not installed. box left clean.

what was not verified, and why

  • reboot. cannot reboot this machine. what stands in for it: the timer is enabled (so timers.target pulls it in) and linger is on (so the user manager starts at boot without a login). those two together are what makes a user timer survive logout and come back after a reboot. i did not reboot, so i am not ticking that box.
  • the loginctl enable-linger branch. this box already had linger on, so install's call had nothing to do. i did not turn linger off to test it, since five unrelated user timers run on this box and i am not gambling with them.
  • macOS launchd. no macOS host. reviewed against the plist contract instead: Label, ProgramArguments, StartInterval in whole seconds, RunAtLoad, StandardOutPath/StandardErrorPath, and an agent in ~/Library/LaunchAgents is loaded at login, which is the macOS answer to "after a reboot". a test parses the generated plist and checks those keys are present and the values intact. it has never been handed to launchd.
  • windows schtasks. the printed line is pinned by a test (/SC MINUTE /MO n, minutes rounded up, never 0, \" around the executable so a C:\Program Files\... path stays one argument). never run on windows.

after review

four more, all from codex, all real, all fixed on this branch:

  • systemd expands % specifiers inside unit values, so a percent-encoded URL or a path with a % in it either got dropped or silently rewritten. every rendered value doubles its % now.
  • HOME was missing from the pinned set, and it is where every default path comes from when the XDG variables are unset. pinned.
  • a relative WALLAPOP_CONFIG was recorded as given, and the scheduler starts from its own directory. made absolute.
  • then the fix for that one over-reached: filepath.Abs on a relative XDG value handed the timer an override adrg/xdg had ignored at install time, which is this PR's own bug from the other side. XDG values are pinned only when already absolute.

a relative HOME makes every derived path relative, so install refuses instead of writing a unit systemd would ignore. the deeper fix, normalising HOME where paths are resolved, is in internal/config and is left alone.

re-verified live on systemd after each round: the unit installs, systemctl --user show -p Environment reads the pinned values back unchanged, the run exits 0, uninstall leaves nothing.

outside my lane

wallapop config set cannot set an array, so an exec sink's command cannot be configured from the CLI at all: config set sinks.x.command /path fails with cannot decode TOML string into []string. i hand-edited config.toml for the live test. that lives in internal/cli/misc.go, which i do not own on this branch, so it is untouched and reported here instead.

Closes #5

…ystemd

A scheduler starts a job with a bare environment, so a timer installed from a
shell that sets XDG_DATA_HOME or WALLAPOP_CONFIG went on to check a different,
empty state database: no events, no error, nothing to see. The unit now carries
the variables that decide where the CLI reads and writes, and which backend it
talks to, as they stood at install time. The session token is deliberately left
out of a world-readable file.

Alongside that, three correctness fixes the live run and a close reading turned
up: ExecStart quotes the executable so a path with a space does not produce a
unit that fails on every trigger; the launchd plist escapes every value, since a
plist that does not parse is an agent that silently never runs; and linger is
read from the passwd database rather than $USER, which a scheduled process may
not have.

Unit rendering moves into three pure functions so the launchd and Windows cases
are testable on Linux: the plist is parsed and its keys checked, the schtasks
line is pinned exactly.

Verified live on systemd 249 at a 30s interval against the fake Wallapop:
install, repeated firing, events reaching the log and the sinks, status and
doctor reporting active, log rotation at the cap by a scheduled run, and an
uninstall that leaves nothing. Reboot, launchd and schtasks are not exercised;
docs/cli-spec.md says exactly what was and was not.
@coderabbitai

coderabbitai Bot commented Sep 16, 2026 •

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Advanced

Run ID: 7512a579-d888-45b6-b956-437be7db4ed3


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@Microck

Microck commented Sep 16, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 16, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-16T11:43:32.324123Z e0464bb Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@Microck

Microck commented Sep 16, 2026

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
⚠️ Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

…rrides

Three findings from review, all real.

systemd expands % specifiers inside unit values, so a percent-encoded URL or a
path with a % in it either made systemd drop the assignment or substituted
something else. Every rendered value now doubles its %.

HOME is what the default paths derive from when the XDG variables are unset,
which is the common case, so a unit that did not carry it could still land on
another home. It is pinned with the rest.

A relative WALLAPOP_CONFIG or XDG override was recorded as given, and a
scheduler runs the job from its own working directory, so it would have pointed
somewhere else. Path overrides are made absolute before they go into the unit.

Re-verified live: systemd accepts the unit, resolves the environment exactly as
written, runs it, and uninstall leaves nothing.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1983deccfe

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread internal/cli/watch.go Resolved
Comment thread internal/cli/watch.go Resolved
Comment thread internal/cli/watch.go Resolved
@Microck

Microck commented Sep 16, 2026

Copy link
Copy Markdown
Owner Author

@codex review

A relative HOME makes every derived path relative, so the unit would carry a
StandardOutput= systemd ignores and the unit files would land outside the
directory systemd reads. Install now says so and stops instead of writing a
schedule that quietly does nothing.

Relative XDG_* overrides do not reach this: adrg/xdg drops them and falls back
to the HOME defaults, checked against the built binary.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4a58438636

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread internal/cli/watch.go Resolved
@Microck

Microck commented Sep 16, 2026

Copy link
Copy Markdown
Owner Author

@codex review

A relative XDG value is invalid per the spec and adrg/xdg drops it, so the
install ran on the HOME defaults. Making it absolute and writing it into the
unit handed the timer an override the install never used, which is the same
empty-database failure from the other direction. XDG values are now pinned only
when they are already absolute.

WALLAPOP_CONFIG keeps the absolute conversion: it is read raw rather than
through xdg, so a relative one does take effect and the scheduler starts from
its own working directory. HOME goes in as it is, since a relative one is
refused before this point.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 340225ae05

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread internal/cli/watch.go Resolved
@Microck

Microck commented Sep 16, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Delightful!

Reviewed commit: e0464bb1f3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Microck
Microck merged commit 1bed938 into main Sep 16, 2026
1 check passed
@Microck
Microck deleted the feat/watch-service-verify branch November 18, 2026 22:46
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.

Live-verify scheduled checks on systemd and launchd

1 participant