@tnunamak/dalan 0.9.4 → 0.9.5
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 +6 -0
- package/CONTRIBUTING.md +2 -0
- package/docs/test-suite-isolation.md +14 -7
- package/integrations/t3/acp-kit/src/capability.mjs +1 -25
- package/package.json +2 -1
- package/src/acp-bridge.mjs +1 -1
- package/src/mcp-tasks.mjs +1 -1
- package/src/owner-capability.mjs +25 -0
- package/src/server.mjs +11 -1
- package/src/store.mjs +27 -13
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,12 @@ This file lists user-visible changes, newest first. Check the section for your t
|
|
|
4
4
|
|
|
5
5
|
## Unreleased
|
|
6
6
|
|
|
7
|
+
## 0.9.5
|
|
8
|
+
|
|
9
|
+
- Small source edits run the checks that depend on the edited files. Unclear dependencies keep more checks in the run. Release qualification still runs the full suite.
|
|
10
|
+
- Queued reviews end with `pr_head_mismatch` when the pinned pull request head moves. This lets the requester prepare a new review without repeatedly waking a worker for the old request.
|
|
11
|
+
- MCP Tasks can sign and reopen requester task handles without loading the T3 integration.
|
|
12
|
+
|
|
7
13
|
## 0.9.4
|
|
8
14
|
|
|
9
15
|
- Delegate in the background from Claude Code through MCP Tasks or from Codex through a custom agent. Supported host versions can bring the result back when the calling conversation is idle.
|
package/CONTRIBUTING.md
CHANGED
|
@@ -15,6 +15,8 @@ DALAN_HOST_CHECKS=0 npm test
|
|
|
15
15
|
|
|
16
16
|
`DALAN_HOST_CHECKS=0` turns host checks off by default; tests that exercise host checks may still turn them on.
|
|
17
17
|
|
|
18
|
+
Install `strace` on Linux for affected testing. Use `npm test -- --full` to run every segment serially. See [pull request feedback](docs/test-suite-isolation.md#pull-request-feedback) for how the runner chooses and checks affected segments.
|
|
19
|
+
|
|
18
20
|
For concurrent runs, use a separate Git worktree and a separate short `TMPDIR` for each run (for example `/tmp/s-a-$$` and `/tmp/s-b-$$`). The temporary directory must exist before the run starts. Unix socket paths must fit within 107 bytes. Each test owns its temporary homes, databases, listeners, and host-check systemd units; installed dependencies and the toolchain may be shared read-only. Host-check resource ceilings apply per check, so concurrent runs add their resource use together.
|
|
19
21
|
|
|
20
22
|
When running the installed Gozar journey on its own, point `TMPDIR` at a short, existing, writable directory on disk, especially if the isolated `HOME` is deeply nested. The journey creates and removes its own fixture directory under that temporary root.
|
|
@@ -4,13 +4,20 @@ The ordered commands in `scripts/test-segments.json` are the audit boundary. The
|
|
|
4
4
|
|
|
5
5
|
## Pull request feedback
|
|
6
6
|
|
|
7
|
-
`npm test`
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
7
|
+
`npm test` reads committed, staged, unstaged and untracked changes. It follows
|
|
8
|
+
first-party imports and script paths from each manifest command to select
|
|
9
|
+
affected segments. An edit limited to the reviewed standalone tests in
|
|
10
|
+
`scripts/test-affected.json` can use their verified direct commands.
|
|
11
|
+
Commands and receipts keep their original manifest ordinals.
|
|
12
|
+
Segments with unresolved dynamic imports run on source edits. Global inputs,
|
|
13
|
+
unknown files or commands, and missing Git evidence select the full manifest.
|
|
14
|
+
Hosted PR checks compare the tested merge commit to its recorded base.
|
|
15
|
+
|
|
16
|
+
On Linux, `strace` checks the files opened by a selected segment and its
|
|
17
|
+
descendants. A first-party source read missing from the dependency graph fails
|
|
18
|
+
the segment. Use a literal module specifier or script path to make the dependency
|
|
19
|
+
visible. Without a working tracer, local feedback uses the full manifest.
|
|
20
|
+
Manually dispatched GitHub test runs also audit the full manifest.
|
|
14
21
|
|
|
15
22
|
Use `npm test -- --full` for an explicit serial run. A detached checkout
|
|
16
23
|
without a PR base also runs the full manifest. Profile recording runs the
|
|
@@ -1,25 +1 @@
|
|
|
1
|
-
|
|
2
|
-
// derived, not stored, so it is the same after an adapter restart.
|
|
3
|
-
import { createHmac, randomBytes } from 'node:crypto';
|
|
4
|
-
import fs from 'node:fs';
|
|
5
|
-
import path from 'node:path';
|
|
6
|
-
|
|
7
|
-
// Read the secret, create it on first use. A file that is not exactly 0600 or is too short is an error, never replaced.
|
|
8
|
-
export function readOrCreateSecret(file) {
|
|
9
|
-
fs.mkdirSync(path.dirname(file), { recursive: true, mode: 0o700 });
|
|
10
|
-
const read = () => {
|
|
11
|
-
const mode = fs.statSync(file).mode & 0o777;
|
|
12
|
-
if (mode !== 0o600) throw Object.assign(new Error(`${file} must be mode 0600 (found ${mode.toString(8)})`), { code: 'state_permissions' });
|
|
13
|
-
const secret = fs.readFileSync(file, 'utf8').trim();
|
|
14
|
-
if (secret.length < 32) throw new Error(`${file} is too short`);
|
|
15
|
-
return secret;
|
|
16
|
-
};
|
|
17
|
-
try { return read(); } catch (error) { if (error.code !== 'ENOENT') throw error; }
|
|
18
|
-
// link() fails with EEXIST when another creator won: the file appears complete or not at all, and the first one is kept.
|
|
19
|
-
const tmp = `${file}.${process.pid}.tmp`;
|
|
20
|
-
fs.writeFileSync(tmp, randomBytes(32).toString('hex') + '\n', { mode: 0o600 });
|
|
21
|
-
try { fs.linkSync(tmp, file); } catch (error) { if (error.code !== 'EEXIST') throw error; } finally { fs.rmSync(tmp, { force: true }); }
|
|
22
|
-
return read();
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export const ownerToken = (secret, id) => createHmac('sha256', secret).update(id).digest('hex');
|
|
1
|
+
export { ownerToken, readOrCreateSecret } from '../../../../src/owner-capability.mjs';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tnunamak/dalan",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.5",
|
|
4
4
|
"description": "An MCP job bridge for bounded agent work, durable progress, results, and owner review.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -61,6 +61,7 @@
|
|
|
61
61
|
"oidc-provider": "9.13.0"
|
|
62
62
|
},
|
|
63
63
|
"devDependencies": {
|
|
64
|
+
"acorn": "8.15.0",
|
|
64
65
|
"ajv": "8.17.1",
|
|
65
66
|
"ajv-formats": "3.0.1",
|
|
66
67
|
"marked": "15.0.12"
|
package/src/acp-bridge.mjs
CHANGED
|
@@ -14,7 +14,7 @@ import { hostCheckRefusal } from './host-execution-policy.mjs';
|
|
|
14
14
|
import { redactLogEntry } from './redaction.mjs';
|
|
15
15
|
import { isLiteralScopePath, submissionLimits } from './submission-policy.mjs';
|
|
16
16
|
import { readablePath } from './path-syntax.mjs';
|
|
17
|
-
import { readOrCreateSecret, ownerToken } from '
|
|
17
|
+
import { readOrCreateSecret, ownerToken } from './owner-capability.mjs';
|
|
18
18
|
import { CONTINUE_PROMPT, promptText, unwrapUserRequest, isT3RuntimeBlock, parseIdentity } from '../integrations/t3/acp-kit/src/t3-envelope.mjs';
|
|
19
19
|
import { adminSocketPathError, adminSocketPath } from './admin-socket.mjs';
|
|
20
20
|
|
package/src/mcp-tasks.mjs
CHANGED
|
@@ -4,7 +4,7 @@ import fs from 'node:fs';
|
|
|
4
4
|
import os from 'node:os';
|
|
5
5
|
import path from 'node:path';
|
|
6
6
|
import { timingSafeEqual } from 'node:crypto';
|
|
7
|
-
import { ownerToken } from '
|
|
7
|
+
import { ownerToken } from './owner-capability.mjs';
|
|
8
8
|
import { defaultPath, ownerReceiptFile } from './paths.mjs';
|
|
9
9
|
import { safeDiagnostic } from './diagnostic.mjs';
|
|
10
10
|
import { MAX_ANSWER_BYTES } from './answer-journal.mjs';
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// Reattach capability: HMAC-SHA256(secret, id). The secret is created once (mode 0600, published atomically). The token is
|
|
2
|
+
// derived, not stored, so it is the same after a requester restart.
|
|
3
|
+
import { createHmac, randomBytes } from 'node:crypto';
|
|
4
|
+
import fs from 'node:fs';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
|
|
7
|
+
// Read the secret, create it on first use. A file that is not exactly 0600 or is too short is an error, never replaced.
|
|
8
|
+
export function readOrCreateSecret(file) {
|
|
9
|
+
fs.mkdirSync(path.dirname(file), { recursive: true, mode: 0o700 });
|
|
10
|
+
const read = () => {
|
|
11
|
+
const mode = fs.statSync(file).mode & 0o777;
|
|
12
|
+
if (mode !== 0o600) throw Object.assign(new Error(`${file} must be mode 0600 (found ${mode.toString(8)})`), { code: 'state_permissions' });
|
|
13
|
+
const secret = fs.readFileSync(file, 'utf8').trim();
|
|
14
|
+
if (secret.length < 32) throw new Error(`${file} is too short`);
|
|
15
|
+
return secret;
|
|
16
|
+
};
|
|
17
|
+
try { return read(); } catch (error) { if (error.code !== 'ENOENT') throw error; }
|
|
18
|
+
// link() fails with EEXIST when another creator won: the file appears complete or not at all, and the first one is kept.
|
|
19
|
+
const tmp = `${file}.${process.pid}.tmp`;
|
|
20
|
+
fs.writeFileSync(tmp, randomBytes(32).toString('hex') + '\n', { mode: 0o600 });
|
|
21
|
+
try { fs.linkSync(tmp, file); } catch (error) { if (error.code !== 'EEXIST') throw error; } finally { fs.rmSync(tmp, { force: true }); }
|
|
22
|
+
return read();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export const ownerToken = (secret, id) => createHmac('sha256', secret).update(id).digest('hex');
|
package/src/server.mjs
CHANGED
|
@@ -795,6 +795,15 @@ function sweepSkipped() {
|
|
|
795
795
|
for(const requestId of ids) { const waiter=waiters.get(requestId); if(waiter) { waiters.delete(requestId); clearTimeout(waiter.timer); json(waiter.res,200,waitSummary(requestId)); } }
|
|
796
796
|
return ids;
|
|
797
797
|
}
|
|
798
|
+
function notifyStalePrCancellation(requestId) {
|
|
799
|
+
log({kind:'pr_head_mismatch_cancelled',request_id:requestId});
|
|
800
|
+
const waiter=waiters.get(requestId);
|
|
801
|
+
if(waiter) {
|
|
802
|
+
waiters.delete(requestId);
|
|
803
|
+
clearTimeout(waiter.timer);
|
|
804
|
+
json(waiter.res,200,waitSummary(requestId));
|
|
805
|
+
}
|
|
806
|
+
}
|
|
798
807
|
// Abandon claims whose lease ran out (Store.sweepStaleLeases): the row is requeued and its lane is free.
|
|
799
808
|
function sweepStaleLeases() {
|
|
800
809
|
const ids=store.sweepStaleLeases();
|
|
@@ -1374,7 +1383,7 @@ async function dispatchTool(name,a,principal,notifyMeta,signal,batchMode=null,re
|
|
|
1374
1383
|
if(preflight) store.clearPrClaimMismatch(requestId,preflight);
|
|
1375
1384
|
}
|
|
1376
1385
|
catch(error) {
|
|
1377
|
-
if(error.prHeadMismatch
|
|
1386
|
+
if(error.prHeadMismatch&&store.recordPrClaimMismatch(requestId,error.prHeadMismatch)) notifyStalePrCancellation(requestId);
|
|
1378
1387
|
throw error;
|
|
1379
1388
|
}
|
|
1380
1389
|
}
|
|
@@ -2244,6 +2253,7 @@ function maintain() {
|
|
|
2244
2253
|
} catch(error) { log({kind:'facade_withdrawal_error',request_id:requestId,reason:error.message}); }
|
|
2245
2254
|
}
|
|
2246
2255
|
sweepExpired();
|
|
2256
|
+
for(const requestId of store.sweepPrClaimMismatches()) notifyStalePrCancellation(requestId);
|
|
2247
2257
|
sweepSkipped();
|
|
2248
2258
|
sweepStaleLeases();
|
|
2249
2259
|
store.retireUnknownSubscriptions();
|
package/src/store.mjs
CHANGED
|
@@ -209,6 +209,7 @@ const live=nowMs=>`NOT ${expired(nowMs)} AND (request_id NOT IN (SELECT request_
|
|
|
209
209
|
WHERE CAST(json_extract(p.settings,'$.retain_until_ms') AS INTEGER)>'${nowMs}'
|
|
210
210
|
AND NOT EXISTS (SELECT 1 FROM job_retention_tombstones t WHERE t.job=p.request_id)
|
|
211
211
|
))`;
|
|
212
|
+
const noPrClaimBlock=table=>`NOT EXISTS (SELECT 1 FROM pr_claim_blocks b WHERE b.request_id=${table}.request_id)`;
|
|
212
213
|
export const expiredError=(validUntil,{cancelled=false,requeue=false}={})=>`assignment_expired: its prepared inputs were valid until ${validUntil}; ${cancelled?'the bridge cancelled it and will not requeue it':requeue?'the bridge has not cancelled it; the expiry sweep will evaluate whether it can requeue it':'the bridge has not cancelled it yet and will not requeue it'}. Call list_pending, then claim another listed assignment.`;
|
|
213
214
|
const denialPattern=/auto-?review|guardian|denied|not approved|paused out of precaution/i;
|
|
214
215
|
export const workerGuidance='If auto-review or Guardian denies an action, stop that line of work, report BLOCKED: with the denied action, and never retry or rephrase to get around it. A denial or error about one assignment does not affect another: an error naming a different request_id (for example a finished assignment) is not a revocation of this one. An assignment with a new request_id that the owner submitted is a separate, fresh owner request, made after the owner saw the earlier outcome; it is not a retry of a denied action, so judge it on its own merits. If finish answers assignment_cancelled, the owner withdrew that request: this is not a denial and nothing to work around or retry; stop work on it and move on. Read the response to see whether bounded audit evidence was retained; output after the lease deadline is dropped. Check owner_notes on this assignment with get before finishing. Reading UI source that renders or validates a credential input field is ordinary UI work; the restriction is on revealing, copying, changing or transmitting actual secret values.';
|
|
@@ -2096,7 +2097,7 @@ export class Store {
|
|
|
2096
2097
|
}
|
|
2097
2098
|
// Queued assignments in list_pending order (waiting normal before other normal, then background and oldest) with queued_at (see queuedAt).
|
|
2098
2099
|
queuedRows() {
|
|
2099
|
-
return this.db.prepare(`SELECT a.request_id,a.payload,a.priority,a.caller_waiting,a.target_worker,${queuedAt} queued_at FROM assignments a WHERE a.status='queued' AND a.cancelled_at IS NULL AND ${live(this.nowMs())} ORDER BY ${LIST_ORDER}`).all();
|
|
2100
|
+
return this.db.prepare(`SELECT a.request_id,a.payload,a.priority,a.caller_waiting,a.target_worker,${queuedAt} queued_at FROM assignments a WHERE a.status='queued' AND a.cancelled_at IS NULL AND ${live(this.nowMs())} AND ${noPrClaimBlock('a')} ORDER BY ${LIST_ORDER}`).all();
|
|
2100
2101
|
}
|
|
2101
2102
|
// Break intervals [since, until or open] in ms. Owner since never reaches back before the previous break's end, so they are disjoint.
|
|
2102
2103
|
breakIntervals(worker='dot') {
|
|
@@ -2113,7 +2114,7 @@ export class Store {
|
|
|
2113
2114
|
// sending owner delivery are left out: they wait for reconcile, not for the worker. Derived only: a requeue restarts the clock.
|
|
2114
2115
|
unclaimedAfterReannounce(limits=this.limits,worker='dot') {
|
|
2115
2116
|
const now=this.nowMs(), windowMs=limits.rewakeWindowMs??defaultRedeliveryLimits.rewakeWindowMs, breaks=this.breakIntervals(worker);
|
|
2116
|
-
const rows=this.db.prepare(`SELECT a.request_id,${queuedAt} queued_at FROM assignments a WHERE a.target_worker=? AND a.status='queued' AND ${live(now)} ORDER BY queued_at`).all(worker).filter(r=>this.queuedAgeMs(r.queued_at,now,breaks)>=windowMs&&!this.uncertainDeliveries(r.request_id));
|
|
2117
|
+
const rows=this.db.prepare(`SELECT a.request_id,${queuedAt} queued_at FROM assignments a WHERE a.target_worker=? AND a.status='queued' AND ${live(now)} AND ${noPrClaimBlock('a')} ORDER BY queued_at`).all(worker).filter(r=>this.queuedAgeMs(r.queued_at,now,breaks)>=windowMs&&!this.uncertainDeliveries(r.request_id));
|
|
2117
2118
|
return {count:rows.length,oldest_age_ms:rows.length?now-Date.parse(rows[0].queued_at):null,request_ids:rows.slice(0,10).map(r=>r.request_id)};
|
|
2118
2119
|
}
|
|
2119
2120
|
// Honest classification of queued work after its first event 2xx. Observations only: nothing here reclaims or cancels a claim.
|
|
@@ -2137,7 +2138,7 @@ export class Store {
|
|
|
2137
2138
|
const hasLiveClaim=liveClaims.some(c=>now-Date.parse(c.last_claim_activity_at??c.claimed_at)<this.claimLeaseMs(c));
|
|
2138
2139
|
const atCapacity=liveSubs.length>0&&liveSubs.every(sub=>this.subscriptionFreeLanes(sub,limits.laneCapacity??6,capacity)===0);
|
|
2139
2140
|
const hasSubscription=liveSubs.length>0;
|
|
2140
|
-
const items=this.db.prepare(`SELECT request_id,created_at,skipped_at,NOT (${live(now)}) expired FROM assignments WHERE target_worker=? AND status='queued' AND cancelled_at IS NULL ORDER BY created_at`).all(worker).map(row=>{
|
|
2141
|
+
const items=this.db.prepare(`SELECT request_id,created_at,skipped_at,NOT (${live(now)}) expired FROM assignments WHERE target_worker=? AND status='queued' AND cancelled_at IS NULL AND ${noPrClaimBlock('assignments')} ORDER BY created_at`).all(worker).map(row=>{
|
|
2141
2142
|
// A queued row past its preparation's valid_until, or a protocol row past its retention, is 'expired', never alive_not_claiming: the worker cannot claim it.
|
|
2142
2143
|
if(row.expired) return {request_id:row.request_id,class:'expired',event_2xx_age_ms:null};
|
|
2143
2144
|
if(row.skipped_at!==null) return {request_id:row.request_id,class:null,event_2xx_age_ms:null};
|
|
@@ -2757,12 +2758,25 @@ export class Store {
|
|
|
2757
2758
|
FROM scoped_input_receipts WHERE request_id=? ORDER BY epoch,sha256`).all(id)
|
|
2758
2759
|
.map(({epoch,worker,sha256,metadata,complete})=>({...JSON.parse(metadata),epoch,worker,sha256,all_chunks_served:!!complete}));
|
|
2759
2760
|
}
|
|
2760
|
-
recordPrClaimMismatch(id,{pinned,observed}) {
|
|
2761
|
-
this.db.prepare(`INSERT INTO pr_claim_blocks(request_id,pinned,observed,checked_at)
|
|
2762
|
-
SELECT request_id,?,?,? FROM assignments WHERE request_id=? AND status='queued'
|
|
2761
|
+
recordPrClaimMismatch(id,{pinned,observed}) { return this.transaction(()=>{
|
|
2762
|
+
const recorded=this.db.prepare(`INSERT INTO pr_claim_blocks(request_id,pinned,observed,checked_at)
|
|
2763
|
+
SELECT request_id,?,?,? FROM assignments WHERE request_id=? AND status='queued' AND json_extract(payload,'$.inputs[0].head_sha')=?
|
|
2763
2764
|
ON CONFLICT(request_id) DO UPDATE SET observed=excluded.observed,checked_at=excluded.checked_at
|
|
2764
|
-
WHERE pr_claim_blocks.pinned=excluded.pinned`).run(pinned,observed,this.stamp(),id);
|
|
2765
|
+
WHERE pr_claim_blocks.pinned=excluded.pinned`).run(pinned,observed,this.stamp(),id,pinned);
|
|
2766
|
+
return recorded.changes>0&&this.cancelQueuedPrClaimMismatch(id);
|
|
2767
|
+
}); }
|
|
2768
|
+
cancelQueuedPrClaimMismatch(id) {
|
|
2769
|
+
if(this.uncertainDeliveries(id)) return false;
|
|
2770
|
+
const reason='pr_head_mismatch';
|
|
2771
|
+
this.cancelInTransaction(id,reason,'system');
|
|
2772
|
+
if(this.isProtocolJob(id)) this.protocolEventInTransaction(id,'cancelled',{reason});
|
|
2773
|
+
return true;
|
|
2765
2774
|
}
|
|
2775
|
+
sweepPrClaimMismatches(limit=100) { return this.transaction(()=>{
|
|
2776
|
+
const rows=this.db.prepare(`SELECT a.request_id FROM pr_claim_blocks b JOIN assignments a USING(request_id)
|
|
2777
|
+
WHERE a.status='queued' AND ${live(this.nowMs())} ORDER BY b.checked_at LIMIT ?`).all(limit);
|
|
2778
|
+
return rows.map(row=>row.request_id).filter(id=>this.cancelQueuedPrClaimMismatch(id));
|
|
2779
|
+
}); }
|
|
2766
2780
|
clearPrClaimMismatch(id,{head_sha,checked_at}) {
|
|
2767
2781
|
this.db.prepare('DELETE FROM pr_claim_blocks WHERE request_id=? AND pinned=? AND checked_at<=?')
|
|
2768
2782
|
.run(id,head_sha,checked_at);
|
|
@@ -3818,7 +3832,7 @@ export class Store {
|
|
|
3818
3832
|
const workCancelled=this.pullQueue.cancel(id,reason);if(workCancelled)return workCancelled;
|
|
3819
3833
|
return this.isProtocolJob(id)?cancelProtocolJob(this,id,reason,ownerToken,ctx):this.transaction(()=>this.cancelInTransaction(id,reason));
|
|
3820
3834
|
}
|
|
3821
|
-
cancelInTransaction(id,reason=null) {
|
|
3835
|
+
cancelInTransaction(id,reason=null,actor='owner') {
|
|
3822
3836
|
if(!this.db.isTransaction)protocolError('transaction_required');
|
|
3823
3837
|
const a=this.db.prepare('SELECT status FROM assignments WHERE request_id=?').get(id); if(!a) throw new Error('assignment not found'); if(a.status==='finished') throw new Error('already finished');
|
|
3824
3838
|
if(a.status!=='cancelled') {
|
|
@@ -3826,8 +3840,8 @@ export class Store {
|
|
|
3826
3840
|
const released=this.db.prepare('DELETE FROM admission_reservations WHERE request_id=?').run(id).changes>0;
|
|
3827
3841
|
if(a.status==='claimed'||released) this.laneFreed();
|
|
3828
3842
|
this.db.prepare("UPDATE assignments SET status='cancelled',cancelled_at=?,cancelled_reason=? WHERE request_id=?").run(this.stamp(),reason,id);
|
|
3829
|
-
this.lifecycle(id,'withdraw_work',
|
|
3830
|
-
this.lifecycle(id,'cancelled',
|
|
3843
|
+
this.lifecycle(id,'withdraw_work',actor,reason,undefined,{scope:`job:${id}`,outcome:'done'});
|
|
3844
|
+
this.lifecycle(id,'cancelled',actor,reason);
|
|
3831
3845
|
this.db.prepare("UPDATE notifications SET state='suppressed' WHERE request_id=? AND state IN ('pending','failed','waiting')").run(id);
|
|
3832
3846
|
this.db.prepare("UPDATE watches SET state='suppressed',updated_at=? WHERE request_id=? AND state IN ('armed','fired')").run(this.stamp(),id);
|
|
3833
3847
|
}
|
|
@@ -4311,7 +4325,7 @@ export class Store {
|
|
|
4311
4325
|
const counts=this.db.prepare(`SELECT status,count(*) count FROM assignments WHERE status<>'queued' OR ${live(this.nowMs())} GROUP BY status`).all().filter(x=>x.count>0);
|
|
4312
4326
|
const sub=this.db.prepare("SELECT * FROM subscriptions WHERE worker='dot' ORDER BY verified_at DESC LIMIT 1").get();
|
|
4313
4327
|
const active=this.activeSubscriptions().filter(sub=>sub.worker==='dot');
|
|
4314
|
-
const oldest=this.db.prepare(`SELECT min(created_at) oldest FROM assignments WHERE target_worker='dot' AND status='queued' AND ${live(this.nowMs())}`).get().oldest;
|
|
4328
|
+
const oldest=this.db.prepare(`SELECT min(created_at) oldest FROM assignments WHERE target_worker='dot' AND status='queued' AND ${live(this.nowMs())} AND ${noPrClaimBlock('assignments')}`).get().oldest;
|
|
4315
4329
|
const lastClaim=this.db.prepare("SELECT max(claimed_at) last_claim FROM claims WHERE worker='dot'").get().last_claim;
|
|
4316
4330
|
const uncertain=this.db.prepare("SELECT count(*) n FROM notifications WHERE state='uncertain' AND kind IN ('t3','watch','blocker','break','event')").get().n;
|
|
4317
4331
|
const pause=this.db.prepare('SELECT paused_at,reason FROM operator_state WHERE id=1').get();
|
|
@@ -4319,9 +4333,9 @@ export class Store {
|
|
|
4319
4333
|
SELECT target_worker worker,request_id,created_at,
|
|
4320
4334
|
count(*) OVER (PARTITION BY target_worker) n,
|
|
4321
4335
|
row_number() OVER (PARTITION BY target_worker ORDER BY created_at,request_id) rank
|
|
4322
|
-
FROM assignments WHERE status='queued' AND cancelled_at IS NULL AND skipped_at IS NULL AND ${live(this.nowMs())})
|
|
4336
|
+
FROM assignments WHERE status='queued' AND cancelled_at IS NULL AND skipped_at IS NULL AND ${live(this.nowMs())} AND ${noPrClaimBlock('assignments')})
|
|
4323
4337
|
SELECT worker,n,created_at oldest,request_id FROM live_queue WHERE rank=1`).all().map(r=>[r.worker,r]));
|
|
4324
|
-
const dotQueuedWithoutSubscription=active.length===0&&!!this.db.prepare(`SELECT 1 FROM assignments WHERE target_worker='dot' AND status='queued' AND ${live(this.nowMs())} LIMIT 1`).get();
|
|
4338
|
+
const dotQueuedWithoutSubscription=active.length===0&&!!this.db.prepare(`SELECT 1 FROM assignments WHERE target_worker='dot' AND status='queued' AND ${live(this.nowMs())} AND ${noPrClaimBlock('assignments')} LIMIT 1`).get();
|
|
4325
4339
|
const subscription={state:!sub?'absent':sub.state==='revoked'?'revoked':sub.rotation_blocked?'rotation_blocked':sub.auth_failures>=3?'callback_blocked':sub.expires_at<=this.stamp()?'expired':'active',expires_at:sub?.expires_at||null,last_verified_at:sub?.verified_at||null,last_event_2xx_at:sub?.last_event_2xx_at||null,last_claim_at:lastClaim,principal:sub?.principal||null,auth_failures:sub?.auth_failures||0};
|
|
4326
4340
|
const priority_counts=Object.fromEntries(['normal','background'].map(priority=>[priority,Object.fromEntries(['queued','claimed'].map(status=>[status,this.db.prepare(`SELECT count(*) n FROM assignments WHERE priority=? AND status=? AND (status<>'queued' OR ${live(this.nowMs())})`).get(priority,status).n]))]));
|
|
4327
4341
|
const throttle=this.rollingUsage(limits);
|