@goodandready/dsh-cron 0.3.40 → 0.3.42
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/lib/runtimes/runner.js +66 -26
- package/package.json +1 -1
- package/lib/api-actions.js +0 -1
- package/lib/api-item.js +0 -1
- package/lib/artifacts.js +0 -1
- package/lib/routes/index.js +0 -11
- package/lib/runtimes/index.js +0 -4
- package/lib/scheduler/index.js +0 -6
- package/lib/scheduler-assists.js +0 -1
- package/lib/scheduler-completion.js +0 -1
- package/lib/scheduler-lifecycle.js +0 -1
- package/lib/scheduler-preflight.js +0 -1
- package/lib/store/index.js +0 -6
package/lib/runtimes/runner.js
CHANGED
|
@@ -460,8 +460,8 @@ export class SessionRunner {
|
|
|
460
460
|
|
|
461
461
|
const targetSessionId = resolveTargetSessionId(task.targetSessionId, task.targetSessionReset);
|
|
462
462
|
|
|
463
|
-
const mintSessionId = () => {
|
|
464
|
-
if (targetSessionId) {
|
|
463
|
+
const mintSessionId = ({ fresh = false } = {}) => {
|
|
464
|
+
if (targetSessionId && !fresh) {
|
|
465
465
|
if (sessionModule && typeof sessionModule.SessionId === 'function') {
|
|
466
466
|
return sessionModule.SessionId(targetSessionId);
|
|
467
467
|
}
|
|
@@ -572,35 +572,52 @@ export class SessionRunner {
|
|
|
572
572
|
}
|
|
573
573
|
} : {};
|
|
574
574
|
|
|
575
|
-
// If targetSessionId is set, attempt to resume the existing session (#143, #346, GH #9)
|
|
575
|
+
// If targetSessionId is set, attempt to borrow or resume the existing session (#143, #346, GH #9, GH #23)
|
|
576
576
|
let resumeFailure = null;
|
|
577
577
|
const agents = this._getAgentsService();
|
|
578
|
-
if (prep.targetSessionId && agents
|
|
578
|
+
if (prep.targetSessionId && agents) {
|
|
579
|
+
let liveAgent = null;
|
|
579
580
|
try {
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
});
|
|
581
|
+
if (typeof agents.get === 'function') {
|
|
582
|
+
liveAgent = agents.get(prep.targetSessionId);
|
|
583
|
+
}
|
|
584
|
+
} catch (_getErr) {
|
|
585
|
+
liveAgent = null;
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
if (liveAgent) {
|
|
589
|
+
handle = { agent: liveAgent, __borrowedLive: true };
|
|
590
590
|
isResumed = true;
|
|
591
|
-
logger.info(`[dsh-cron]
|
|
592
|
-
}
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
591
|
+
logger.info(`[dsh-cron] borrowed active live session: ${prep.targetSessionId}`);
|
|
592
|
+
} else if (typeof agents.resume === 'function') {
|
|
593
|
+
try {
|
|
594
|
+
handle = await agents.resume({
|
|
595
|
+
sessionId: prep.targetSessionId,
|
|
596
|
+
resumeSessionId: prep.targetSessionId,
|
|
597
|
+
meta: {
|
|
598
|
+
cwd: prep.cwd,
|
|
599
|
+
...(preset ? { agentPreset: preset.id } : {})
|
|
600
|
+
},
|
|
601
|
+
agentOptions: prep.provider && prep.model ? { provider: prep.provider, model: prep.model } : undefined,
|
|
602
|
+
...presetSetup,
|
|
603
|
+
});
|
|
604
|
+
isResumed = true;
|
|
605
|
+
logger.info(`[dsh-cron] resumed existing persistent session: ${prep.targetSessionId}`);
|
|
606
|
+
} catch (resumeErr) {
|
|
607
|
+
resumeFailure = resumeErr;
|
|
608
|
+
logger.warn(`[dsh-cron] could not resume session ${prep.targetSessionId} (${resumeErr.message}), fallback creating new session`);
|
|
609
|
+
handle = null;
|
|
610
|
+
}
|
|
596
611
|
}
|
|
597
612
|
}
|
|
598
613
|
|
|
599
614
|
// Create new session if not resumed
|
|
600
615
|
if (!handle) {
|
|
616
|
+
const isLockedOrColliding = resumeFailure && /already (?:active|owned|exists)|write handle|locked|collision/i.test(resumeFailure.message || '');
|
|
617
|
+
const targetId = prep.mintSessionId({ fresh: isLockedOrColliding });
|
|
601
618
|
try {
|
|
602
619
|
handle = await agents.create({
|
|
603
|
-
sessionId:
|
|
620
|
+
sessionId: targetId,
|
|
604
621
|
meta: {
|
|
605
622
|
cwd: prep.cwd,
|
|
606
623
|
ephemeral: !prep.targetSessionId,
|
|
@@ -611,10 +628,32 @@ export class SessionRunner {
|
|
|
611
628
|
...presetSetup,
|
|
612
629
|
});
|
|
613
630
|
} catch (createErr) {
|
|
614
|
-
if (
|
|
615
|
-
|
|
631
|
+
if (prep.targetSessionId && targetId === prep.targetSessionId) {
|
|
632
|
+
logger.warn(`[dsh-cron] failed to create session with targetSessionId ${prep.targetSessionId} (${createErr.message}), retrying with fresh session ID`);
|
|
633
|
+
try {
|
|
634
|
+
handle = await agents.create({
|
|
635
|
+
sessionId: prep.mintSessionId({ fresh: true }),
|
|
636
|
+
meta: {
|
|
637
|
+
cwd: prep.cwd,
|
|
638
|
+
ephemeral: !prep.targetSessionId,
|
|
639
|
+
internal: !prep.targetSessionId,
|
|
640
|
+
...(preset ? { agentPreset: preset.id } : {})
|
|
641
|
+
},
|
|
642
|
+
agentOptions: prep.provider && prep.model ? { provider: prep.provider, model: prep.model } : undefined,
|
|
643
|
+
...presetSetup,
|
|
644
|
+
});
|
|
645
|
+
} catch (retryErr) {
|
|
646
|
+
if (resumeFailure) {
|
|
647
|
+
throw new Error(`could not resume session "${prep.targetSessionId}" (${resumeFailure.message}): ${retryErr.message}`);
|
|
648
|
+
}
|
|
649
|
+
throw retryErr;
|
|
650
|
+
}
|
|
651
|
+
} else {
|
|
652
|
+
if (resumeFailure) {
|
|
653
|
+
throw new Error(`could not resume session "${prep.targetSessionId}" (${resumeFailure.message}): ${createErr.message}`);
|
|
654
|
+
}
|
|
655
|
+
throw createErr;
|
|
616
656
|
}
|
|
617
|
-
throw createErr;
|
|
618
657
|
}
|
|
619
658
|
}
|
|
620
659
|
|
|
@@ -771,9 +810,6 @@ export class SessionRunner {
|
|
|
771
810
|
if (handle?.agent) {
|
|
772
811
|
bestEffort('approval-set-policy-agent', () => approval.setPolicy(handle.agent, 'never'), logger);
|
|
773
812
|
}
|
|
774
|
-
if (handle?.agent?.session) {
|
|
775
|
-
bestEffort('approval-set-policy-session', () => approval.setPolicy(handle.agent.session, 'never'), logger);
|
|
776
|
-
}
|
|
777
813
|
}
|
|
778
814
|
} catch (appErr) {
|
|
779
815
|
logger.warn('[dsh-cron] approval setPolicy not applied:', appErr.message);
|
|
@@ -912,6 +948,10 @@ export class SessionRunner {
|
|
|
912
948
|
|
|
913
949
|
/** Dispose the session, archive it best-effort, drop the worktree (#30, #29). */
|
|
914
950
|
async _disposeAgentRun(task, prep, handle) {
|
|
951
|
+
if (handle?.__borrowedLive) {
|
|
952
|
+
logger.info(`[dsh-cron] skipping disposal of borrowed live session: ${prep.targetSessionId}`);
|
|
953
|
+
return;
|
|
954
|
+
}
|
|
915
955
|
let archivedSessionId = null;
|
|
916
956
|
archivedSessionId = bestEffort('get-archived-session-id', () => {
|
|
917
957
|
return (handle && handle.agent && handle.agent.session && handle.agent.session.id) || null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@goodandready/dsh-cron",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.42",
|
|
4
4
|
"description": "Background automation runner for DSH: isolated agent runs, script/HTTP/SSH/Docker runtimes, cost guard, notifications, heartbeats.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
package/lib/api-actions.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './routes/api-actions.js';
|
package/lib/api-item.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './routes/api-item.js';
|
package/lib/artifacts.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './store/artifacts.js';
|
package/lib/routes/index.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export * from './api-collection.js';
|
|
2
|
-
export * from './api-item.js';
|
|
3
|
-
export * from './api-actions.js';
|
|
4
|
-
export * from './api-import-export.js';
|
|
5
|
-
export * from './api-task-webhook.js';
|
|
6
|
-
export * from './api-webhook.js';
|
|
7
|
-
export * from './api-helpers.js';
|
|
8
|
-
export * from './metrics.js';
|
|
9
|
-
export * from './external-api.js';
|
|
10
|
-
export * from './routes.js';
|
|
11
|
-
export * from './api.js';
|
package/lib/runtimes/index.js
DELETED
package/lib/scheduler/index.js
DELETED
package/lib/scheduler-assists.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './scheduler/scheduler-assists.js';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './scheduler/scheduler-completion.js';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './scheduler/scheduler-lifecycle.js';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './scheduler/scheduler-preflight.js';
|