@soffits/dsh-cron-jobs 0.13.0 → 0.13.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/session.js +15 -0
- package/src/watchers.js +4 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@soffits/dsh-cron-jobs",
|
|
3
|
-
"version": "0.13.
|
|
3
|
+
"version": "0.13.1",
|
|
4
4
|
"description": "Scheduled jobs for DeepSeek Harness: shell commands and agent prompts on cron, RRULE or one-time schedules, a gate that wakes an agent only when there is something to do, result delivery through any plugin that can send messages, tools to manage jobs from a conversation, and a Cron tasks page in the Web GUI.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./index.js",
|
package/src/session.js
CHANGED
|
@@ -184,6 +184,9 @@ export async function archiveWhenIdle(ctx, sessionId, {
|
|
|
184
184
|
// A failed turn still ends the activity; its error belongs to the session.
|
|
185
185
|
await agent.whenIdle().catch(() => {})
|
|
186
186
|
if (signal?.aborted) return { archive: 'pending' }
|
|
187
|
+
// A turn DSH's own stop cut off is unfinished work: dsh-restart-resume finds it after the
|
|
188
|
+
// restart only in a session that is not archived, and the rerun's own run archives it later.
|
|
189
|
+
if (turnCutByShutdown(agent.session?.log ?? [])) return { archive: 'kept', note: 'its turn was cut off by a DSH stop' }
|
|
187
190
|
const result = await lock(async () => {
|
|
188
191
|
if (!isLatest()) return { archive: 'superseded' }
|
|
189
192
|
const hold = userHold(ctx, sessionId, agent.session)
|
|
@@ -204,6 +207,18 @@ export async function archiveWhenIdle(ctx, sessionId, {
|
|
|
204
207
|
}
|
|
205
208
|
}
|
|
206
209
|
|
|
210
|
+
/** Whether the session's last turn ended because DSH stopped (aborted `disposed`) or died (`interrupted`). */
|
|
211
|
+
export function turnCutByShutdown(log) {
|
|
212
|
+
for (let i = log.length - 1; i >= 0; i -= 1) {
|
|
213
|
+
if (log[i]?.type === 'turn/start') return false
|
|
214
|
+
if (log[i]?.type !== 'turn/end') continue
|
|
215
|
+
const reason = log[i].data?.reason
|
|
216
|
+
const kind = reason?.kind === 'aborted' ? reason.reason?.kind : reason?.kind
|
|
217
|
+
return kind === 'disposed' || kind === 'interrupted'
|
|
218
|
+
}
|
|
219
|
+
return false
|
|
220
|
+
}
|
|
221
|
+
|
|
207
222
|
/** Time between checks while a prompt waits for its turn to end. */
|
|
208
223
|
export const ANSWER_RETRY_MS = 5000
|
|
209
224
|
/** Checks before giving up on a prompt that never reaches a finished turn. */
|
package/src/watchers.js
CHANGED
|
@@ -281,13 +281,13 @@ class Watcher {
|
|
|
281
281
|
this.child = undefined
|
|
282
282
|
if (this.pidFile) rm(this.pidFile, { force: true }).catch(() => {})
|
|
283
283
|
const ranMs = this.startedAt === undefined ? 0 : sup.now() - this.startedAt
|
|
284
|
-
|
|
284
|
+
const stderrTail = this.stderr.trim().slice(-500)
|
|
285
|
+
this.lastExit = { at: new Date(sup.now()).toISOString(), code, signal, ...(error ? { error } : {}), ranMs, ...(stderrTail ? { stderrTail } : {}) }
|
|
285
286
|
this.resolveExit?.()
|
|
286
287
|
if (this.stopped) {
|
|
287
288
|
this.state = 'stopped'
|
|
288
289
|
return
|
|
289
290
|
}
|
|
290
|
-
const stderrTail = this.stderr.trim().slice(-500)
|
|
291
291
|
sup.record({ time: new Date(sup.now()).toISOString(), job: null, event: 'watcher-exit', watcher: def.id, code, signal, ...(error ? { error } : {}), ranMs, ...(stderrTail ? { stderrTail } : {}) })
|
|
292
292
|
if (def.once) {
|
|
293
293
|
this.state = 'done'
|
|
@@ -321,7 +321,8 @@ class Watcher {
|
|
|
321
321
|
const minutes = Math.round((sup.now() - this.downSince) / 60000)
|
|
322
322
|
const exit = this.lastExit
|
|
323
323
|
const how = exit?.error ?? (exit?.signal ? `killed by ${exit.signal}` : `exit ${exit?.code}`)
|
|
324
|
-
|
|
324
|
+
// The last run's, not this.stderr: a restarted run may be going already, with its own empty tail.
|
|
325
|
+
const stderr = (exit?.stderrTail ?? '').slice(-300)
|
|
325
326
|
sup.record({ time: new Date(sup.now()).toISOString(), job: null, event: 'watcher-down', watcher: def.id, downMs: sup.now() - this.downSince })
|
|
326
327
|
sup.notify(`⚠️ Watcher ${def.id} (${def.channel}) has been down for ${minutes} min (${this.restarts} restarts, last: ${how})${stderr ? `: ${stderr}` : ''}. Jobs on this channel only run on their schedule until it is back.`, def).catch(() => {})
|
|
327
328
|
}
|