Kaku icon indicating copy to clipboard operation
Kaku copied to clipboard

[BUG] Auto-update quits the app but never installs the update or relaunches

Open vdxz opened this issue 1 month ago • 4 comments

Environment: macOS 27

When updating Kaku from 0.25.0 to 0.26.0, clicking “Restart to Update” in the menu bar only quits the app. It does not install the update or relaunch. When I open Kaku manually, it is still on 0.25.0 and shows another update notification. This repeats on every attempt.

I also ran into this with the previous release and updated manually. Now that it has happened again, I’m reporting it.

The downloaded 0.26.0 app passes code signature verification, and both the installed app and /Applications are writable. The update log (staged_update/update.log) shows only start apply update for each attempt, with no entries for backing up the old app, copying the new one, or relaunching.

Manually replacing the app with the downloaded copy worked. Kaku now runs 0.26.0 and has cleared the staged update.

My agent suspects that the update helper may be getting terminated along with Kaku before it can replace the app. spawn_update_helper() uses nohup without creating a separate process group, and its stderr is redirected to /dev/null.

vdxz avatar Oct 21 '26 06:10 vdxz

@vdxz Thanks for digging into this, your agent was right. Kaku.app runs as a launchd job, and when Kaku quit, launchd also killed the update helper, which was still in Kaku's process group, before it could replace the app. The helper now starts in its own process group, so it keeps running after Kaku quits.

The fix is in the latest Nightly: https://github.com/tw93/Kaku/releases/tag/nightly. Restart to Update in 0.26.0 still runs the old helper, so please install Kaku-nightly.dmg by hand this one time. Updates from then on should install and relaunch on their own.

If one still fails, update.log will now include the helper's error output; please attach it here.

tw93 avatar Oct 21 '26 09:10 tw93

@tw93 After several new releases, I can confirm this is still not fixed. Restart to Update still doesn't finish. It stops right after renaming the old app to Kaku.app.backup.*, so I'm left with no new Kaku.app at all. I asked my agent to look into it, and its report is below.


Agent report

Setup: macOS 27.2 (26B123), Apple silicon. Kaku 0.27.0 was installed, and it already includes the .process_group(0) fix. The staged update was V0.27.1 (verified: true).

What I found

staged_update/update.log contains only these two lines:

[2026-10-28 20:24:20] start apply update
[2026-10-28 20:24:21] backup existing app

The helper stopped between mv "$TARGET_APP" "$BACKUP_APP" and the next log call. stderr now goes to the log, yet the log has no error, so the helper did not exit through set -e. A signal (most likely SIGKILL) almost certainly killed it.

This is not a one-off failure. All five 0.27.x helper scripts are still in updates/ (apply-staged-1793005383, …5394, …20762, …20858, …190260). The helper deletes $0 when it finishes, so none of these runs completed. The first four left the app in place. This one got further and removed it.

Unified log, filtered:

20:24:20.263 launchd      user/501/com.apple.xpc.launchd.unmanaged.nohup.526 [526]: added unmanaged active
20:24:20.263 kernel       [nohup:526] EXC_GUARD AST: type=0x1 flavor=0x0 target=0x1d13
20:24:20.378 launchd      gui/501/application.fun.tw93.kaku.… [1238]: exited due to exit(0)
20:24:21.563 launchd      Queried 0 attributed services: caller=loginwindow[615], coalition=1135
20:24:21.565 loginwindow  kLSNotifyApplicationExitedIncludingSubordinateProcesses for LSASN:{0x0-0x24024} (Kaku)
20:24:21.566 backgroundtaskmanagementd  BTMCodeSignInfo initWithURL: result=-67068 (bundle already gone)
20:24:21.577 loginwindow  quitOrKillSubordinateProcesses: Failed to quit or kill application "Kaku", error=-600 procNotFound

My reading

  • The process-group change helped, but only partly. The helper now survives launchd's teardown of the app job. Before the change, the log stopped at start apply update.
  • LaunchServices still treats the helper as a subordinate process of Kaku (same coalition 1135). Kaku's "exited including subordinate processes" notification fires about 1.2 s after kaku-gui exits, right after the mv. In other words, that is when the helper dies. loginwindow's quitOrKillSubordinateProcesses runs at the same moment and is the most likely killer. The bundle disappearing on mv may be what triggers it. This part is inference: no log line names the signal sender.
  • A new process group does not move a process out of the app's coalition. To run independently of Kaku, the helper probably has to be started by launchd, e.g. a one-shot job via launchctl submit/bootstrap, as Sparkle does for its installer.

One more issue: step order

The helper moves the working app away before it copies the new one in. If anything interrupts it between those steps, the user is left with no Kaku and no in-app way to recover. A safer order is to ditto the new app to a sibling path such as Kaku.app.new, then do the two renames back to back, with a trap that restores the backup if a step fails.

vdxz avatar Oct 28 '26 12:10 vdxz

@vdxz Thanks for the detailed report, and sorry this left you without Kaku.app. The updater now copies the new app next to the installed one first and swaps them only at the very end, so if anything stops it midway you still have a working Kaku.app, and it runs as its own launchd job instead of as a child of Kaku. This is in the latest Nightly: https://github.com/tw93/Kaku/releases/download/nightly/Kaku-nightly.dmg

Restart to Update always runs the updater from the version you have installed, so please install this Nightly by hand once. If /Applications only has a Kaku.app.backup.* right now, renaming it back to Kaku.app also works. Updates after that should install and relaunch on their own.

If one still fails, please attach staged_update/update.log, it now records which step it reached.

tw93 avatar Nov 01 '26 11:11 tw93

@tw93 I tried again a few days later. I honestly assumed I'd done something wrong on my end, but auto-update still fails on my Mac (0.28.0 → 0.29.0, macOS 27.2). The good news is that the new swap order kept Kaku.app intact this time.

I asked Opus 5.5 to look again. This time the system log shows who stops the updater:

update.log
[01:54:15] handed off to launchd job fun.tw93.kaku.update.1794160455.12075
[01:54:15] stage new app
[01:54:16] interrupted by signal

loginwindow
01:54:15.779  launchJobCheck: app "Kaku" job fun.tw93.kaku.update.1794160455.12075 agent not managed by BTM so is not allowed.
01:54:15.844  applicationDeath: app "Kaku" was foreground, and still has subordinate processes, and is not allowed by BTM so scheduling its subordinates' termination.
01:54:16.912  _LSForceQuitApplication: Unloading one-shot jobs for application "Kaku", jobs=[<OSLaunchdJob ...>]

So the system still treats the launchd job as Kaku's. When Kaku quits, Background Task Management doesn't allow the job to keep running, and loginwindow unloads it about a second later, in the middle of the copy.

Two directions that might work:

  1. Swap before quitting. Stage the new app and do both renames while Kaku is still running, then just open the new app and quit. Nothing needs to outlive Kaku.
  2. Register the helper with SMAppService, so Background Task Management allows it.

Thanks for sticking with this!

vdxz avatar Nov 08 '26 18:11 vdxz