From ea66156b6d8a90494d74f5a41f8c0abe34543ed4 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 20 Feb 2026 22:25:56 +0000 Subject: [PATCH 1/2] Initial plan From ec620d800edbf652ffd1fe6085b7000e04b805fa Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 20 Feb 2026 22:53:01 +0000 Subject: [PATCH 2/2] Fix operator precedence bug in restart delay and status KV write initialization Co-authored-by: Hexagon <419737+Hexagon@users.noreply.github.com> --- lib/core/pup.ts | 2 +- lib/core/status.ts | 12 ++++-------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/lib/core/pup.ts b/lib/core/pup.ts index 49c1fb5..182814a 100644 --- a/lib/core/pup.ts +++ b/lib/core/pup.ts @@ -279,7 +279,7 @@ class Pup { const msSinceExited = status.exited ? (new Date().getTime() - status.exited?.getTime()) : Infinity // Default restart delay to 10000ms, except when watching - const baseRestartDelay = config.restartDelayMs ?? config.watch ? 500 : 10000 + const baseRestartDelay = config.restartDelayMs ?? (config.watch ? 500 : 10000) // Calculate exponential backoff if restartBackoffMs is configured let restartDelay = baseRestartDelay diff --git a/lib/core/status.ts b/lib/core/status.ts index 9920bc0..fa5af09 100644 --- a/lib/core/status.ts +++ b/lib/core/status.ts @@ -23,7 +23,7 @@ const started = new Date() */ class Status { private storeName?: string - private lastWrite = Date.now() + private lastWrite = 0 /** * Constructs a new `Status` instance. @@ -36,8 +36,9 @@ class Status { /** * Writes the application status to the KV store with a timestamp as part of the key. * - * Key ["last_application_state"] is written every iteration. - * Key ["application_state", ] is written at most once per 20 seconds. + * Both keys are written at most once per APPLICATION_STATE_WRITE_LIMIT_MS milliseconds. + * Key ["last_application_state"] stores the most recent state (deleted on clean shutdown). + * Key ["application_state", ] stores the historical state log. * @param applicationState The application state to be stored. */ public async writeToStore(applicationState: ApiApplicationState) { @@ -48,11 +49,6 @@ class Status { const kv = new KV({ autoSync: false, disableIndex: true }) await kv.open(this.storeName) - // Initialize lastWrite if it's not set - if (!this.lastWrite) { - this.lastWrite = 0 - } - this.lastWrite = Date.now() await kv.set(["application_state", Date.now()], applicationState)