@bakers-build/conductor 0.12.1-next.1 → 0.12.1-next.2
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/dist/src/core/conductor.d.ts +9 -0
- package/dist/src/core/conductor.js +50 -7
- package/dist/src/core/http-error.d.ts +5 -0
- package/dist/src/core/http-error.js +15 -0
- package/dist/src/plugins/tools.d.ts +5 -2
- package/dist/src/plugins/tools.js +15 -5
- package/dist/src/types.d.ts +1 -0
- package/package.json +4 -4
|
@@ -41,6 +41,10 @@ export declare class Conductor {
|
|
|
41
41
|
/** `~/.bakers/.bakers.env`, loaded at start; runs get declared names only. */
|
|
42
42
|
private readonly secrets;
|
|
43
43
|
private uuid;
|
|
44
|
+
/** While the server refuses claims (426): the current backoff, else 0. */
|
|
45
|
+
private claimBackoffMs;
|
|
46
|
+
/** No claim before this epoch ms while refused. */
|
|
47
|
+
private claimsRefusedUntil;
|
|
44
48
|
/**
|
|
45
49
|
* Frozen tickets seen on the last poll, by uuid, with the worktree their
|
|
46
50
|
* hook ran in. Mirrored to `frozenStateFile` when one is given, so an
|
|
@@ -126,6 +130,11 @@ export declare class Conductor {
|
|
|
126
130
|
/** Never throws: a failed state write leaves the grant on disk, and the next start prunes it. */
|
|
127
131
|
private revokeRunTools;
|
|
128
132
|
start(): Promise<void>;
|
|
133
|
+
/**
|
|
134
|
+
* The server refuses claims from this CLI version (426): say so once with
|
|
135
|
+
* its remedy, then retry claims at a doubling interval up to five minutes.
|
|
136
|
+
*/
|
|
137
|
+
private refuseClaims;
|
|
129
138
|
/** One tick that also waits for its actions: `bakers conductor once`, tests. */
|
|
130
139
|
tick(): Promise<void>;
|
|
131
140
|
/** A failing list query must not stop the other steps or the claims. */
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
2
2
|
import { basename, dirname, join } from 'node:path';
|
|
3
3
|
import { killRunProcesses, loadRunClone, pickSecrets, protectedProjectPaths, saveRunClone, shellQuote, stemForConfigFile, transferIsolatedCommit, } from '@bakers-build/core';
|
|
4
|
+
import { HttpError } from 'dropsh/plugin';
|
|
4
5
|
import { CONDUCTOR_TOKEN_ENV, CONDUCTOR_URL_ENV, DEFAULT_ENV_DENY, matchesEnvDeny, } from '../plugins/agent.js';
|
|
5
6
|
import { homeKey, homePath } from '../plugins/agent-home.js';
|
|
6
7
|
import { agentReason, resolveAgent, } from '../plugins/plugins.js';
|
|
@@ -11,6 +12,7 @@ import { loadTools } from '../plugins/tools.js';
|
|
|
11
12
|
import { ActionQueue } from './action-queue.js';
|
|
12
13
|
import { attemptFamily } from './attempt.js';
|
|
13
14
|
import { shellHookRunner } from './hook-runner.js';
|
|
15
|
+
import { httpErrorDetail, httpErrorText } from './http-error.js';
|
|
14
16
|
import { InboxRuntime, runInbox } from './inbox-runtime.js';
|
|
15
17
|
import { measureMrChanges, mrChangesRows } from './mr-changes.js';
|
|
16
18
|
import { runStartHooks } from './start-hooks.js';
|
|
@@ -45,6 +47,8 @@ function isReservedEnvKey(key) {
|
|
|
45
47
|
key === 'WORKSPACE_ROOT' ||
|
|
46
48
|
key === 'TICKET_URL');
|
|
47
49
|
}
|
|
50
|
+
/** The longest wait between claims the server refuses (426). */
|
|
51
|
+
const MAX_CLAIM_BACKOFF_MS = 300_000;
|
|
48
52
|
/** A portable environment variable name. */
|
|
49
53
|
const ENV_KEY = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
50
54
|
/**
|
|
@@ -200,6 +204,10 @@ export class Conductor {
|
|
|
200
204
|
readMachine;
|
|
201
205
|
secrets;
|
|
202
206
|
uuid = null;
|
|
207
|
+
/** While the server refuses claims (426): the current backoff, else 0. */
|
|
208
|
+
claimBackoffMs = 0;
|
|
209
|
+
/** No claim before this epoch ms while refused. */
|
|
210
|
+
claimsRefusedUntil = 0;
|
|
203
211
|
/**
|
|
204
212
|
* Frozen tickets seen on the last poll, by uuid, with the worktree their
|
|
205
213
|
* hook ran in. Mirrored to `frozenStateFile` when one is given, so an
|
|
@@ -467,6 +475,25 @@ export class Conductor {
|
|
|
467
475
|
this.logger.error({ conductorId: this.id }, line);
|
|
468
476
|
}
|
|
469
477
|
}
|
|
478
|
+
/**
|
|
479
|
+
* The server refuses claims from this CLI version (426): say so once with
|
|
480
|
+
* its remedy, then retry claims at a doubling interval up to five minutes.
|
|
481
|
+
*/
|
|
482
|
+
refuseClaims(err) {
|
|
483
|
+
if (this.claimBackoffMs) {
|
|
484
|
+
this.claimBackoffMs = Math.min(this.claimBackoffMs * 2, MAX_CLAIM_BACKOFF_MS);
|
|
485
|
+
this.logger.debug({
|
|
486
|
+
conductorId: this.id,
|
|
487
|
+
status: err.status,
|
|
488
|
+
backoffMs: this.claimBackoffMs,
|
|
489
|
+
}, 'claims still refused');
|
|
490
|
+
}
|
|
491
|
+
else {
|
|
492
|
+
this.claimBackoffMs = this.config.poll_interval_ms * 2;
|
|
493
|
+
this.logger.error({ conductorId: this.id, status: err.status }, `claims refused by the server: ${httpErrorDetail(err)}`);
|
|
494
|
+
}
|
|
495
|
+
this.claimsRefusedUntil = Date.now() + this.claimBackoffMs;
|
|
496
|
+
}
|
|
470
497
|
/** One tick that also waits for its actions: `bakers conductor once`, tests. */
|
|
471
498
|
async tick() {
|
|
472
499
|
await this.produce();
|
|
@@ -478,7 +505,7 @@ export class Conductor {
|
|
|
478
505
|
await fn();
|
|
479
506
|
}
|
|
480
507
|
catch (err) {
|
|
481
|
-
this.logger.warn({ conductorId: this.id, err:
|
|
508
|
+
this.logger.warn({ conductorId: this.id, err: httpErrorText(err) }, `${name} query failed`);
|
|
482
509
|
}
|
|
483
510
|
}
|
|
484
511
|
/**
|
|
@@ -532,12 +559,28 @@ export class Conductor {
|
|
|
532
559
|
this.logger.warn({ conductorId: this.id }, `claims withheld: ${line}`);
|
|
533
560
|
}
|
|
534
561
|
let claimed = 0;
|
|
535
|
-
|
|
562
|
+
// A refusal backs off silently: counted as withheld, so no idle line.
|
|
563
|
+
let withheld = unavailable.length > 0 || Date.now() < this.claimsRefusedUntil;
|
|
536
564
|
while (!withheld && machineLoad < maxParallel) {
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
565
|
+
let run;
|
|
566
|
+
try {
|
|
567
|
+
run = await this.remote.claimNext({
|
|
568
|
+
leaseSeconds: this.config.lease_seconds,
|
|
569
|
+
conductorId: this.id,
|
|
570
|
+
});
|
|
571
|
+
}
|
|
572
|
+
catch (err) {
|
|
573
|
+
if (!(err instanceof HttpError) || err.status !== 426)
|
|
574
|
+
throw err;
|
|
575
|
+
this.refuseClaims(err);
|
|
576
|
+
withheld = true;
|
|
577
|
+
break;
|
|
578
|
+
}
|
|
579
|
+
if (this.claimBackoffMs) {
|
|
580
|
+
this.claimBackoffMs = 0;
|
|
581
|
+
this.claimsRefusedUntil = 0;
|
|
582
|
+
this.logger.info({ conductorId: this.id }, 'claims accepted again');
|
|
583
|
+
}
|
|
541
584
|
if (!run)
|
|
542
585
|
break;
|
|
543
586
|
if ('reason' in run) {
|
|
@@ -1818,7 +1861,7 @@ export class Conductor {
|
|
|
1818
1861
|
await this.produce();
|
|
1819
1862
|
}
|
|
1820
1863
|
catch (err) {
|
|
1821
|
-
this.logger.error({ conductorId: this.id, err:
|
|
1864
|
+
this.logger.error({ conductorId: this.id, err: httpErrorText(err) }, 'tick failed');
|
|
1822
1865
|
}
|
|
1823
1866
|
await sleep(this.config.poll_interval_ms, signal);
|
|
1824
1867
|
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { HttpError } from 'dropsh/plugin';
|
|
2
|
+
/** An error for the log: the HTTP status plus the server's first JSON:API error, if any. */
|
|
3
|
+
export declare function httpErrorText(err: unknown): string;
|
|
4
|
+
/** The server's `detail` of an HTTP error, else its log text. */
|
|
5
|
+
export declare function httpErrorDetail(err: HttpError): string;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { HttpError } from 'dropsh/plugin';
|
|
2
|
+
const firstError = (err) => err.body?.errors?.[0];
|
|
3
|
+
/** An error for the log: the HTTP status plus the server's first JSON:API error, if any. */
|
|
4
|
+
export function httpErrorText(err) {
|
|
5
|
+
if (!(err instanceof HttpError))
|
|
6
|
+
return String(err);
|
|
7
|
+
const first = firstError(err);
|
|
8
|
+
return first
|
|
9
|
+
? `HTTP ${err.status} ${first.title ?? ''}: ${first.detail ?? ''}`
|
|
10
|
+
: `HTTP ${err.status}`;
|
|
11
|
+
}
|
|
12
|
+
/** The server's `detail` of an HTTP error, else its log text. */
|
|
13
|
+
export function httpErrorDetail(err) {
|
|
14
|
+
return firstError(err)?.detail || httpErrorText(err);
|
|
15
|
+
}
|
|
@@ -74,8 +74,11 @@ export interface ToolRegistry {
|
|
|
74
74
|
logger?: ConductorLogger;
|
|
75
75
|
}): Promise<ToolResult>;
|
|
76
76
|
}
|
|
77
|
-
/** `hooks.provision_up`: one command, or a command per profile. */
|
|
78
|
-
export type ProvisionHook = string | Record<string, string
|
|
77
|
+
/** `hooks.provision_up`: one command, or a command per profile, optionally described for the agent. */
|
|
78
|
+
export type ProvisionHook = string | Record<string, string | {
|
|
79
|
+
command: string;
|
|
80
|
+
description?: string;
|
|
81
|
+
}>;
|
|
79
82
|
export declare const PROVISION_TIMEOUT_MS: number;
|
|
80
83
|
type ShellResult = {
|
|
81
84
|
exitCode: number;
|
|
@@ -46,8 +46,11 @@ export function provisionTools(hook, runs = provisionRuns(), options = {}) {
|
|
|
46
46
|
typeof hook !== 'string' &&
|
|
47
47
|
(typeof hook !== 'object' ||
|
|
48
48
|
hook === null ||
|
|
49
|
-
Object.values(hook).some((cmd) => typeof cmd !== 'string'
|
|
50
|
-
|
|
49
|
+
Object.values(hook).some((cmd) => typeof cmd !== 'string' &&
|
|
50
|
+
(typeof cmd !== 'object' ||
|
|
51
|
+
cmd === null ||
|
|
52
|
+
typeof cmd.command !== 'string'))))
|
|
53
|
+
throw new Error('hooks.provision_up must be a command or a { profile: command | { command, description? } } map');
|
|
51
54
|
const keys = profiles ? Object.keys(profiles).join(', ') : '';
|
|
52
55
|
const commandFor = (profile) => {
|
|
53
56
|
if (!profiles)
|
|
@@ -55,8 +58,15 @@ export function provisionTools(hook, runs = provisionRuns(), options = {}) {
|
|
|
55
58
|
if (profile === undefined)
|
|
56
59
|
throw new Error(`provision_up: profile required, one of ${keys}`);
|
|
57
60
|
// The input schema's enum has already refused an unknown profile.
|
|
58
|
-
|
|
61
|
+
const entry = profiles[String(profile)];
|
|
62
|
+
return typeof entry === 'string' ? entry : entry.command;
|
|
59
63
|
};
|
|
64
|
+
// One `- name: description` line per described entry, after the tool's sentence.
|
|
65
|
+
const described = (entries) => Object.entries(entries)
|
|
66
|
+
.flatMap(([name, entry]) => typeof entry === 'object' && entry.description
|
|
67
|
+
? [`\n- ${name}: ${entry.description}`]
|
|
68
|
+
: [])
|
|
69
|
+
.join('');
|
|
60
70
|
// What a host script needs instead of asking Git in a workspace without one.
|
|
61
71
|
const envFor = (worktreePath) => ({
|
|
62
72
|
BAKERS_WORKTREE_PATH: worktreePath,
|
|
@@ -76,7 +86,7 @@ export function provisionTools(hook, runs = provisionRuns(), options = {}) {
|
|
|
76
86
|
const handlers = {};
|
|
77
87
|
if (hook !== undefined) {
|
|
78
88
|
tools.provision_up = {
|
|
79
|
-
description: `Bring this worktree's environment up${profiles ? ` with a configured profile (${keys})` : ''}; the project's command reuses a ready environment. Returns the command's output, including the base URL. The first call on a new worktree can take minutes; the call waits until the command ends, for up to 30 minutes. On a client timeout the command keeps running: call again with the same profile to join it and receive its result, without starting a second one
|
|
89
|
+
description: `Bring this worktree's environment up${profiles ? ` with a configured profile (${keys})` : ''}; the project's command reuses a ready environment. Returns the command's output, including the base URL. The first call on a new worktree can take minutes; the call waits until the command ends, for up to 30 minutes. On a client timeout the command keeps running: call again with the same profile to join it and receive its result, without starting a second one.${profiles ? described(profiles) : ''}`,
|
|
80
90
|
input: {
|
|
81
91
|
type: 'object',
|
|
82
92
|
properties: {
|
|
@@ -92,7 +102,7 @@ export function provisionTools(hook, runs = provisionRuns(), options = {}) {
|
|
|
92
102
|
if (Object.keys(exec).length > 0) {
|
|
93
103
|
const withArgs = Object.keys(exec).filter((key) => typeof exec[key] === 'object' && exec[key].args === true);
|
|
94
104
|
tools.provision_exec = {
|
|
95
|
-
description: `Run one of the project's configured commands (${Object.keys(exec).join(', ')}) for this worktree, such as a command in its site container. Each key is a fixed command; only ${withArgs.length ? withArgs.join(', ') : 'none'} also take \`args\`, passed as separate arguments after \`--\`, never through a shell. Returns the exit code and the output tail
|
|
105
|
+
description: `Run one of the project's configured commands (${Object.keys(exec).join(', ')}) for this worktree, such as a command in its site container. Each key is a fixed command; only ${withArgs.length ? withArgs.join(', ') : 'none'} also take \`args\`, passed as separate arguments after \`--\`, never through a shell. Returns the exit code and the output tail.${described(exec)}`,
|
|
96
106
|
input: {
|
|
97
107
|
type: 'object',
|
|
98
108
|
required: ['key'],
|
package/dist/src/types.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bakers-build/conductor",
|
|
3
|
-
"version": "0.12.1-next.
|
|
3
|
+
"version": "0.12.1-next.2",
|
|
4
4
|
"description": "bakers.build conductor engine + CLI: registers, claims tickets via JSON:API, dispatches agents.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -32,14 +32,14 @@
|
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"@dropsh/plugin-jsonapi-schema": "^0.8.2",
|
|
34
34
|
"@dropsh/plugin-oauth2": "^0.8.2",
|
|
35
|
-
"@bakers-build/core": "^0.12.1-next.
|
|
36
|
-
"@bakers-build/message": "^0.12.1-next.
|
|
35
|
+
"@bakers-build/core": "^0.12.1-next.2",
|
|
36
|
+
"@bakers-build/message": "^0.12.1-next.2",
|
|
37
37
|
"@modelcontextprotocol/sdk": "1.32.1",
|
|
38
38
|
"commander": "^12.1.0",
|
|
39
39
|
"dropsh": "^0.8.2"
|
|
40
40
|
},
|
|
41
41
|
"bakersBuild": {
|
|
42
|
-
"commit": "
|
|
42
|
+
"commit": "916eaf86970041ef80bf1976a465e1fc9af1b033",
|
|
43
43
|
"channel": "next"
|
|
44
44
|
}
|
|
45
45
|
}
|