pi-better-background-tasks 0.19.0 → 0.20.0
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/README.md +21 -10
- package/package.json +1 -1
- package/runtime-client/artifacts/darwin-arm64.gz +0 -0
- package/runtime-client/artifacts/darwin-arm64.json +1 -1
- package/runtime-client/artifacts/darwin-x64.gz +0 -0
- package/runtime-client/artifacts/darwin-x64.json +1 -1
- package/runtime-client/artifacts/linux-arm64.gz +0 -0
- package/runtime-client/artifacts/linux-arm64.json +1 -1
- package/runtime-client/artifacts/linux-x64.gz +0 -0
- package/runtime-client/artifacts/linux-x64.json +1 -1
- package/runtime-client/src/runtime/root.mjs +5 -2
- package/src/index.ts +19 -0
- package/src/managed-frontend.ts +76 -5
- package/src/navigator-provider.ts +4 -0
- package/src/observed-waits.ts +168 -24
- package/src/process.ts +45 -11
- package/src/review-settings.ts +18 -0
- package/src/runtime.ts +8 -73
- package/src/shared-navigator.ts +47 -26
- package/src/shared-operation-coordinator/src/outbox.ts +9 -0
- package/src/shared-operation-coordinator/src/store.ts +6 -0
- package/src/stall.ts +7 -4
- package/src/supervised-progress.ts +43 -0
- package/src/supervisor/README.md +1 -4
- package/src/supervisor/emit-runner.mjs +1 -0
- package/src/supervisor/generated/process.mjs +49 -11
- package/src/supervisor/generated/runner.mjs +47 -4
- package/src/supervisor/generated/store.mjs +3 -3
- package/src/supervisor/generated/watch-fingerprint.mjs +69 -0
- package/src/supervisor/runner.ts +38 -3
- package/src/supervisor/store.ts +3 -3
- package/src/supervisor/supervisor.ts +6 -3
- package/src/tools.ts +26 -16
- package/src/types.ts +4 -2
- package/src/watch-fingerprint.ts +70 -0
package/README.md
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
`pi-better-background-tasks` is a Pi extension for durable background shell tasks, watchers, logs, and status inspection.
|
|
4
4
|
|
|
5
|
+
For the decisions governing execution, progress, waits, and notifications, see the [Background task policy (ADR 0028)](https://github.com/1aboveio/pi-better-harness/blob/main/docs/adr/0028-background-task-policy.md).
|
|
6
|
+
|
|
5
7
|
## Quick Answer
|
|
6
8
|
|
|
7
9
|
Use `pi-better-background-tasks` when a command should keep running while the foreground Pi session stays free. It is best for dev servers, long scripts, queue watchers, deploy checks, log tails, and other command-driven work.
|
|
@@ -110,10 +112,10 @@ timeouts, and v1 non-goals.
|
|
|
110
112
|
|
|
111
113
|
## Reloads and session switches
|
|
112
114
|
|
|
113
|
-
|
|
114
|
-
session
|
|
115
|
-
|
|
116
|
-
|
|
115
|
+
SSH and legacy tasks belong to the Pi session that started them. After `/reload`,
|
|
116
|
+
that session resumes polling watches and collecting remote tmux output. The
|
|
117
|
+
runtime checks delivery receipts and recovers pending callbacks. For supervised
|
|
118
|
+
local tasks (`bgs_`), see [Observed operations and waits](#observed-operations-and-waits).
|
|
117
119
|
|
|
118
120
|
After `/new`, `/resume`, fork, or switching to another session, the previous
|
|
119
121
|
session's tasks keep running but are paused from Pi's side: watches do not poll,
|
|
@@ -127,9 +129,16 @@ new Pi process, a task whose process is gone is marked lost.
|
|
|
127
129
|
|
|
128
130
|
## Progress And Suspected Stalls
|
|
129
131
|
|
|
132
|
+
Supervised local tasks (`bgs_`) can notify their owning session while a wait
|
|
133
|
+
is pending. The alert includes available output and the state of the other wait
|
|
134
|
+
dependencies. The wait delivers its completion once all dependencies finish.
|
|
135
|
+
The server recovers a pending alert on the owning branch after a reconnect and
|
|
136
|
+
checks the runner for fresh progress before delivery. [Background task policy](../../docs/adr/0028-background-task-policy.md)
|
|
137
|
+
|
|
130
138
|
A task can remain `running` without recent progress evidence. Compact status and
|
|
131
|
-
navigator use the same observation.
|
|
132
|
-
log
|
|
139
|
+
navigator use the same observation. Supervised processes record the time of new output, including bytes beyond the
|
|
140
|
+
log retention limit. SSH and legacy processes use recorded progress and the log's
|
|
141
|
+
modification time. A watch advances only when a poll observes a changed
|
|
133
142
|
outcome: running a poll, appending its result to the watch log, or polling on
|
|
134
143
|
schedule is activity, not progress. Before any progress, the task's launch time
|
|
135
144
|
anchors the silence duration. This does not measure CPU activity, network waits,
|
|
@@ -163,9 +172,11 @@ records an observation, not a process failure. After the existing 60-second
|
|
|
163
172
|
attention grace, callback-enabled tasks wake the parent once per silent spell.
|
|
164
173
|
New progress closes the observation and a later spell can notify again. Quiet
|
|
165
174
|
work does not alert, `callback:false` suppresses notification, and no silence
|
|
166
|
-
threshold stops a task or changes its lifecycle.
|
|
167
|
-
|
|
168
|
-
|
|
175
|
+
threshold stops a task or changes its lifecycle. For supervised tasks the server
|
|
176
|
+
schedules the next silence threshold, including during an in-flight watch poll.
|
|
177
|
+
A supervised watch launched by an older runner lacks the progress checkpoint
|
|
178
|
+
needed to classify silence. Its next launch uses the new runner. Reload restores
|
|
179
|
+
monitoring and persisted delivery receipts. Log-retention writes
|
|
169
180
|
are excluded from task progress.
|
|
170
181
|
|
|
171
182
|
## Launch Policy And Diagnostics
|
|
@@ -335,7 +346,7 @@ leader exits before cleanup can be verified. Descendants may remain running;
|
|
|
335
346
|
inspect that evidence before interpreting the result.
|
|
336
347
|
|
|
337
348
|
Call `wait_for_operations` with `task_ids` and an optional `continuation_note` to
|
|
338
|
-
register an all-settled wait. The parent remains responsive. A notification means
|
|
349
|
+
register an all-settled wait. The parent remains responsive. A wait completion notification means
|
|
339
350
|
every dependency is terminal, including failed, cancelled, timed-out or lost
|
|
340
351
|
operations; it does not mean the command succeeded.
|
|
341
352
|
|
package/package.json
CHANGED
|
Binary file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"build":{"format":1,"sourceDigest":"
|
|
1
|
+
{"build":{"format":1,"sourceDigest":"5bd2e8ad130e4ee494caf40bb7129c5c9c1f787d486de66304ec9a7fa5fcb45e","piSdkVersion":"1.4.0","nodeVersion":"24.14.1","platform":"darwin-arm64","dependencyLockDigest":"300f19071b0e3f4e68220f42d7976b92dc6a629dd2719325fb7fad41781164c8","protocolVersion":1,"serverVersion":"0.7.0","contentId":"be4b4f5c05d403d84c98a0e34f407fbf65fb8f90e4e9d07930404c8f408665eb"},"sha256":"701e694c1047bcb5ef4652c6a05cfbee0798eb90a4a1e57574118c0b3df59d18"}
|
|
Binary file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"build":{"format":1,"sourceDigest":"
|
|
1
|
+
{"build":{"format":1,"sourceDigest":"5bd2e8ad130e4ee494caf40bb7129c5c9c1f787d486de66304ec9a7fa5fcb45e","piSdkVersion":"1.4.0","nodeVersion":"24.14.1","platform":"darwin-x64","dependencyLockDigest":"300f19071b0e3f4e68220f42d7976b92dc6a629dd2719325fb7fad41781164c8","protocolVersion":1,"serverVersion":"0.7.0","contentId":"3db710d017c57fdc43d18531bcd3144de15767b9021223fcc262d39107db55f6"},"sha256":"4f88a4c1bf931f4af0805f227f5d473336f796f74cacad45020bad79e3962232"}
|
|
Binary file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"build":{"format":1,"sourceDigest":"
|
|
1
|
+
{"build":{"format":1,"sourceDigest":"5bd2e8ad130e4ee494caf40bb7129c5c9c1f787d486de66304ec9a7fa5fcb45e","piSdkVersion":"1.4.0","nodeVersion":"24.14.1","platform":"linux-arm64","dependencyLockDigest":"300f19071b0e3f4e68220f42d7976b92dc6a629dd2719325fb7fad41781164c8","protocolVersion":1,"serverVersion":"0.7.0","contentId":"93a5ca8f14a1667ff653465e5844577f34c3f48c79b1ac87daea77f52eba65e3"},"sha256":"24938d0af26379b8b068e09e1e92d3a4c87d88ea04894a676100a4ed19d90649"}
|
|
Binary file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"build":{"format":1,"sourceDigest":"
|
|
1
|
+
{"build":{"format":1,"sourceDigest":"5bd2e8ad130e4ee494caf40bb7129c5c9c1f787d486de66304ec9a7fa5fcb45e","piSdkVersion":"1.4.0","nodeVersion":"24.14.1","platform":"linux-x64","dependencyLockDigest":"300f19071b0e3f4e68220f42d7976b92dc6a629dd2719325fb7fad41781164c8","protocolVersion":1,"serverVersion":"0.7.0","contentId":"71973a617087e76c008eb1eb0b6e50d4ec51f2e6617af432828dba6bdf4baaa1"},"sha256":"b5f918fde231b83e9351dc194ec10bd60f5d8641c452c4925f0bbbffa5eeebd9"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { linkSync, mkdirSync, readFileSync, realpathSync, unlinkSync, writeFileSync } from "node:fs";
|
|
2
2
|
import { join, resolve } from "node:path";
|
|
3
3
|
import { randomUUID } from "node:crypto";
|
|
4
|
+
import { socketPathFor } from "./socket.mjs";
|
|
4
5
|
/** Transport selection is durable and independent of installation or package version. */
|
|
5
6
|
export function runtimeRoot(agentDir, requestedServerDir) {
|
|
6
7
|
mkdirSync(agentDir, { recursive: true, mode: 0o700 });
|
|
@@ -21,9 +22,11 @@ export function runtimeRoot(agentDir, requestedServerDir) {
|
|
|
21
22
|
if (error.code !== "ENOENT")
|
|
22
23
|
throw error;
|
|
23
24
|
}
|
|
24
|
-
const temporary = `${path}.${randomUUID()}`;
|
|
25
25
|
mkdirSync(requestedServerDir, { recursive: true, mode: 0o700 });
|
|
26
|
-
const
|
|
26
|
+
const serverDir = realpathSync(requestedServerDir);
|
|
27
|
+
socketPathFor(serverDir);
|
|
28
|
+
const proposed = { version: 1, agentDir, serverDir };
|
|
29
|
+
const temporary = `${path}.${randomUUID()}`;
|
|
27
30
|
writeFileSync(temporary, JSON.stringify(proposed), { mode: 0o600, flag: "wx" });
|
|
28
31
|
try {
|
|
29
32
|
try {
|
package/src/index.ts
CHANGED
|
@@ -8,6 +8,7 @@ import { observeForegroundSandboxPolicy } from "./sandbox.js";
|
|
|
8
8
|
import { registerTools } from "./tools.js";
|
|
9
9
|
import { deliverBackgroundTasksPrompt } from "./prompt.js";
|
|
10
10
|
import { closeBackgroundObservation } from "./work-observation.js";
|
|
11
|
+
import { readBackgroundReviewInterval, saveBackgroundReviewInterval } from "./review-settings.js";
|
|
11
12
|
|
|
12
13
|
export default function backgroundTasksExtension(pi: ExtensionAPI): void {
|
|
13
14
|
// The frontend owns native UI/delivery only. Mechanical tools run in the
|
|
@@ -15,6 +16,20 @@ export default function backgroundTasksExtension(pi: ExtensionAPI): void {
|
|
|
15
16
|
const {host: observedWaits, proxy, ui} = createManagedBackgroundFrontend(pi);
|
|
16
17
|
const navigator = createBackgroundTasksNavigator(undefined, ui);
|
|
17
18
|
initializeNavigatorPanels(pi);
|
|
19
|
+
const intervalLabel = (minutes: number) => `${minutes} minute${minutes === 1 ? "" : "s"}`;
|
|
20
|
+
const reviewSetting = {
|
|
21
|
+
id: "background-review-interval",
|
|
22
|
+
label: "Background wait review interval",
|
|
23
|
+
values: [1, 5, 10, 15, 30, 60].map(intervalLabel),
|
|
24
|
+
get: () => intervalLabel(readBackgroundReviewInterval()),
|
|
25
|
+
change(value: string) {
|
|
26
|
+
saveBackgroundReviewInterval(Number.parseInt(value, 10));
|
|
27
|
+
void observedWaits.reconcileNow().catch(() => undefined);
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
const registerReviewSetting = () => pi.events.emit("harness-settings:register", reviewSetting);
|
|
31
|
+
let stopReviewSettings: (() => void) | undefined = pi.events.on("harness-settings:request", registerReviewSetting);
|
|
32
|
+
registerReviewSetting();
|
|
18
33
|
// Sections on a host that renders them; text only where it renders none.
|
|
19
34
|
// Returning a prompt on modern pi would set forceSystemPrompt, and the request
|
|
20
35
|
// would then carry a snapshot, so sections published after it never arrive.
|
|
@@ -26,6 +41,8 @@ export default function backgroundTasksExtension(pi: ExtensionAPI): void {
|
|
|
26
41
|
observeForegroundSandboxPolicy(pi);
|
|
27
42
|
// Registered before registerTools(pi), so this runs before running tasks are resumed.
|
|
28
43
|
pi.on("session_start", async (_event, ctx) => {
|
|
44
|
+
stopReviewSettings ??= pi.events.on("harness-settings:request", registerReviewSetting);
|
|
45
|
+
registerReviewSetting();
|
|
29
46
|
registerBackgroundTasksGoalProvider(pi);
|
|
30
47
|
navigator.ensureBackgroundTasksNavigator(ctx);
|
|
31
48
|
});
|
|
@@ -35,6 +52,8 @@ export default function backgroundTasksExtension(pi: ExtensionAPI): void {
|
|
|
35
52
|
navigator.clearBackgroundTasksNavigatorSession();
|
|
36
53
|
});
|
|
37
54
|
pi.on("session_shutdown", async (_event, ctx) => {
|
|
55
|
+
stopReviewSettings?.();
|
|
56
|
+
stopReviewSettings = undefined;
|
|
38
57
|
closeBackgroundObservation(pi);
|
|
39
58
|
// /reload, session replacement, and quit load a fresh instance; stop this one's timers (#324).
|
|
40
59
|
observedWaits.close();
|
package/src/managed-frontend.ts
CHANGED
|
@@ -11,6 +11,7 @@ import { observeNavigatorLaunch } from './shared-navigator.ts';
|
|
|
11
11
|
export function createManagedBackgroundFrontend(pi: ExtensionAPI) {
|
|
12
12
|
let ctx: ExtensionContext | undefined, generation = 0, refresh: Promise<void> | undefined, dirty=false;
|
|
13
13
|
let rows: any[] = [], legacyRows: any[] = [], details = new Map<string, any>(), logs = new Map<string, any>();
|
|
14
|
+
let pendingAttention = new Set<string>();
|
|
14
15
|
const retainedTasks = new Map<string, any>();
|
|
15
16
|
const cachedTask = (id: string) => rows.find(row => row.id === id) ?? retainedTasks.get(id);
|
|
16
17
|
let adoptedScope: string | undefined;
|
|
@@ -20,6 +21,7 @@ export function createManagedBackgroundFrontend(pi: ExtensionAPI) {
|
|
|
20
21
|
const adoptContext = (context: ExtensionContext) => {
|
|
21
22
|
if (adoptedScope !== undefined && adoptedScope !== scopeOf(context)) {
|
|
22
23
|
ownership.clear(); rows = []; legacyRows = []; details.clear(); logs.clear(); retainedTasks.clear(); generation++;
|
|
24
|
+
pendingAttention.clear();
|
|
23
25
|
}
|
|
24
26
|
ctx = context; adoptedScope = scopeOf(context);
|
|
25
27
|
};
|
|
@@ -50,6 +52,30 @@ export function createManagedBackgroundFrontend(pi: ExtensionAPI) {
|
|
|
50
52
|
};
|
|
51
53
|
const notify = () => { for (const listener of listeners)
|
|
52
54
|
listener({ workspace: ctx?.cwd, sessionId: ctx?.sessionManager.getSessionId() }); };
|
|
55
|
+
let handoffRetry: ReturnType<typeof setTimeout> | undefined;
|
|
56
|
+
let attentionRetry: ReturnType<typeof setTimeout> | undefined;
|
|
57
|
+
let retryAt = Infinity;
|
|
58
|
+
const scheduleHandoffPoll = (delayMs: number) => {
|
|
59
|
+
if (!ctx || retryAt <= Date.now() + delayMs) return;
|
|
60
|
+
clearTimeout(handoffRetry);
|
|
61
|
+
retryAt = Date.now() + delayMs;
|
|
62
|
+
// Poll again before attempting delivery: the task or its recipient may have changed.
|
|
63
|
+
handoffRetry = setTimeout(() => {
|
|
64
|
+
handoffRetry = undefined; retryAt = Infinity;
|
|
65
|
+
if (ctx) void reconcile().catch(() => undefined);
|
|
66
|
+
}, delayMs);
|
|
67
|
+
handoffRetry.unref();
|
|
68
|
+
};
|
|
69
|
+
const waitForAttentionIdle = () => {
|
|
70
|
+
if (attentionRetry) return;
|
|
71
|
+
attentionRetry = setTimeout(() => {
|
|
72
|
+
attentionRetry = undefined;
|
|
73
|
+
if (!ctx || !pendingAttention.size) return;
|
|
74
|
+
if (!ctx.isIdle()) { waitForAttentionIdle(); return; }
|
|
75
|
+
void reconcile().catch(() => undefined);
|
|
76
|
+
}, 1000);
|
|
77
|
+
attentionRetry.unref();
|
|
78
|
+
};
|
|
53
79
|
const reconcile = () => {
|
|
54
80
|
if (!ctx)
|
|
55
81
|
return Promise.resolve();
|
|
@@ -57,15 +83,18 @@ export function createManagedBackgroundFrontend(pi: ExtensionAPI) {
|
|
|
57
83
|
dirty=false;
|
|
58
84
|
const captured = ctx, version = generation;
|
|
59
85
|
refresh = (async () => {
|
|
86
|
+
const rechecking = pendingAttention.size && captured.isIdle() ? pendingAttention : undefined;
|
|
60
87
|
trace('poll-start');
|
|
61
88
|
const snapshot = await request('__background_poll', { knownActiveIds: rows.filter(row => row.active).map(row => row.id).slice(0, 200) });
|
|
62
89
|
trace('poll-received', { stale: version !== generation, total: snapshot.deliveries?.length ?? 0, deliveries: (snapshot.deliveries ?? []).slice(0, 8).map((item: any) => ({ taskId: item.notification.taskId, receiptId: item.receiptId })) });
|
|
63
90
|
if (version !== generation)
|
|
64
91
|
return;
|
|
92
|
+
if (Number.isFinite(snapshot.retryAfterMs)) scheduleHandoffPoll(snapshot.retryAfterMs);
|
|
65
93
|
if (snapshot.recoveryPending === true) dirty = true;
|
|
66
94
|
// A rebuilding snapshot is not evidence that visible tasks vanished.
|
|
67
95
|
if (snapshot.status !== 'rebuilding' && snapshot.status !== 'degraded') {
|
|
68
|
-
|
|
96
|
+
// Older servers include compact callback pointers in the task list.
|
|
97
|
+
rows = (snapshot.tasks ?? []).filter((task: any) => !task.callbackPending);
|
|
69
98
|
// Detail remains inspectable while Navigator retains a terminal row.
|
|
70
99
|
for (const task of rows) {
|
|
71
100
|
retainedTasks.delete(task.id); retainedTasks.set(task.id, task);
|
|
@@ -74,9 +103,19 @@ export function createManagedBackgroundFrontend(pi: ExtensionAPI) {
|
|
|
74
103
|
legacyRows = snapshot.legacyRows ?? [];
|
|
75
104
|
}
|
|
76
105
|
notify();
|
|
106
|
+
const deferredAttention = new Set<string>();
|
|
77
107
|
for (const item of snapshot.deliveries ?? []) {
|
|
78
108
|
if (queued.has(item.token))
|
|
79
109
|
continue;
|
|
110
|
+
const n = item.notification;
|
|
111
|
+
const type = n.event?.customType;
|
|
112
|
+
if ((type === 'background-task-stall' || type === 'background-wait-review')
|
|
113
|
+
&& (!rechecking?.has(item.receiptId) || !captured.isIdle())) {
|
|
114
|
+
// Keep the candidate here while busy. Pi's followUp queue cannot
|
|
115
|
+
// revalidate it when the current turn eventually ends.
|
|
116
|
+
deferredAttention.add(item.receiptId);
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
80
119
|
queued.add(item.token);
|
|
81
120
|
const facts = { taskId: item.notification.taskId, receiptId: item.receiptId };
|
|
82
121
|
const receipt = (delivered: boolean, reason?: string) => {
|
|
@@ -93,15 +132,30 @@ export function createManagedBackgroundFrontend(pi: ExtensionAPI) {
|
|
|
93
132
|
receipt(true);
|
|
94
133
|
continue;
|
|
95
134
|
}
|
|
96
|
-
const n = item.notification;
|
|
97
135
|
trace('queue', { ...facts, urgent: n.urgent === true, recipientActive: active(n.origin, n.branchId) });
|
|
98
|
-
if(n.urgent)
|
|
136
|
+
if (n.urgent) {
|
|
137
|
+
const handoff = getCallbackBatcher(pi).deliverUrgent({ ...n.event, receiptId: item.receiptId,
|
|
138
|
+
getSuppressionReason: () => active(n.origin, n.branchId) ? undefined : 'The originating session or branch is no longer active',
|
|
139
|
+
onDelivered: () => receipt(true), onSuppressed: reason => receipt(false, reason) });
|
|
140
|
+
const retry = () => { queued.delete(item.token); if (version === generation) scheduleHandoffPoll(1000); };
|
|
141
|
+
void Promise.resolve(handoff).then(ok => { if (!ok) retry(); }, retry);
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
99
144
|
getCallbackBatcher(pi).enqueue({ ...n.event, source: 'background-task', id: n.taskId, label: n.taskId, status: n.waitId ? `${n.status}; wait ${n.waitId} ready` : n.status,
|
|
100
145
|
detailTool: 'bg_task_status', outcome: n.outcome, callback: true, receiptId: item.receiptId,
|
|
101
146
|
getSuppressionReason: () => active(n.origin, n.branchId) ? undefined : 'The originating session or branch is no longer active',
|
|
102
147
|
onDelivered: () => receipt(true), onSuppressed: (reason) => receipt(false, reason) });
|
|
103
148
|
}
|
|
104
|
-
|
|
149
|
+
pendingAttention = deferredAttention;
|
|
150
|
+
if (pendingAttention.size) {
|
|
151
|
+
if (captured.isIdle()) dirty = true;
|
|
152
|
+
else waitForAttentionIdle();
|
|
153
|
+
}
|
|
154
|
+
})().catch(error => {
|
|
155
|
+
trace('poll-error', { error: String(error).slice(0, 256) });
|
|
156
|
+
if (version === generation && pendingAttention.size) waitForAttentionIdle();
|
|
157
|
+
throw error;
|
|
158
|
+
})
|
|
105
159
|
.finally(() => { refresh = undefined;if(dirty&&ctx)void reconcile().catch(()=>undefined); });
|
|
106
160
|
return refresh;
|
|
107
161
|
};
|
|
@@ -118,7 +172,24 @@ export function createManagedBackgroundFrontend(pi: ExtensionAPI) {
|
|
|
118
172
|
if (restore) activate();
|
|
119
173
|
},
|
|
120
174
|
noteParentContext(context: ExtensionContext) { adoptContext(context); generation++; void reconcile().catch(() => undefined); },
|
|
121
|
-
close() {
|
|
175
|
+
close() {
|
|
176
|
+
clearTimeout(handoffRetry);
|
|
177
|
+
clearTimeout(attentionRetry);
|
|
178
|
+
handoffRetry = attentionRetry = undefined;
|
|
179
|
+
retryAt = Infinity;
|
|
180
|
+
observing = false;
|
|
181
|
+
ctx = undefined;
|
|
182
|
+
adoptedScope = undefined;
|
|
183
|
+
generation++;
|
|
184
|
+
rows = [];
|
|
185
|
+
legacyRows = [];
|
|
186
|
+
details.clear();
|
|
187
|
+
logs.clear();
|
|
188
|
+
retainedTasks.clear();
|
|
189
|
+
queued.clear();
|
|
190
|
+
ownership.clear();
|
|
191
|
+
pendingAttention.clear();
|
|
192
|
+
},
|
|
122
193
|
isParentOriginActive: active,
|
|
123
194
|
onDurableTaskChange(listener: (change: any) => void) { listeners.add(listener); return () => listeners.delete(listener); },
|
|
124
195
|
listDurableTasks(origin: any, _options: any = {}) { return active(origin) ? rows : []; },
|
|
@@ -17,6 +17,7 @@ import { failurePath, failureView } from "./failures.js";
|
|
|
17
17
|
import { readLog } from "./logs.js";
|
|
18
18
|
import { listMetasForOrigin, onMetaChanged, readMeta, writeMeta } from "./registry.js";
|
|
19
19
|
import { getObservedWaitHost } from "./observed-wait-client.js";
|
|
20
|
+
import { describeSupervisedProgress } from "./supervised-progress.js";
|
|
20
21
|
import type { DurableTaskProjection } from "./observed-waits.js";
|
|
21
22
|
import type { BackgroundTaskRuntime } from "./runtime.js";
|
|
22
23
|
import { formatBackgroundTaskStall, observeBackgroundTaskStall } from "./stall.js";
|
|
@@ -191,6 +192,8 @@ function rowFromDurable(task: DurableTaskProjection, now: number): BackgroundWor
|
|
|
191
192
|
const command = durableCommandLabel(task);
|
|
192
193
|
const elapsed = formatDuration((task.endedAt ?? now) - task.startedAt);
|
|
193
194
|
const facts: string[] = [];
|
|
195
|
+
const progress = task.progress && describeSupervisedProgress(task.progress, now);
|
|
196
|
+
if (progress) facts.push(progress);
|
|
194
197
|
if (task.attention && task.reason) facts.push(task.reason);
|
|
195
198
|
else if (task.attention) facts.push(task.status);
|
|
196
199
|
if (task.kind === "watch" && task.intervalSeconds) facts.push(`every ${formatDuration(task.intervalSeconds * 1000)}`);
|
|
@@ -228,6 +231,7 @@ function detailFromDurable(task: DurableTaskProjection, options?: { logTailLines
|
|
|
228
231
|
{ label: "kind", value: task.kind },
|
|
229
232
|
...(task.parentAgentId ? [{label: "agent", value: task.parentAgentId}] : []),
|
|
230
233
|
{ label: "operation", value: task.operationId },
|
|
234
|
+
...(task.progress ? [{ label: "last progress", value: new Date(task.progress.observedAt).toISOString() }] : []),
|
|
231
235
|
{ label: "status", value: `${task.status}${task.terminalOutcome ? ` (${task.terminalOutcome})` : ""}` },
|
|
232
236
|
{ label: "started", value: new Date(task.startedAt).toISOString() },
|
|
233
237
|
...(task.endedAt !== undefined ? [{ label: "ended", value: new Date(task.endedAt).toISOString() }] : []),
|