How a release removed tg and max from my computer, and why nobody heard about it

A night release reinstalled max through pnpm, npm answered 404, and both max and tg vanished from the global folder. In the same week the daily digest failed 3 more times for other reasons and said nothing. What I changed so that such failures show up at once.

On this page
A dark wooden stand with thin brass tools, two slots in the middle empty. On the right a brass desk bell, its clapper lying apart on the table, and a violet thread running to it from the empty slots

If your own scripts and CLIs run on a schedule, after this post a failed job will tell you about itself, and pnpm add -g won't wipe out the CLIs next to it. In 5 days my background jobs failed 4 times, nobody heard about any of it, and one release removed 2 tools from the system at once. In this post:

  • why pnpm add -g can remove a CLI you already have, and how to avoid it
  • how to make any failed systemd job report itself
  • how not to miss posts when the schedule runs on timers and CI

Every day at 18:00 Madrid time a digest timer starts on my laptop. It looks at what WireCat tools reached npm, Claude writes a short text about it, the text goes to Discord, and the Russian text for Telegram and a short one for X landed in my Telegram Saved Messages, so I could check and post them. And the site plans a post every day or every other day since December. All of this runs on systemd timers.

4 failures in 5 days

DateWhat failedWhy
29 Novthe digest went to Discord, the Telegram and X texts were lostspawnSync tg ENOENT: the service's PATH had the nvm folder, and tg lived in the pnpm folder by then
1 Decthe digest didn't rungit pull over ssh, and the ssh agent refused to sign
2 Decthe digest didn't runthe same git pull hung, and systemd killed it after 30 minutes
3 Dec, at nightmax and tg vanishedthe max-cli 0.129.2 release reinstalled max through pnpm and got a 404

The first one is the simplest. tg moved from the nvm folder to ~/.local/share/pnpm, and a service's PATH is written when it is installed, so the service didn't see tg anymore. On 1 Dec I fixed the install, it now always adds the pnpm folder to PATH, and I installed the service again. But the system never said that Discord had the post while the Russian text was gone, it was only in the journal.

Rows 2 and 3 are the same git pull. The digest has its own copy of the repository and updates it before every run. It updated over ssh, and on 1 Dec the ssh agent just refused (agent refused operation). On 2 Dec the pull didn't answer at all and hung until systemd killed it at TimeoutStartSec=30min. Both days there was no digest.

How a release removed tg and max

On 3 Dec at 00:56 UTC max-cli 0.129.2 was published. After publishing, the max-cli release script installs the new version globally, so my computer has the fresh max right away. 3 minutes later it ran pnpm add -g @wirecat/max-cli@0.129.2 and got this:

Packages: +6 -5
 ERR_PNPM_FETCH_404  GET https://registry.npmjs.org/@wirecat/max-cli/-/max-cli-0.129.2.tgz: Not Found - 404

So npm had accepted the version, but the tarball link didn't serve it yet. Fine, the install failed, it happens. But pnpm had already removed the old links before the download broke. The global folder's package.json still listed max and tg at their old versions, while the folders node_modules/@wirecat/max-cli and tg-cli were gone. Why tg went too, when the release never touched it, I didn't dig into.

Then the nightly full sync of max failed with MODULE_NOT_FOUND, and everything that called tg got "not installed". tg was reinstalled by hand only in the evening, some 16 hours later. Again nobody told anyone, there were no failure notices yet.

The fix in max-cli's bin/release is small. Before the global install the script waits up to 5 minutes until npm view returns the tarball link and the tarball itself answers a HEAD request. If it never does, it doesn't try to install, the global max stays as it was, and the script exits with an error and prints the install command to run later. If pnpm add -g still fails, it says plainly that other global CLIs may have been unlinked, and how to bring them back. No other WireCat repository installs anything globally in its release.

If you install something globally right after npm publish, I'd do the same. One failed pnpm install took a neighbouring package with it on my machine, so I'd first check that the tarball really downloads.

Why nobody heard about it

All 4 times systemd wrote the error to the journal, but nobody opened the journal, and from the outside a job with Failed with result 'exit-code' looks just like one that worked.

On top of that, 3 Dec was the day of the site post about WireCat Desktop 0.12. It wasn't merged, so in the morning it wasn't on the site, and nothing reminded anyone either. The scheduled site Deploy failed the same day. The post was merged and went out only in the evening. Before the merge it was clear that we keep missing posts and announcements, and I decided to make posts go out on schedule.

What reports itself now

Updates without ssh and without hanging. The digest's copy now updates over https, and gh auth git-credential takes the token from the system keyring, so it no longer needs the ssh agent. Each fetch gets 2 minutes and GIT_TERMINAL_PROMPT=0, so git never asks anything, with 3 tries in all. If all 3 fail, the digest runs with the last copy and tells me which one. On a test repository with an unreachable remote this took 40 seconds instead of half an hour.

A failed job writes to me. Every digest unit now has OnFailure=wirecat-alert@%n.service. When a job fails, systemd starts another one, which takes the last journal lines and sends them to me 3 ways: a desktop notification, a message to my Telegram Saved Messages and a line in alerts.log. Each way is tried on its own, because Saved Messages are sent by the same tg, and on a day without tg only the notification and the log are left. If something didn't arrive, the log says so, NOT SENT and where. Nothing goes to a public channel.

Texts aren't lost anymore. If Discord already has the post and Saved Messages failed, the Telegram and X texts are saved to ~/.local/state/wirecat-digest/telegram-<date>.md, and the error message names that file.

The very first real notice reached nobody. On 3 Dec at 17:00 Madrid time the posts check wanted to show a list that started with - , and notify-send read it as its own flag. And Telegram didn't get it, because tg wasn't back yet. Only the log line was left, with NOT SENT for both, so the log did exactly what it was added for. The fix is -- before the title and the text, a classic.

The post calendar and a Deploy that runs hours late

Posts now live in one table, CALENDAR.md, each with its date, its site PR and its status. The site shows a post only from its date, so a PR can be merged early, and the post appears by itself once a Deploy runs on that day.

A separate check reads the table. It looks at the site's main branch and at wirecat.dev itself and writes to me, for example when tomorrow's post isn't merged, or is merged but not on the site, or when it's time to post the teasers, and when the scheduled Deploy failed. The check publishes nothing, it only tells.

At first it ran once a day, at 07:30. But the site's scheduled Deploy has a cron of 05:17 UTC, and from 27 Nov to 1 Dec it started at 15:05, 14:12, 14:15, 16:55 and 23:53 UTC. GitHub doesn't promise to start schedules on the minute, under load they are delayed, but this is up to 18 and a half hours late. With one check at 07:30 almost every post would look "merged but not on the site", and the teaser reminder would come a day late. So now there are 4 checks, at 07:30, 10:30, 14:30 and 18:30 Madrid time, and it writes only when its list changed that day. For a post that is merged but not out, it gives the command that starts a Deploy by hand.

On 4 Dec it already worked. At 07:30 the check wrote that the day's post wasn't merged and that the scheduled Deploy had failed, and by 11 in the morning the post was on the site.

What I didn't check

  • The 404 happened once. How long it usually takes from npm publish until the tarball really downloads, I didn't measure. The 5-minute wait in the fix is a margin, not a measurement.
  • The fix in max-cli's bin/release was tested in parts (the 0.129.2 tarball is served, on a version that doesn't exist the script waits), but not yet as a whole, in a real release.
  • Why pnpm removed tg too, I didn't dig into.
  • The file where the digest saves the texts when Saved Messages fails hasn't been needed for real yet, and the 40 seconds for 3 tries were measured on a test repository.
  • Notices work while the computer works. If the laptop is off, the posts check runs at the next start (Persistent=true), not earlier.

The code of the digest, the posts check and the notices is in our private repository, and the release fix is in a public one: max-cli #1043. I wrote earlier about how WireCat's background services survive a reboot: What a background service needs to survive a laptop reboot.

This broke only on my computer, the normal install of tg and max through Desktop or npm has nothing to do with it. If you run your own jobs on systemd timers too and know a simpler way, write in Discord how you do it.