Scheduled scripts stop being scheduled
Hey, thank you so much for making this project. It's wonderful to have an API to script so easily.
However, I've run into some issues with scheduled scripts. My scheduled scripts stop being scheduled after a while. I notice when I pull up the command palette, they don't show the next scheduled time. The way I fix this is by restarting ScriptKit.
But this is super annoying to deal with, and ideally ScriptKit can figure out that it should reschedule these scripts.
Below is an example scheduled script that stops working after scriptkit has been launched for a few hours.
// Name: Kenv Sync
// Description: Syncs main kenv directory with github on a schedule (every 10 minutes)
// Schedule: 0 */10 * * * *
import "@johnlindquist/kit";
import { invariantAndExit } from "../lib/script-invariant";
await hide();
const mainKenvDir = kenvPath();
const deviceName = await env("DEVICE_NAME");
const commitMessage = `${formatDate(new Date(), "yyyy-MM-dd kk:mm:ss")} ${deviceName}`;
const cliOptions = {
cwd: mainKenvDir,
shell: "/bin/zsh",
all: true,
reject: false,
};
const gitStatusResult = await execa("git status --porcelain", cliOptions);
invariantAndExit(gitStatusResult.exitCode === 0, "Git status failed");
// We need to check if there are any changes to commit and if there are, we need to commit them
if (gitStatusResult.stdout.trim() !== "") {
const commitResult = await execa(
`git add -A && git commit -m '${commitMessage}'`,
cliOptions,
);
invariantAndExit(commitResult.exitCode === 0, "Git commit failed");
}
const pullResult = await execa("git pull --rebase", cliOptions);
invariantAndExit(pullResult.exitCode === 0, "Git pull failed");
const gitUnpushedResult = await execa("git log origin/main..HEAD", cliOptions);
invariantAndExit(gitUnpushedResult.exitCode === 0, "Git unpushed check failed");
// If there are no changes to commit, we can exit the script
if (gitUnpushedResult.stdout.trim() === "") {
exit(0);
}
const pushResult = await execa("git push", cliOptions);
invariantAndExit(pushResult.exitCode === 0, "Git push failed");
notify("Synced kenv");
Thanks for the kind words!
Do you see anything in the ~/.kit/logs/kit.log that would indicate that something failed/etc? I'm not exactly sure what to tell you to look for. I'll investigate from my end too.
Looking through my log file, I don't see anything out of the ordinary, but I'll keep an eye on it when it occurs.
I'll also try doing a clean restart of everything. Hopefully that will fix it permanently.
Hmm, maybe it's because I'm not calling await hide() for longer running scheduled scripts and then script kit kills the script?
[2024-08-18 14:59:01.127] [warn] ☠️ ERROR PROMPT SHOULD SHOW ☠️
[2024-08-18 14:59:01.127] [warn] Error: Timeout after 1 seconds waiting for HIDE_APP response
The app failed to send a HIDE_APP response to the script process within the expected timeframe. Halting script.
Please share this error to our GitHub Discussions with your scenario: https://github.com/johnlindquist/kit/discussions/categories/errors
at Timeout._onTimeout (file:///Users/kpfromer/.kit/target/app.js:1605:25)
at listOnTimeout (node:internal/timers:569:17)
at process.processTimers (node:internal/timers:512:7)
[2024-08-18 15:12:01.124] [warn] Error: Timeout after 1 seconds waiting for HIDE_APP response
The app failed to send a HIDE_APP response to the script process within the expected timeframe. Halting script.
Please share this error to our GitHub Discussions with your scenario: https://github.com/johnlindquist/kit/discussions/categories/errors
[2024-08-18 15:12:01.127] [warn] ☠️ ERROR PROMPT SHOULD SHOW ☠️
[2024-08-18 15:12:01.127] [warn] Error: Timeout after 1 seconds waiting for HIDE_APP response
Note: N00b Kit user here...
Maybe try setting the KIT_HIDE_DELAY env var to something sufficient for the script to complete? This is just based off glancing at the code here: https://github.com/johnlindquist/kit/blob/main/src/api/kit.ts#L862
I could be mistaken, and it's likely that I am, so... grain of salt and all.
Other thought, given behavior reported, is there is some internal timer that maybe has some bad math behind it and creates some kind of skew as the length of the Kit process increases?
I'm experiencing the same issue, and I have a reliable way to reproduce it. The script seems to stop being scheduled after I close my MacBook lid. Here are the steps:
- Start Kit – the script is scheduled correctly.
- Close the MacBook lid.
- Open the lid and log in.
- The script is no longer scheduled.
The logs seem to confirm that. When I start Kit, there is:
[2025-03-03 18:23:46.373] [info] Scheduling: /Users/masov/.kenv/scripts/[...].js for 0 0 * * * *
After I close the lid:
[2025-03-03 18:24:21.983] [info] 😴 System suspending. Removing watchers.
[2025-03-03 18:24:21.984] [info] Unscheduling: /Users/masov/.kenv/scripts/[...].js
But after waking the system, there is no Scheduling part.
@johnlindquist do you think I can help you somehow? I tried to find that part in the code, but sadly, without success
@Masov Sorry for missing your previous comment. Any chance you could check out the latest build?
https://github.com/script-kit/app/releases/tag/v3.20.8
I've added a lot of fixes recently
@johnlindquist, it is indeed working, thank you very much!