toolroll 0.9.130 → 0.9.131
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/CHANGELOG.md +20 -0
- package/dist/agent-state.js +1 -1
- package/dist/browser/manifest.json +14 -14
- package/dist/browser/{terminal.2a682d0b91a35288271c73b7ee253e524cca0917d17fbaf6733e80b7a767a37c.js → terminal.8978c8cbb268e1006f4b0be371c2401b58078e6d9f1380f4a5c2a12da843909f.js} +1 -1
- package/dist/browser/terminal.8978c8cbb268e1006f4b0be371c2401b58078e6d9f1380f4a5c2a12da843909f.js.br +0 -0
- package/dist/browser/{terminal.2a682d0b91a35288271c73b7ee253e524cca0917d17fbaf6733e80b7a767a37c.js.gz → terminal.8978c8cbb268e1006f4b0be371c2401b58078e6d9f1380f4a5c2a12da843909f.js.gz} +0 -0
- package/dist/browser/{workspace.9bd1db81d3c897045a5d82d4804e374e41e78b1b2cfd05d37b982a4ea0d02626.js → workspace.4f5935dc80574baadf1adafd39a08c567fb1fac1323052ca355546622f9b06d2.js} +1 -1
- package/dist/browser/workspace.4f5935dc80574baadf1adafd39a08c567fb1fac1323052ca355546622f9b06d2.js.br +0 -0
- package/dist/browser/workspace.4f5935dc80574baadf1adafd39a08c567fb1fac1323052ca355546622f9b06d2.js.gz +0 -0
- package/dist/builder-restart.js +13 -4
- package/dist/builder.js +4 -1
- package/dist/central-recovery-stage.js +2 -2
- package/dist/chat-follow.js +4 -0
- package/dist/db-tuning.js +16 -0
- package/dist/discord.js +9 -3
- package/dist/dispatch.js +32 -4
- package/dist/doctor.js +30 -0
- package/dist/evidence.js +49 -3
- package/dist/exec.js +3 -0
- package/dist/git-views.js +7 -1
- package/dist/invoke.js +12 -2
- package/dist/lead-queue-runtime.js +8 -5
- package/dist/lead-status.js +3 -3
- package/dist/loop-recovery.js +40 -0
- package/dist/maintenance.js +29 -1
- package/dist/needs-you.js +2 -0
- package/dist/operate.js +376 -52
- package/dist/planner.js +4 -1
- package/dist/query-index-schema.js +10 -0
- package/dist/read-executor-worker.js +9 -7
- package/dist/read-executor.js +18 -1
- package/dist/read-worker-connection.js +7 -0
- package/dist/release-adapters.js +51 -6
- package/dist/release-cli.js +24 -11
- package/dist/release-next.js +1 -1
- package/dist/release-stops.js +71 -0
- package/dist/release-supersede.js +125 -0
- package/dist/release-supervise.js +90 -0
- package/dist/release.js +252 -40
- package/dist/runner.js +36 -1
- package/dist/scout.js +4 -1
- package/dist/serve.js +92 -6
- package/dist/shutdown-proof.js +29 -0
- package/dist/slack.js +9 -3
- package/dist/sqlite-telemetry.js +26 -14
- package/dist/statement-cache.js +137 -0
- package/dist/store.js +70 -13
- package/dist/task-status.js +1 -1
- package/dist/teams.js +9 -3
- package/dist/teardown-git.js +10 -1
- package/dist/telegram.js +4 -1
- package/dist/up-processes.js +16 -1
- package/dist/up-role-child.js +2 -0
- package/dist/wake-hub.js +15 -6
- package/dist/work-index.js +101 -44
- package/dist/work-reads.js +53 -9
- package/dist/work-snapshots.js +185 -0
- package/dist/worker-statement-cache.js +83 -0
- package/dist/workspace-revision.js +145 -21
- package/package.json +1 -1
- package/dist/browser/terminal.2a682d0b91a35288271c73b7ee253e524cca0917d17fbaf6733e80b7a767a37c.js.br +0 -0
- package/dist/browser/workspace.9bd1db81d3c897045a5d82d4804e374e41e78b1b2cfd05d37b982a4ea0d02626.js.br +0 -0
- package/dist/browser/workspace.9bd1db81d3c897045a5d82d4804e374e41e78b1b2cfd05d37b982a4ea0d02626.js.gz +0 -0
package/dist/teardown-git.js
CHANGED
|
@@ -2,7 +2,7 @@ import { spawnSync } from "node:child_process";
|
|
|
2
2
|
import { accessSync, closeSync, constants as fsConstants, existsSync, fstatSync, lstatSync, mkdirSync, mkdtempSync, openSync, readdirSync, readFileSync, realpathSync, renameSync, rmSync, symlinkSync, writeFileSync, writeSync } from "node:fs";
|
|
3
3
|
import { randomBytes } from "node:crypto";
|
|
4
4
|
import { homedir } from "node:os";
|
|
5
|
-
import { ensureGitViewsRoot, withCheckoutLock } from "./git-views.js";
|
|
5
|
+
import { CheckoutBusy, ensureGitViewsRoot, withCheckoutLock } from "./git-views.js";
|
|
6
6
|
import { gitIncident } from "./git-incident.js";
|
|
7
7
|
import { basename, delimiter, dirname, isAbsolute, join, resolve } from "node:path";
|
|
8
8
|
import { run } from "./exec.js";
|
|
@@ -176,6 +176,8 @@ async function inView(cwd, binding, work, after = true, lockTimeoutMs, doing, gi
|
|
|
176
176
|
}, lockTimeoutMs);
|
|
177
177
|
}
|
|
178
178
|
catch (error) {
|
|
179
|
+
if (error instanceof CheckoutBusy)
|
|
180
|
+
return busyRefusal(error.message);
|
|
179
181
|
return refused(error instanceof Error ? error.message : "the checkout is busy");
|
|
180
182
|
}
|
|
181
183
|
}
|
|
@@ -1195,3 +1197,10 @@ export function checkoutTop(dir, timeoutMs = 10_000) {
|
|
|
1195
1197
|
at = up;
|
|
1196
1198
|
}
|
|
1197
1199
|
}
|
|
1200
|
+
function busyRefusal(why) {
|
|
1201
|
+
const result = { ...refused(why), checkoutBusy: true };
|
|
1202
|
+
return result;
|
|
1203
|
+
}
|
|
1204
|
+
export function checkoutBusy(result) {
|
|
1205
|
+
return result.checkoutBusy === true && refusal(result) !== null;
|
|
1206
|
+
}
|
package/dist/telegram.js
CHANGED
|
@@ -246,7 +246,10 @@ export async function bridgePass(store, options) {
|
|
|
246
246
|
report.pushed = pushed;
|
|
247
247
|
await drainUpdates(store, botId, transport, owner, lease.generation, lease.cursor, clock, report, 0, undefined, options.readProjects, options.conversation);
|
|
248
248
|
if (options.conversation !== undefined && options.readProjects !== undefined) {
|
|
249
|
-
const renew = setInterval(() => {
|
|
249
|
+
const renew = setInterval(() => { try {
|
|
250
|
+
store.acquireBridgeLease(botId, owner, BRIDGE_LEASE_MS, clock());
|
|
251
|
+
}
|
|
252
|
+
catch { } }, 30_000);
|
|
250
253
|
renew.unref?.();
|
|
251
254
|
try {
|
|
252
255
|
await processConversations(store, botId, transport, owner, clock, report, options.readProjects, options.conversation);
|
package/dist/up-processes.js
CHANGED
|
@@ -48,6 +48,18 @@ export function roleMessage(value, role) {
|
|
|
48
48
|
case "fatal": return text(value["detail"]) ? { type: "fatal", detail: value["detail"] } : null;
|
|
49
49
|
case "sign-in-link": return role === "console" && whole(value["id"]) && orNull(value["link"], (one) => nonEmpty(one, 2_048)) ? { type: "sign-in-link", id: value["id"], link: value["link"] } : null;
|
|
50
50
|
case "closed": return orNull(value["problem"], (one) => text(one)) ? { type: "closed", problem: value["problem"] } : null;
|
|
51
|
+
case "alive": {
|
|
52
|
+
if (role !== "worker" || typeof value["stopping"] !== "boolean" || !Array.isArray(value["repos"]) || value["repos"].length > MAX_LIST || !whole(value["liveBuilds"], 0, 1_000_000))
|
|
53
|
+
return null;
|
|
54
|
+
const repos = [];
|
|
55
|
+
for (const one of value["repos"]) {
|
|
56
|
+
if (!isObject(one) || !nonEmpty(one["repo"]) || typeof one["leaseLive"] !== "boolean" || typeof one["stopping"] !== "boolean" ||
|
|
57
|
+
!orNull(one["lastPassAt"], (at) => nonEmpty(at, 64)) || !orNull(one["cleanup"], (stage) => nonEmpty(stage, 256)))
|
|
58
|
+
return null;
|
|
59
|
+
repos.push({ repo: one["repo"], leaseLive: one["leaseLive"], lastPassAt: one["lastPassAt"], stopping: one["stopping"], cleanup: one["cleanup"] });
|
|
60
|
+
}
|
|
61
|
+
return { type: "alive", stopping: value["stopping"], repos, liveBuilds: value["liveBuilds"] };
|
|
62
|
+
}
|
|
51
63
|
default: return null;
|
|
52
64
|
}
|
|
53
65
|
}
|
|
@@ -125,6 +137,7 @@ export class RoleGenerations {
|
|
|
125
137
|
refused(detail) { this.refusal = detail; }
|
|
126
138
|
refusedWith() { return this.refusal; }
|
|
127
139
|
wasReady() { return this.everReady; }
|
|
140
|
+
current() { return this.generationReady; }
|
|
128
141
|
ended() {
|
|
129
142
|
if (!this.everReady)
|
|
130
143
|
return "fail-start";
|
|
@@ -135,6 +148,8 @@ export class RoleGenerations {
|
|
|
135
148
|
return "restart";
|
|
136
149
|
}
|
|
137
150
|
this.notReadyStreak += 1;
|
|
138
|
-
return
|
|
151
|
+
return "restart";
|
|
139
152
|
}
|
|
153
|
+
notReady() { return this.notReadyStreak; }
|
|
154
|
+
struggling() { return this.notReadyStreak >= ROLE_NOT_READY_REPLACEMENTS; }
|
|
140
155
|
}
|
package/dist/up-role-child.js
CHANGED
|
@@ -28,6 +28,8 @@ const port = {
|
|
|
28
28
|
onMessage: handler => { handlers.push(handler); },
|
|
29
29
|
onStop: handler => { stops.push(handler); if (stopRequested)
|
|
30
30
|
handler(false); },
|
|
31
|
+
exit: code => { if (process.connected)
|
|
32
|
+
process.disconnect?.(); process.exit(code); },
|
|
31
33
|
};
|
|
32
34
|
process.on("SIGINT", () => { });
|
|
33
35
|
process.on("SIGTERM", () => stop(false));
|
package/dist/wake-hub.js
CHANGED
|
@@ -19,9 +19,11 @@ export class WakeHub {
|
|
|
19
19
|
setTimer;
|
|
20
20
|
clearTimer;
|
|
21
21
|
readsMade = 0;
|
|
22
|
+
transient;
|
|
22
23
|
constructor(read, options = {}) {
|
|
23
24
|
this.read = read;
|
|
24
25
|
this.intervalMs = options.intervalMs ?? WAKE_HUB_INTERVAL_MS;
|
|
26
|
+
this.transient = options.transient ?? sqliteBusy;
|
|
25
27
|
this.now = options.now ?? Date.now;
|
|
26
28
|
this.setTimer = options.setTimer ?? ((fn, ms) => setTimeout(fn, ms));
|
|
27
29
|
this.clearTimer = options.clearTimer ?? (handle => clearTimeout(handle));
|
|
@@ -88,9 +90,12 @@ export class WakeHub {
|
|
|
88
90
|
seq = this.read();
|
|
89
91
|
}
|
|
90
92
|
catch (error) {
|
|
91
|
-
|
|
92
|
-
entry.
|
|
93
|
-
|
|
93
|
+
if (!this.transient(error)) {
|
|
94
|
+
for (const entry of [...this.waiters])
|
|
95
|
+
entry.fail(error);
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
seq = null;
|
|
94
99
|
}
|
|
95
100
|
const now = this.now();
|
|
96
101
|
for (const entry of [...this.waiters]) {
|
|
@@ -104,7 +109,7 @@ export class WakeHub {
|
|
|
104
109
|
}
|
|
105
110
|
if (stop)
|
|
106
111
|
entry.settle("poke");
|
|
107
|
-
else if (seq !== entry.baseline)
|
|
112
|
+
else if (seq !== null && seq !== entry.baseline)
|
|
108
113
|
entry.settle("wake");
|
|
109
114
|
else if (now >= entry.deadline)
|
|
110
115
|
entry.settle("deadline");
|
|
@@ -112,11 +117,15 @@ export class WakeHub {
|
|
|
112
117
|
this.arm();
|
|
113
118
|
}
|
|
114
119
|
}
|
|
120
|
+
function sqliteBusy(error) {
|
|
121
|
+
const code = error?.errcode;
|
|
122
|
+
return typeof code === "number" && (code & 0xff) === 5;
|
|
123
|
+
}
|
|
115
124
|
const hubs = new WeakMap();
|
|
116
|
-
export function wakeHubFor(store) {
|
|
125
|
+
export function wakeHubFor(store, brief) {
|
|
117
126
|
let hub = hubs.get(store);
|
|
118
127
|
if (hub === undefined) {
|
|
119
|
-
hub = new WakeHub(() => store.wakeSeq());
|
|
128
|
+
hub = new WakeHub(() => brief === undefined ? store.wakeSeq() : brief(() => store.wakeSeq()));
|
|
120
129
|
hubs.set(store, hub);
|
|
121
130
|
}
|
|
122
131
|
return hub;
|
package/dist/work-index.js
CHANGED
|
@@ -20,7 +20,8 @@ import { ASKS, CODE_READING, STORAGE_HOLD_PREFIX, NEED_ASK, NEEDS, askChipOf, fa
|
|
|
20
20
|
import { agentlessCommand, NO_AGENT_TITLE, noAgentWords, retryWhenWords, signInAgainWords } from './dispatch.js';
|
|
21
21
|
import { releaseTaskOf } from './release-approval.js';
|
|
22
22
|
import { LEAD_CLAIM_SQL, LEAD_CLAIMED, LEAD_IDLE_MS } from './lead-voice.js';
|
|
23
|
-
import { workReadsOf } from './work-reads.js';
|
|
23
|
+
import { prefetchedPage, workReadsOf } from './work-reads.js';
|
|
24
|
+
import { forDisplay } from './evidence.js';
|
|
24
25
|
export const WORK_ASK_GROUPS = ['release', 'approve', 'answer', 'wrong', 'review', 'other'];
|
|
25
26
|
export const WORK_INDEX_PAGE_LIMIT = 40;
|
|
26
27
|
export const WORK_INDEX_MAX_LIMIT = 100;
|
|
@@ -29,7 +30,7 @@ const NO_GROUPS = { decide: 0, review: 0, unblock: 0, building: 0, rest: 0 };
|
|
|
29
30
|
const NO_ASKS = { release: 0, approve: 0, answer: 0, wrong: 0, review: 0, other: 0 };
|
|
30
31
|
const FAMILY_PROBLEM = 'Task history is unavailable or incomplete. This task is shown separately.';
|
|
31
32
|
const VIEWS = ['all', 'needs-you', 'ready', 'running', 'queued', 'completed', 'archived'];
|
|
32
|
-
const ARCHIVED = `
|
|
33
|
+
const ARCHIVED = `c.member_archived`;
|
|
33
34
|
const n = (row, key) => Number(row[key] ?? 0);
|
|
34
35
|
const s = (row, key) => row[key] == null ? null : String(row[key]);
|
|
35
36
|
const AGENT_ASK = `(SELECT q.id FROM agent_question q JOIN run qr ON qr.id=q.run WHERE q.task_ref=a.ref_id AND q.closed_at IS NULL
|
|
@@ -41,8 +42,10 @@ const PERSON_CODES = ['finding-held', 'history-problem', 'earlier-active', 'read
|
|
|
41
42
|
'process-needs-attention', 'failed', 'vanished-run', 'stopped', 'held', 'waiting-incident', 'plan-stopped', 'planning-stopped', 'terminal-dependency', 'needs-project',
|
|
42
43
|
'needs-scope', 'invalid-scope', 'needs-agent-profile', 'needs-approval', 'missing-requirement', 'no-worker-registered', 'no-worker-online', 'signed-out', 'storage-blocked'];
|
|
43
44
|
const HELD_FINDINGS = `(SELECT COUNT(*) FROM finding fd WHERE fd.family_root=root.id AND fd.state='with-person')`;
|
|
45
|
+
const SETTLED = `c.state IN ('done','cancelled','failed')`;
|
|
46
|
+
const unlessSettled = (sql) => `CASE WHEN ${SETTLED} THEN NULL ELSE ${sql} END`;
|
|
44
47
|
export const WAITING_CODES = ['cancelled', 'complete', 'running', 'queued',
|
|
45
|
-
...['stopping', 'updating', 'retry-scheduled', 'plan-retry', 'waiting-dependency', 'worker-at-capacity', 'planning-ready', 'scouting-ready'].filter(code => isWaitCode(code))];
|
|
48
|
+
...['stopping', 'updating', 'retry-scheduled', 'plan-retry', 'waiting-dependency', 'worker-at-capacity', 'watch-stalled', 'planning-ready', 'scouting-ready'].filter(code => isWaitCode(code))];
|
|
46
49
|
const WAITING_SQL = WAITING_CODES.map(code => `'${code}'`).join(',');
|
|
47
50
|
const STATE_ACT_LABEL = {
|
|
48
51
|
'ready-to-check': 'Open result', complete: 'Open result', cancelled: 'View task details', failed: 'Review and retry', 'waiting-incident': 'Review and retry', 'plan-stopped': 'Plan again', 'planning-stopped': 'Plan again',
|
|
@@ -116,6 +119,8 @@ const PROJECTION = `WITH RECURSIVE admitted AS MATERIALIZED (
|
|
|
116
119
|
FROM admitted a LEFT JOIN lineage l ON l.ref_id=a.ref_id GROUP BY COALESCE(l.root_ref,a.ref_id)
|
|
117
120
|
), workers AS MATERIALIZED (
|
|
118
121
|
SELECT r.name,r.capacity,r.heartbeat_at,j.value repo,
|
|
122
|
+
-- Self-healing (dispatch.ts watchingProject): its loop for the project runs (a live watch lease), or it never watched it.
|
|
123
|
+
COALESCE((SELECT MAX(wl.expires_at) FROM watch_lease wl WHERE wl.runner=r.name AND wl.repo=j.value)>$now,1) watching,
|
|
119
124
|
(SELECT COUNT(*) FROM claim c WHERE c.runner=r.name AND c.released_at IS NULL AND c.expires_at>$now
|
|
120
125
|
AND c.lease_generation=(SELECT MAX(newest.lease_generation) FROM claim newest WHERE newest.task_ref=c.task_ref)) occupied
|
|
121
126
|
FROM runner r,json_each(CASE WHEN json_valid(r.repos) THEN r.repos ELSE '[]' END) j WHERE r.retired_at IS NULL
|
|
@@ -125,22 +130,23 @@ const PROJECTION = `WITH RECURSIVE admitted AS MATERIALIZED (
|
|
|
125
130
|
earlier.id earlier_id,c.fam_running family_running,COALESCE(c.decision_id,c.fam_question_id) question_id,
|
|
126
131
|
root.id root_id,root.title root_title,fam.fam_refs,fam.fam_ids,
|
|
127
132
|
result.role result_role,result.outcome result_outcome,result.head_revision,result.scope_digest,result.finished_at,
|
|
128
|
-
(SELECT id FROM run WHERE task_ref=c.ref_id AND lease_id=c.live_lease AND outcome IS NULL ORDER BY id DESC LIMIT 1) live_run,
|
|
133
|
+
CASE WHEN c.live_lease IS NULL THEN NULL ELSE (SELECT id FROM run WHERE task_ref=c.ref_id AND lease_id=c.live_lease AND outcome IS NULL ORDER BY id DESC LIMIT 1) END live_run,
|
|
129
134
|
h.owner_kind hold_kind,h.owner_id hold_owner,h.reason hold_reason,h.until hold_until,
|
|
130
135
|
sc.task_id scope_id,sc.digest,sc.approved_at,sc.proposed_at,sc.profile_state,
|
|
131
136
|
-- A prepared candidate: the machine checks out that commit and runs its check; no agent runs (machine-check.ts).
|
|
132
137
|
(typeof(sc.candidate)='text' AND sc.candidate<>'') machine_check,
|
|
133
138
|
-- The pause the dispatch gate itself left this task waiting on (the provider it resolved, pins,
|
|
134
139
|
-- configuration and planners included) first; the approved terms answer before any gate has looked.
|
|
135
|
-
EXISTS(SELECT 1 FROM provider_auth_pause p WHERE p.id=c.auth_wait_pause AND p.lifted_at IS NULL AND ${GATE_PAUSE_ON_TASK}) gate_signed_out,
|
|
136
|
-
COALESCE((SELECT p.provider||':'||p.auth_mode FROM provider_auth_pause p WHERE p.id=c.auth_wait_pause AND p.lifted_at IS NULL AND ${GATE_PAUSE_ON_TASK}),
|
|
140
|
+
${unlessSettled(`EXISTS(SELECT 1 FROM provider_auth_pause p WHERE p.id=c.auth_wait_pause AND p.lifted_at IS NULL AND ${GATE_PAUSE_ON_TASK})`)} gate_signed_out,
|
|
141
|
+
${unlessSettled(`COALESCE((SELECT p.provider||':'||p.auth_mode FROM provider_auth_pause p WHERE p.id=c.auth_wait_pause AND p.lifted_at IS NULL AND ${GATE_PAUSE_ON_TASK}),
|
|
137
142
|
(SELECT p.provider||':'||p.auth_mode FROM provider_auth_pause p WHERE p.lifted_at IS NULL AND p.provider IN (
|
|
138
143
|
SELECT json_extract(sc.approved_profile_json,'$.provider') WHERE json_valid(sc.approved_profile_json)
|
|
139
144
|
UNION ALL SELECT json_extract(leg.value,'$.provider') FROM json_each(CASE WHEN json_valid(sc.approved_route_json) THEN sc.approved_route_json ELSE '{}' END,'$.legs') leg
|
|
140
|
-
WHERE json_extract(leg.value,'$.phase')='build'))) signed_out,
|
|
145
|
+
WHERE json_extract(leg.value,'$.phase')='build')))`)} signed_out,
|
|
141
146
|
(sc.approved_at IS NOT NULL AND sc.approved_by IS NOT NULL AND sc.approved_digest=sc.digest) approved,
|
|
142
|
-
${authorityStandsSql("sc", "c.repo", "$now")} dispatch_approval,
|
|
143
|
-
|
|
147
|
+
${unlessSettled(authorityStandsSql("sc", "c.repo", "$now"))} dispatch_approval,
|
|
148
|
+
-- A done version reads its scope's validity (ready); a cancelled or failed one never does (LAZY).
|
|
149
|
+
CASE WHEN sc.task_id IS NULL THEN 0 WHEN c.state IN ('cancelled','failed') THEN NULL ELSE so_work_scope_valid(json_object(
|
|
144
150
|
'touches',sc.touches,'acceptance_json',sc.acceptance_json,'budget_microusd',sc.budget_microusd,
|
|
145
151
|
'goal',CASE WHEN typeof(sc.goal)='text' THEN '' ELSE sc.goal END,
|
|
146
152
|
'out_of_scope',CASE WHEN typeof(sc.out_of_scope)='text' THEN '' ELSE sc.out_of_scope END,
|
|
@@ -154,18 +160,19 @@ const PROJECTION = `WITH RECURSIVE admitted AS MATERIALIZED (
|
|
|
154
160
|
'proposed_route_json',CASE WHEN typeof(sc.proposed_route_json)='text' THEN '' ELSE sc.proposed_route_json END,
|
|
155
161
|
'approved_route_json',CASE WHEN typeof(sc.approved_route_json)='text' THEN '' ELSE sc.approved_route_json END,
|
|
156
162
|
'unresolved_reason',CASE WHEN typeof(sc.unresolved_reason)='text' THEN '' ELSE sc.unresolved_reason END)) END scope_valid,
|
|
157
|
-
(SELECT CASE WHEN EXISTS(SELECT 1 FROM admitted visible WHERE visible.id=blocker.id) THEN blocker.id END FROM task_edge e JOIN task blocker ON blocker.id=e.blocker WHERE e.blocked=c.id AND blocker.state<>'done'
|
|
158
|
-
ORDER BY (blocker.state IN ('failed','cancelled')) DESC,blocker.id LIMIT 1) dependency_id,
|
|
159
|
-
(SELECT blocker.state FROM task_edge e JOIN task blocker ON blocker.id=e.blocker WHERE e.blocked=c.id AND blocker.state<>'done'
|
|
160
|
-
ORDER BY (blocker.state IN ('failed','cancelled')) DESC,blocker.id LIMIT 1) dependency_state,
|
|
161
|
-
(SELECT COUNT(*) FROM workers w WHERE w.repo=c.repo AND (c.assigned_runner IS NULL OR w.name=c.assigned_runner)) worker_count,
|
|
162
|
-
(SELECT COUNT(*) FROM workers w WHERE w.repo=c.repo AND (c.assigned_runner IS NULL OR w.name=c.assigned_runner) AND w.heartbeat_at>$alive) online_count,
|
|
163
|
-
(SELECT COUNT(*) FROM workers w WHERE w.repo=c.repo AND (c.assigned_runner IS NULL OR w.name=c.assigned_runner) AND w.heartbeat_at>$alive AND w.
|
|
163
|
+
${unlessSettled(`(SELECT CASE WHEN EXISTS(SELECT 1 FROM admitted visible WHERE visible.id=blocker.id) THEN blocker.id END FROM task_edge e JOIN task blocker ON blocker.id=e.blocker WHERE e.blocked=c.id AND blocker.state<>'done'
|
|
164
|
+
ORDER BY (blocker.state IN ('failed','cancelled')) DESC,blocker.id LIMIT 1)`)} dependency_id,
|
|
165
|
+
${unlessSettled(`(SELECT blocker.state FROM task_edge e JOIN task blocker ON blocker.id=e.blocker WHERE e.blocked=c.id AND blocker.state<>'done'
|
|
166
|
+
ORDER BY (blocker.state IN ('failed','cancelled')) DESC,blocker.id LIMIT 1)`)} dependency_state,
|
|
167
|
+
${unlessSettled(`(SELECT COUNT(*) FROM workers w WHERE w.repo=c.repo AND (c.assigned_runner IS NULL OR w.name=c.assigned_runner))`)} worker_count,
|
|
168
|
+
${unlessSettled(`(SELECT COUNT(*) FROM workers w WHERE w.repo=c.repo AND (c.assigned_runner IS NULL OR w.name=c.assigned_runner) AND w.heartbeat_at>$alive)`)} online_count,
|
|
169
|
+
${unlessSettled(`(SELECT COUNT(*) FROM workers w WHERE w.repo=c.repo AND (c.assigned_runner IS NULL OR w.name=c.assigned_runner) AND w.heartbeat_at>$alive AND w.watching)`)} watching_count,
|
|
170
|
+
${unlessSettled(`(SELECT COUNT(*) FROM workers w WHERE w.repo=c.repo AND (c.assigned_runner IS NULL OR w.name=c.assigned_runner) AND w.heartbeat_at>$alive AND w.watching AND w.occupied<w.capacity)`)} available_count,
|
|
164
171
|
-- The first run with no coding agent signed in (dispatch.ts agentlessFirstRun): no planner pinned, no models chosen
|
|
165
172
|
-- anywhere, and on every live builder for it Claude Code and Codex were each seen not installed or not signed in,
|
|
166
173
|
-- with no agent ready or unknown. 2: Claude Code is installed there, 3: only Codex is, 1: neither. Read only while
|
|
167
174
|
-- the task waits for its plan (classified below).
|
|
168
|
-
CASE WHEN (SELECT plan_provider FROM task_ref WHERE id=c.ref_id) IS NULL
|
|
175
|
+
CASE WHEN ${SETTLED} THEN NULL WHEN (SELECT plan_provider FROM task_ref WHERE id=c.ref_id) IS NULL
|
|
169
176
|
AND NOT EXISTS(SELECT 1 FROM phase_config) AND NOT EXISTS(SELECT 1 FROM phase_tier_config) AND NOT EXISTS(SELECT 1 FROM phase_tier_alternate)
|
|
170
177
|
AND EXISTS(SELECT 1 FROM workers w WHERE w.repo=c.repo AND (c.assigned_runner IS NULL OR w.name=c.assigned_runner) AND w.heartbeat_at>$alive)
|
|
171
178
|
AND NOT EXISTS(SELECT 1 FROM workers w WHERE w.repo=c.repo AND (c.assigned_runner IS NULL OR w.name=c.assigned_runner) AND w.heartbeat_at>$alive AND NOT (EXISTS(SELECT 1 FROM provider_readiness pr WHERE pr.runner=w.name AND pr.provider='claude' AND pr.state='unavailable' AND pr.probe IN ('path','login')) AND EXISTS(SELECT 1 FROM provider_readiness pr WHERE pr.runner=w.name AND pr.provider='codex' AND pr.state='unavailable' AND pr.probe IN ('path','identity')) AND NOT EXISTS(SELECT 1 FROM provider_readiness pr WHERE pr.runner=w.name AND pr.state<>'unavailable')))
|
|
@@ -173,13 +180,12 @@ const PROJECTION = `WITH RECURSIVE admitted AS MATERIALIZED (
|
|
|
173
180
|
WHEN EXISTS(SELECT 1 FROM workers w JOIN provider_readiness pr ON pr.runner=w.name WHERE w.repo=c.repo AND (c.assigned_runner IS NULL OR w.name=c.assigned_runner) AND w.heartbeat_at>$alive AND pr.provider='codex' AND pr.probe='identity') THEN 3 ELSE 1 END ELSE 0 END no_agent,
|
|
174
181
|
-- Models chosen here once and cleared (dispatch.ts modelsEverChosen): the no-agent line then promises no start by itself.
|
|
175
182
|
EXISTS(SELECT 1 FROM models_generation) models_cleared,
|
|
176
|
-
CASE WHEN NOT json_valid(c.capability_requirements) THEN 1 ELSE EXISTS(
|
|
183
|
+
CASE WHEN ${SETTLED} THEN NULL WHEN NOT json_valid(c.capability_requirements) THEN 1 ELSE EXISTS(
|
|
177
184
|
SELECT 1 FROM json_each(c.capability_requirements) req WHERE req.type<>'text' OR instr(req.value,':')<2
|
|
178
185
|
OR NOT EXISTS(SELECT 1 FROM capability cap WHERE cap.repo=c.repo AND cap.kind=substr(req.value,1,instr(req.value,':')-1)
|
|
179
186
|
AND cap.name=substr(req.value,instr(req.value,':')+1) AND cap.status='verified' AND (cap.expires_at IS NULL OR cap.expires_at>$now))) END capability_gap,
|
|
180
187
|
(SELECT run FROM run_stop WHERE task_ref=c.ref_id AND resumed_at IS NULL ORDER BY requested_at DESC LIMIT 1) stop_run,
|
|
181
188
|
(SELECT settled_at FROM run_stop WHERE task_ref=c.ref_id AND resumed_at IS NULL ORDER BY requested_at DESC LIMIT 1) stop_settled,
|
|
182
|
-
COALESCE((SELECT substr(actor,13) FROM action_ledger WHERE task_id=root.id AND action='assignment claimed' AND source='work' ORDER BY id DESC LIMIT 1),root.coordinator_cid) owner_id,
|
|
183
189
|
${HELD_FINDINGS} held_findings,
|
|
184
190
|
pub.pr_url publication_url
|
|
185
191
|
FROM ordered c JOIN admitted root ON root.ref_id=c.root_ref JOIN versions fam ON fam.root_ref=c.root_ref
|
|
@@ -257,6 +263,7 @@ const PROJECTION = `WITH RECURSIVE admitted AS MATERIALIZED (
|
|
|
257
263
|
WHEN question_id IS NOT NULL THEN 'waiting-decision'
|
|
258
264
|
WHEN worker_count=0 THEN 'no-worker-registered'
|
|
259
265
|
WHEN online_count=0 THEN 'no-worker-online'
|
|
266
|
+
WHEN watching_count=0 THEN 'watch-stalled'
|
|
260
267
|
WHEN available_count=0 THEN 'worker-at-capacity'
|
|
261
268
|
WHEN signed_out IS NOT NULL AND (gate_signed_out OR NOT (plan='requested' AND NOT COALESCE(approved AND dispatch_approval,0))) THEN 'signed-out'
|
|
262
269
|
WHEN no_agent>0 AND plan='requested' AND NOT COALESCE(approved AND dispatch_approval,0) THEN 'signed-out'
|
|
@@ -280,6 +287,9 @@ const PROJECTION = `WITH RECURSIVE admitted AS MATERIALIZED (
|
|
|
280
287
|
FROM claimed c LEFT JOIN action_ledger completed ON completed.id=c.checked_id WHERE ($state IS NULL OR c.state=$state) AND ($leadId IS NULL OR EXISTS(SELECT 1 FROM team_task_owner own WHERE own.task_ref=c.root_ref AND own.lead=$leadId))
|
|
281
288
|
)`;
|
|
282
289
|
const registered = new WeakMap();
|
|
290
|
+
const SCOPE_VERDICTS_MAX = 8_192;
|
|
291
|
+
const SCOPE_VERDICT_CHARS_MAX = 16 * 1024 * 1024;
|
|
292
|
+
const SCOPE_VERDICT_TEXT_MAX = 256 * 1024;
|
|
283
293
|
const statements = new WeakMap();
|
|
284
294
|
function prepared(store, sql) {
|
|
285
295
|
let cache = statements.get(store.handle);
|
|
@@ -297,13 +307,30 @@ function registerValidators(store) {
|
|
|
297
307
|
return cached;
|
|
298
308
|
if (typeof db.function !== 'function')
|
|
299
309
|
throw new Error('Work summaries require the native SQLite scalar-function API.');
|
|
310
|
+
const verdicts = new Map();
|
|
311
|
+
let held = 0;
|
|
300
312
|
db.function('so_work_scope_valid', { deterministic: true }, value => {
|
|
313
|
+
const text = String(value);
|
|
314
|
+
const known = verdicts.get(text);
|
|
315
|
+
if (known !== undefined)
|
|
316
|
+
return known;
|
|
317
|
+
let verdict;
|
|
301
318
|
try {
|
|
302
|
-
|
|
319
|
+
verdict = scopeTermsProblem(JSON.parse(text)) === null ? 1 : 0;
|
|
303
320
|
}
|
|
304
321
|
catch {
|
|
305
|
-
|
|
322
|
+
verdict = 0;
|
|
306
323
|
}
|
|
324
|
+
if (text.length <= SCOPE_VERDICT_TEXT_MAX) {
|
|
325
|
+
while (verdicts.size > 0 && (verdicts.size >= SCOPE_VERDICTS_MAX || held + text.length > SCOPE_VERDICT_CHARS_MAX)) {
|
|
326
|
+
const oldest = verdicts.keys().next().value;
|
|
327
|
+
held -= oldest.length;
|
|
328
|
+
verdicts.delete(oldest);
|
|
329
|
+
}
|
|
330
|
+
verdicts.set(text, verdict);
|
|
331
|
+
held += text.length;
|
|
332
|
+
}
|
|
333
|
+
return verdict;
|
|
307
334
|
});
|
|
308
335
|
db.function('so_work_operator_access', { deterministic: true }, (raw, repo) => {
|
|
309
336
|
const projects = readProjectAccess(raw);
|
|
@@ -378,7 +405,9 @@ function projectionRows(store, now, access, options, custody, reads, query) {
|
|
|
378
405
|
if (same.$leadOf !== null && !reads.value(`lead-claims\u0000${same.$leadOf}`, () => store.handle.prepare('SELECT 1 FROM action_ledger WHERE actor = ? AND action = ? LIMIT 1').get(same.$leadOf, LEAD_CLAIMED) !== undefined))
|
|
379
406
|
same.$leadOf = null;
|
|
380
407
|
const key = JSON.stringify(Object.entries(same).filter(([name]) => !TIME_INPUTS.has(name)).sort(([a], [b]) => a.localeCompare(b)));
|
|
381
|
-
const table = reads.ranked(key, now, name
|
|
408
|
+
const table = reads.ranked(key, now, (name, made) => {
|
|
409
|
+
prepared(store, made ? `INSERT INTO temp."${name}" ${projection} SELECT * FROM ranked` : `CREATE TEMP TABLE "${name}" AS ${projection} SELECT * FROM ranked`).run(same);
|
|
410
|
+
});
|
|
382
411
|
if (table !== null) {
|
|
383
412
|
try {
|
|
384
413
|
return run(`WITH ranked AS (SELECT * FROM temp."${table}")`, true);
|
|
@@ -415,6 +444,8 @@ const PAGE_TOTAL_NAMES = namesOf(`${TOTALS},${GROUP_TOTALS},${ASK_TOTALS}`);
|
|
|
415
444
|
const PROJECT_TOTALS = `${over(TOTALS, 'PARTITION BY repo', 'project_')},SUM(state='queued' AND family_running=0 AND archived=0) OVER (PARTITION BY repo) project_queued,
|
|
416
445
|
SUM(state='done' AND family_running=0 AND archived=0 AND updated_at>=$recent) OVER (PARTITION BY repo) project_done_recently`;
|
|
417
446
|
const PROJECT_TOTAL_NAMES = [...TOTAL_NAMES.map(name => `project_${name}`), 'project_queued', 'project_done_recently'];
|
|
447
|
+
const PROJECT_SUMS = `${TOTALS.replace(/\),0\) (\w+)/g, '),0) project_$1')},SUM(state='queued' AND family_running=0 AND archived=0) project_queued,
|
|
448
|
+
SUM(state='done' AND family_running=0 AND archived=0 AND updated_at>=$recent) project_done_recently`;
|
|
418
449
|
function askCounts(row) {
|
|
419
450
|
return Object.fromEntries(WORK_ASK_GROUPS.map(group => [group, n(row, `ask_${group}_count`)]));
|
|
420
451
|
}
|
|
@@ -454,29 +485,20 @@ export function workIndexTask(store, taskId, now, access, root) {
|
|
|
454
485
|
return readWorkIndexPage(store, now, access, { limit: 1, ...(root === undefined ? {} : { root }) }, taskId).items[0] ?? null;
|
|
455
486
|
}
|
|
456
487
|
function readWorkIndexPage(store, now, access, options, taskId = null) {
|
|
488
|
+
if (taskId === null) {
|
|
489
|
+
const held = prefetchedPage(store, access, options);
|
|
490
|
+
if (held !== undefined)
|
|
491
|
+
return held;
|
|
492
|
+
}
|
|
457
493
|
const reads = workReadsOf(store);
|
|
458
494
|
const custody = custodyOf(store, reads);
|
|
459
495
|
const view = VIEWS.includes(options.view ?? 'all') ? options.view ?? 'all' : 'all';
|
|
460
496
|
const limit = Number.isFinite(options.limit) ? Math.max(1, Math.min(WORK_INDEX_MAX_LIMIT, Math.floor(options.limit))) : WORK_INDEX_PAGE_LIMIT;
|
|
461
497
|
const scope = cursorScope(access, options, view), cursor = readCursor(options.cursor, scope);
|
|
462
498
|
const filter = view === 'archived' ? 'archived=1' : view === 'needs-you' ? 'needs=1' : view === 'ready' ? READY : view === 'running' ? 'family_running=1 AND archived=0' : view === 'queued' ? QUEUED : view === 'completed' ? "code='complete' AND archived=0 AND ($completedSince IS NULL OR sort_at>=$completedSince)" : 'archived=0';
|
|
463
|
-
const
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
FROM (SELECT s.*,ROW_NUMBER() OVER (PARTITION BY s.in_page ORDER BY ${ORDER},sort_at DESC,root_ref DESC) page_order,
|
|
467
|
-
ROW_NUMBER() OVER (PARTITION BY repo ORDER BY root_ref) repo_order,DENSE_RANK() OVER (ORDER BY repo) repo_rank
|
|
468
|
-
FROM (SELECT ${kept ? 'r.root_ref,r.repo,r.rank,r.ask_rank,r.sort_at' : 'r.*'},($taskId IS NOT NULL OR ${filter}) AND ($taskId IS NULL OR EXISTS(SELECT 1 FROM json_each(r.fam_ids) WHERE value=$taskId)) AND ($roots IS NULL OR root_id IN (SELECT value FROM json_each($roots))) AND ($cursorRoot=0 OR
|
|
469
|
-
${ORDER}>$cursorRank OR (${ORDER}=$cursorRank AND (sort_at<$cursorAt OR (sort_at=$cursorAt AND root_ref<$cursorRoot)))) in_page,
|
|
470
|
-
${PAGE_TOTALS},${PROJECT_TOTALS}
|
|
471
|
-
FROM ranked r) s) p${kept ? ' JOIN ranked r ON r.root_ref=p.root_ref' : ''}
|
|
472
|
-
WHERE (p.in_page AND p.page_order<=$limit) OR p.repo_order=1
|
|
473
|
-
)${kept ? `, led AS MATERIALIZED (
|
|
474
|
-
-- The page's results' own check-level and check-request lines, read in one pass: each row's lookups below then
|
|
475
|
-
-- read this short list instead of scanning its project's ledger (their filters and order are unchanged).
|
|
476
|
-
SELECT id,repo,run_id,action,outcome,detail FROM action_ledger WHERE action IN ('checks used','checks requested')
|
|
477
|
-
AND run_id IN (SELECT page_result_id FROM page WHERE is_row AND page_result_id IS NOT NULL)
|
|
478
|
-
)` : ''}
|
|
479
|
-
SELECT is_row,is_project,repo_rank,repo,${PAGE_TOTAL_NAMES.join(',')},${PROJECT_TOTAL_NAMES.join(',')},CASE WHEN is_row THEN json_object('archived',archived,'archived_by',(SELECT by FROM task_archive WHERE task_ref=page.ref_id),
|
|
499
|
+
const IN_PAGE = `($taskId IS NOT NULL OR ${filter}) AND ($taskId IS NULL OR EXISTS(SELECT 1 FROM json_each(r.fam_ids) WHERE value=$taskId)) AND ($roots IS NULL OR root_id IN (SELECT value FROM json_each($roots))) AND ($cursorRoot=0 OR
|
|
500
|
+
${ORDER}>$cursorRank OR (${ORDER}=$cursorRank AND (sort_at<$cursorAt OR (sort_at=$cursorAt AND root_ref<$cursorRoot))))`;
|
|
501
|
+
const rowJson = (kept) => `json_object('archived',archived,'archived_by',(SELECT by FROM task_archive WHERE task_ref=page.ref_id),
|
|
480
502
|
'archived_kind',(SELECT by_kind FROM task_archive WHERE task_ref=page.ref_id),'archived_reason',(SELECT reason FROM task_archive WHERE task_ref=page.ref_id),
|
|
481
503
|
'archived_at',(SELECT at FROM task_archive WHERE task_ref=page.ref_id),'root_ref',root_ref,'root_id',root_id,'id',id,'root_title',root_title,'repo',repo,
|
|
482
504
|
'state',state,'created_at',created_at,'family_updated',family_updated,'version_count',version_count,'earlier_active',earlier_active,
|
|
@@ -502,8 +524,40 @@ function readWorkIndexPage(store, now, access, options, taskId = null) {
|
|
|
502
524
|
'question_run',(SELECT run FROM decision WHERE id=page.question_id),'agent_ask',page.agent_ask,
|
|
503
525
|
'agent_ask_run',(SELECT run FROM agent_question WHERE id=page.agent_ask),'agent_ask_text',(SELECT substr(question,1,300) FROM agent_question WHERE id=page.agent_ask),'replaced_by',(SELECT successor FROM task_replacement WHERE task_ref=page.ref_id),
|
|
504
526
|
'completed_by_lead',(SELECT lead FROM task_act WHERE task_ref=page.root_ref AND act='completed' ORDER BY id DESC LIMIT 1),'machine_check',COALESCE(machine_check,0),
|
|
505
|
-
'question_task',(SELECT r.external_id FROM decision d JOIN run ON run.id=d.run JOIN task_ref r ON r.id=run.task_ref WHERE d.id=page.question_id))
|
|
506
|
-
|
|
527
|
+
'question_task',(SELECT r.external_id FROM decision d JOIN run ON run.id=d.run JOIN task_ref r ON r.id=run.task_ref WHERE d.id=page.question_id))`;
|
|
528
|
+
const plain = () => `, page AS (
|
|
529
|
+
SELECT p.*,p.in_page AND p.page_order<=$limit is_row,p.repo_order=1 is_project,
|
|
530
|
+
CASE WHEN p.in_page AND p.page_order<=$limit THEN COALESCE(p.result_id,(SELECT id FROM run WHERE task_ref=p.ref_id AND finished_at IS NOT NULL AND role IN ('builder','scout') ORDER BY id DESC LIMIT 1)) END page_result_id
|
|
531
|
+
FROM (SELECT s.*,ROW_NUMBER() OVER (PARTITION BY s.in_page ORDER BY ${ORDER},sort_at DESC,root_ref DESC) page_order,
|
|
532
|
+
ROW_NUMBER() OVER (PARTITION BY repo ORDER BY root_ref) repo_order,DENSE_RANK() OVER (ORDER BY repo) repo_rank
|
|
533
|
+
FROM (SELECT r.*,${IN_PAGE} in_page,
|
|
534
|
+
${PAGE_TOTALS},${PROJECT_TOTALS}
|
|
535
|
+
FROM ranked r) s) p
|
|
536
|
+
WHERE (p.in_page AND p.page_order<=$limit) OR p.repo_order=1
|
|
537
|
+
)
|
|
538
|
+
SELECT is_row,is_project,repo_rank,repo,${PAGE_TOTAL_NAMES.join(',')},${PROJECT_TOTAL_NAMES.join(',')},CASE WHEN is_row THEN ${rowJson(false)} END row_json
|
|
539
|
+
FROM page ORDER BY is_row DESC,page_order`;
|
|
540
|
+
const keptSql = () => `, picked AS MATERIALIZED (
|
|
541
|
+
SELECT r.root_ref,ROW_NUMBER() OVER (ORDER BY ${ORDER},sort_at DESC,root_ref DESC) page_order FROM ranked r
|
|
542
|
+
WHERE ${IN_PAGE}
|
|
543
|
+
), page AS (
|
|
544
|
+
SELECT r.*,p.page_order,1 is_row,COALESCE(r.result_id,(SELECT id FROM run WHERE task_ref=r.ref_id AND finished_at IS NOT NULL AND role IN ('builder','scout') ORDER BY id DESC LIMIT 1)) page_result_id
|
|
545
|
+
FROM picked p JOIN ranked r ON r.root_ref=p.root_ref WHERE p.page_order<=$limit
|
|
546
|
+
), totals AS MATERIALIZED (
|
|
547
|
+
SELECT ${TOTALS},${GROUP_TOTALS},${ASK_TOTALS} FROM ranked
|
|
548
|
+
), projects AS MATERIALIZED (
|
|
549
|
+
SELECT repo,ROW_NUMBER() OVER (ORDER BY repo) repo_rank,${PROJECT_SUMS} FROM ranked GROUP BY repo
|
|
550
|
+
), led AS MATERIALIZED (
|
|
551
|
+
-- The page's results' own check-level and check-request lines, read in one pass: each row's lookups below then
|
|
552
|
+
-- read this short list instead of scanning its project's ledger (their filters and order are unchanged).
|
|
553
|
+
SELECT id,repo,run_id,action,outcome,detail FROM action_ledger WHERE action IN ('checks used','checks requested')
|
|
554
|
+
AND run_id IN (SELECT page_result_id FROM page WHERE is_row AND page_result_id IS NOT NULL)
|
|
555
|
+
)
|
|
556
|
+
SELECT 1 is_row,0 is_project,NULL repo_rank,page.repo,${PAGE_TOTAL_NAMES.join(',')},${PROJECT_TOTAL_NAMES.map(name => `NULL ${name}`).join(',')},${rowJson(true)} row_json,page_order
|
|
557
|
+
FROM page,totals
|
|
558
|
+
UNION ALL SELECT 0,1,repo_rank,projects.repo,${PAGE_TOTAL_NAMES.join(',')},${PROJECT_TOTAL_NAMES.join(',')},NULL,NULL FROM projects,totals
|
|
559
|
+
ORDER BY is_row DESC,page_order`;
|
|
560
|
+
const rows = projectionRows(store, now, access, options, custody, reads, (_, kept) => ({ cached: true, sql: kept ? keptSql() : plain(), params: { $taskId: taskId, $roots: options.roots === undefined ? null : JSON.stringify(options.roots), $cursorRoot: cursor?.root ?? 0, $cursorRank: cursor?.rank ?? 0, $cursorAt: cursor?.at ?? '', $limit: limit + 1, $completedSince: options.completedSince ?? null, $recent: new Date(now.getTime() - 86_400_000).toISOString() } }));
|
|
507
561
|
const selected = rows.filter(row => n(row, 'is_row') === 1).map(row => JSON.parse(String(row['row_json'])));
|
|
508
562
|
const page = selected.slice(0, limit), last = page.at(-1);
|
|
509
563
|
const nextCursor = selected.length > limit && last !== undefined ? Buffer.from(JSON.stringify({ version: 2, scope,
|
|
@@ -519,21 +573,24 @@ function readWorkIndexPage(store, now, access, options, taskId = null) {
|
|
|
519
573
|
const memo = new Map();
|
|
520
574
|
if (reads !== null)
|
|
521
575
|
prefetchResults(reads, store, page);
|
|
522
|
-
const readiness = (row, checks) => resultReadinessFacts(facts, now, options.root, row, checks, memo);
|
|
576
|
+
const readiness = (row, checks) => forDisplay(() => resultReadinessFacts(facts, now, options.root, row, checks, memo));
|
|
523
577
|
return { items: page.map(row => itemOf(row, access.principal, probe, leadName, readiness, options.root !== undefined, now)), projects, totals: rows[0] === undefined ? { ...EMPTY } : counts(rows[0]),
|
|
524
578
|
groups: rows[0] === undefined ? { ...NO_GROUPS } : groupCounts(rows[0]), asks: rows[0] === undefined ? { ...NO_ASKS } : askCounts(rows[0]),
|
|
525
579
|
completedSince: rows[0] === undefined ? 0 : n(rows[0], 'completed_since_count'), builderWaits: rows[0] === undefined ? 0 : n(rows[0], 'builder_wait_count'), nextCursor, limit, view };
|
|
526
580
|
}
|
|
527
581
|
export function workCountsByProject(store, now, access) {
|
|
528
582
|
const reads = workReadsOf(store);
|
|
529
|
-
return projectionRows(store, now, access, {}, custodyOf(store, reads), reads, () => ({ sql: ` SELECT repo,${TOTALS},SUM(state='queued' AND family_running=0 AND archived=0) queued,
|
|
583
|
+
return projectionRows(store, now, access, {}, custodyOf(store, reads), reads, () => ({ cached: true, sql: ` SELECT repo,${TOTALS},SUM(state='queued' AND family_running=0 AND archived=0) queued,
|
|
530
584
|
SUM(state='done' AND family_running=0 AND archived=0 AND updated_at>=$recent) done_recently FROM ranked GROUP BY repo ORDER BY repo`,
|
|
531
585
|
params: { $recent: new Date(now.getTime() - 86_400_000).toISOString() } }))
|
|
532
586
|
.map(row => ({ repo: s(row, 'repo'), totals: counts(row), queued: n(row, 'queued'), doneRecently: n(row, 'done_recently') }));
|
|
533
587
|
}
|
|
534
588
|
export function workStateRows(store, now, access) {
|
|
589
|
+
const held = prefetchedPage(store, access, {}, 'states');
|
|
590
|
+
if (held !== undefined)
|
|
591
|
+
return held;
|
|
535
592
|
const reads = workReadsOf(store);
|
|
536
|
-
return projectionRows(store, now, access, {}, custodyOf(store, reads), reads, () => ({ params: {}, sql: ` SELECT repo,root_id,code,needs,person_need,lead_claim,live_run,unfinished,result_id,rank,
|
|
593
|
+
return projectionRows(store, now, access, {}, custodyOf(store, reads), reads, () => ({ params: {}, cached: true, sql: ` SELECT repo,root_id,code,needs,person_need,lead_claim,live_run,unfinished,result_id,rank,
|
|
537
594
|
code||':'||COALESCE(question_id,'')||':'||COALESCE(agent_ask,'')||':'||COALESCE(hold_id,'')||':'||COALESCE(result_id,'')||':'||COALESCE(stop_run,'')||':'||COALESCE(digest,'')||':'||COALESCE(scope_digest,'') version,
|
|
538
595
|
COALESCE(NULLIF(MAX(COALESCE(proposed_at,''),COALESCE(finished_at,''),
|
|
539
596
|
COALESCE((SELECT created_at FROM decision WHERE id=question_id),''),COALESCE((SELECT asked_at FROM agent_question WHERE id=agent_ask),''),
|
package/dist/work-reads.js
CHANGED
|
@@ -6,6 +6,7 @@ const MAX_SAVED = 50_000;
|
|
|
6
6
|
const FILL_TRIES = 3;
|
|
7
7
|
const scopes = new AsyncLocalStorage();
|
|
8
8
|
const busy = new WeakMap();
|
|
9
|
+
const made = new WeakMap();
|
|
9
10
|
const tableOf = (slot) => `so_work_ranked_${slot}`;
|
|
10
11
|
export function withWorkReads(run) {
|
|
11
12
|
if (scopes.getStore() !== undefined)
|
|
@@ -24,6 +25,33 @@ export function withWorkReads(run) {
|
|
|
24
25
|
close(scope);
|
|
25
26
|
return result;
|
|
26
27
|
}
|
|
28
|
+
export function pageKey(access, options, kind = 'index') {
|
|
29
|
+
const canonical = (record) => Object.keys(record).filter(name => record[name] !== undefined).sort()
|
|
30
|
+
.map(name => { const value = record[name]; return [name, Array.isArray(value) ? [...new Set(value.map(String))].sort() : value]; });
|
|
31
|
+
return JSON.stringify([kind, canonical(access), canonical(options)]);
|
|
32
|
+
}
|
|
33
|
+
export function providePages(store, held) {
|
|
34
|
+
const scope = scopes.getStore();
|
|
35
|
+
if (scope === undefined)
|
|
36
|
+
return;
|
|
37
|
+
scope.pages = { store: savingFor.get(store) ?? store, held, asked: scope.pages?.asked ?? new Map() };
|
|
38
|
+
}
|
|
39
|
+
export function prefetchedPage(store, access, options, kind = 'index') {
|
|
40
|
+
const scope = scopes.getStore();
|
|
41
|
+
if (scope === undefined)
|
|
42
|
+
return undefined;
|
|
43
|
+
const pages = scope.pages ??= { store: savingFor.get(store) ?? store, held: new Map(), asked: new Map() };
|
|
44
|
+
if (pages.store !== (savingFor.get(store) ?? store))
|
|
45
|
+
return undefined;
|
|
46
|
+
const key = pageKey(access, options, kind);
|
|
47
|
+
if (!pages.asked.has(key))
|
|
48
|
+
pages.asked.set(key, { ...(kind === 'index' ? {} : { kind }), access: structuredClone(access), options: structuredClone(options) });
|
|
49
|
+
const held = pages.held.get(key);
|
|
50
|
+
return held === undefined ? undefined : structuredClone(held);
|
|
51
|
+
}
|
|
52
|
+
export function askedPages() {
|
|
53
|
+
return [...(scopes.getStore()?.pages?.asked.values() ?? [])];
|
|
54
|
+
}
|
|
27
55
|
export function outsideWorkReads(run) {
|
|
28
56
|
return scopes.exit(run);
|
|
29
57
|
}
|
|
@@ -40,11 +68,22 @@ function close(scope) {
|
|
|
40
68
|
}
|
|
41
69
|
function release(db, slot) {
|
|
42
70
|
try {
|
|
43
|
-
db
|
|
71
|
+
empty(db, slot);
|
|
44
72
|
busy.get(db)?.delete(slot);
|
|
45
73
|
}
|
|
46
74
|
catch { }
|
|
47
75
|
}
|
|
76
|
+
function empty(db, slot) {
|
|
77
|
+
if (made.get(db)?.has(slot))
|
|
78
|
+
db.exec(`DELETE FROM temp."${tableOf(slot)}"`);
|
|
79
|
+
}
|
|
80
|
+
function discard(db, slot) {
|
|
81
|
+
try {
|
|
82
|
+
db.exec(`DROP TABLE IF EXISTS temp."${tableOf(slot)}"`);
|
|
83
|
+
}
|
|
84
|
+
catch { }
|
|
85
|
+
made.get(db)?.delete(slot);
|
|
86
|
+
}
|
|
48
87
|
const savingFor = new WeakMap();
|
|
49
88
|
export function readerOf(store) {
|
|
50
89
|
if (savingFor.has(store))
|
|
@@ -95,14 +134,17 @@ export function workReadsOf(given) {
|
|
|
95
134
|
if (before === null || before !== current.stamp)
|
|
96
135
|
reset(db, current, before);
|
|
97
136
|
try {
|
|
98
|
-
db
|
|
99
|
-
|
|
137
|
+
empty(db, slot);
|
|
138
|
+
const exists = made.get(db)?.has(slot) === true;
|
|
139
|
+
fill(table, exists);
|
|
140
|
+
if (!exists) {
|
|
141
|
+
const tables = made.get(db) ?? new Set();
|
|
142
|
+
made.set(db, tables);
|
|
143
|
+
tables.add(slot);
|
|
144
|
+
}
|
|
100
145
|
}
|
|
101
146
|
catch {
|
|
102
|
-
|
|
103
|
-
db.exec(`DROP TABLE IF EXISTS temp."${table}"`);
|
|
104
|
-
}
|
|
105
|
-
catch { }
|
|
147
|
+
discard(db, slot);
|
|
106
148
|
return null;
|
|
107
149
|
}
|
|
108
150
|
const after = stampOf(db, current, true);
|
|
@@ -114,9 +156,11 @@ export function workReadsOf(given) {
|
|
|
114
156
|
return table;
|
|
115
157
|
}
|
|
116
158
|
try {
|
|
117
|
-
db
|
|
159
|
+
empty(db, slot);
|
|
160
|
+
}
|
|
161
|
+
catch {
|
|
162
|
+
discard(db, slot);
|
|
118
163
|
}
|
|
119
|
-
catch { }
|
|
120
164
|
prove(db, current);
|
|
121
165
|
}
|
|
122
166
|
return null;
|