@teamclaws/teamclaw 2026.11.2 → 2026.11.3
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/controller/http-server.js +18 -0
- package/dist/src/controller/journal.js +68 -0
- package/dist/src/controller/provisioning/process-supervisor.js +58 -2
- package/dist/src/controller/provisioning-config.js +53 -0
- package/dist/src/controller/route-table.js +5 -0
- package/dist/src/controller/security.js +39 -0
- package/dist/src/controller/teamauto-routes.js +12 -0
- package/dist/src/controller/tunnel-manager.js +33 -1
- package/dist/src/controller/tunnel-routes.js +17 -1
- package/dist/src/controller/websocket.js +4 -0
- package/dist/src/controller/worker-provisioning.js +36 -0
- package/dist/src/state.js +77 -1
- package/dist/src/teamauto/github-client.js +33 -0
- package/dist/src/teamauto/scanner.js +9 -1
- package/dist/src/teamauto/scheduler.js +292 -17
- package/dist/src/teamauto/store.js +9 -0
- package/dist/src/ui/app.js +44 -0
- package/dist/src/ui/index.html +15 -0
- package/openclaw.plugin.json +1 -1
- package/package.json +1 -1
- package/src/controller/http-server.ts +18 -0
- package/src/controller/journal.ts +89 -0
- package/src/controller/provisioning/process-supervisor.ts +56 -2
- package/src/controller/provisioning-config.ts +54 -0
- package/src/controller/route-table.ts +5 -0
- package/src/controller/security.ts +40 -0
- package/src/controller/teamauto-routes.ts +12 -0
- package/src/controller/tunnel-manager.ts +34 -1
- package/src/controller/tunnel-routes.ts +18 -1
- package/src/controller/websocket.ts +5 -0
- package/src/controller/worker-provisioning.ts +34 -0
- package/src/state.ts +73 -2
- package/src/teamauto/github-client.ts +36 -0
- package/src/teamauto/scanner.ts +9 -1
- package/src/teamauto/scheduler.ts +295 -17
- package/src/teamauto/store.ts +31 -1
- package/src/ui/app.js +44 -0
- package/src/ui/index.html +15 -0
|
@@ -55,6 +55,7 @@ import {
|
|
|
55
55
|
loadOpenClawConfig,
|
|
56
56
|
} from "./provisioning-config.js";
|
|
57
57
|
import type { WorkerProvisionerBackend } from "./provisioning/backend-contract.js";
|
|
58
|
+
import { journalRecord } from "./journal.js";
|
|
58
59
|
import {
|
|
59
60
|
isDockerHostNetwork,
|
|
60
61
|
requiresDedicatedHostPortsForProvisioner,
|
|
@@ -236,6 +237,7 @@ export class WorkerProvisioningManager {
|
|
|
236
237
|
}
|
|
237
238
|
|
|
238
239
|
this.deps.logger.info(`Provisioner: terminating managed worker ${workerId} (${reason})`);
|
|
240
|
+
journalRecord("provisioner", "terminated", `${workerId} (${reason})`);
|
|
239
241
|
await this.terminateManagedWorker(workerId, reason, "terminated");
|
|
240
242
|
}
|
|
241
243
|
|
|
@@ -424,6 +426,7 @@ export class WorkerProvisioningManager {
|
|
|
424
426
|
);
|
|
425
427
|
}
|
|
426
428
|
this.deps.logger.info(`Provisioner: role ${role} needs ${demand} additional worker(s) (${reason})`);
|
|
429
|
+
journalRecord("provisioner", "demand", `${role} needs +${demand} (${reason})`);
|
|
427
430
|
}
|
|
428
431
|
for (let i = 0; i < demand; i += 1) {
|
|
429
432
|
if (this.hasRecentProvisioningFailure(role)) {
|
|
@@ -465,6 +468,7 @@ export class WorkerProvisioningManager {
|
|
|
465
468
|
continue;
|
|
466
469
|
}
|
|
467
470
|
this.deps.logger.info(`Provisioner: warming ${role} worker (${reason})`);
|
|
471
|
+
journalRecord("provisioner", "warming", `warming ${role} (${reason})`);
|
|
468
472
|
await this.launchWorker(role);
|
|
469
473
|
}
|
|
470
474
|
}
|
|
@@ -661,8 +665,38 @@ export class WorkerProvisioningManager {
|
|
|
661
665
|
});
|
|
662
666
|
|
|
663
667
|
this.deps.logger.info(`Provisioner: launched ${role} worker ${workerId} via ${this.backend.type}`);
|
|
668
|
+
journalRecord("provisioner", "launched", `${role} ${workerId} via ${this.backend.type}`);
|
|
664
669
|
} catch (err) {
|
|
665
670
|
const message = err instanceof Error ? err.message : String(err);
|
|
671
|
+
// #stuck-classification: state-library lock family ("another gateway
|
|
672
|
+
// owns this state directory", "undergoing offline maintenance",
|
|
673
|
+
// "pending native opener", ENOENT mkdtemp on a vanished session) is
|
|
674
|
+
// self-healable by retiring the poisoned sandbox and re-launching on
|
|
675
|
+
// a fresh one. A bare cooldown would retry against the SAME stuck
|
|
676
|
+
// state forever (observed: hours of starvation, 2026-11-13).
|
|
677
|
+
const healable = /owns this state directory|undergoing offline maintenance|pending native opener|ENOENT.*mkdtemp/i.test(message);
|
|
678
|
+
if (healable && this.backend?.type === "process") {
|
|
679
|
+
this.deps.logger.warn(`Provisioner: state-library failure for ${workerId} - retiring the poisoned sandbox and retrying once on a fresh one...`);
|
|
680
|
+
try {
|
|
681
|
+
await this.terminateManagedWorker(workerId, `state-library self-heal: ${message.slice(0, 80)}`, "failed");
|
|
682
|
+
} catch { /* best-effort */ }
|
|
683
|
+
try {
|
|
684
|
+
await this.launchWorker(role);
|
|
685
|
+
return;
|
|
686
|
+
} catch (retryErr) {
|
|
687
|
+
const retryMessage = retryErr instanceof Error ? retryErr.message : String(retryErr);
|
|
688
|
+
this.deps.updateTeamState((state) => {
|
|
689
|
+
const record = ensureProvisioningState(state).workers[workerId];
|
|
690
|
+
if (record) {
|
|
691
|
+
record.status = "failed";
|
|
692
|
+
record.updatedAt = Date.now();
|
|
693
|
+
record.lastError = retryMessage;
|
|
694
|
+
}
|
|
695
|
+
});
|
|
696
|
+
this.deps.logger.warn(`Provisioner: self-heal retry also failed for ${workerId}: ${retryMessage}`);
|
|
697
|
+
return;
|
|
698
|
+
}
|
|
699
|
+
}
|
|
666
700
|
this.deps.updateTeamState((state) => {
|
|
667
701
|
const record = ensureProvisioningState(state).workers[workerId];
|
|
668
702
|
if (!record) {
|
package/src/state.ts
CHANGED
|
@@ -7,6 +7,7 @@ import type {
|
|
|
7
7
|
StartupProvisioningReadiness,
|
|
8
8
|
TeamProvisioningState,
|
|
9
9
|
TeamState,
|
|
10
|
+
TeamMessage,
|
|
10
11
|
WorkerIdentity,
|
|
11
12
|
} from "./types.js";
|
|
12
13
|
import { validateRoleIdList } from "./roles.js";
|
|
@@ -240,6 +241,22 @@ async function writeFileAtomically(filePath: string, contents: string): Promise<
|
|
|
240
241
|
// filesystems (e.g. network mounts) reject explicit chmod.
|
|
241
242
|
}
|
|
242
243
|
await fs.rename(tmpPath, filePath);
|
|
244
|
+
// #267-4 hygiene: crash/rename failures used to leave *.tmp-* siblings
|
|
245
|
+
// forever (observed: 16 residue files in the runtime dir). Best-effort
|
|
246
|
+
// sweep of same-prefix leftovers older than 1h - never throws.
|
|
247
|
+
try {
|
|
248
|
+
const dir = path.dirname(filePath);
|
|
249
|
+
const prefix = path.basename(filePath) + ".tmp-";
|
|
250
|
+
const stale = Date.now() - 3_600_000;
|
|
251
|
+
for (const name of await fs.readdir(dir)) {
|
|
252
|
+
if (!name.startsWith(prefix)) continue;
|
|
253
|
+
const full = path.join(dir, name);
|
|
254
|
+
const st = await fs.stat(full).catch(() => null);
|
|
255
|
+
if (st && st.mtimeMs < stale) await fs.unlink(full).catch(() => {});
|
|
256
|
+
}
|
|
257
|
+
} catch {
|
|
258
|
+
// Hygiene is best-effort: any fs failure here is silently ignored.
|
|
259
|
+
}
|
|
243
260
|
}
|
|
244
261
|
|
|
245
262
|
function enqueueAtomicWrite(filePath: string, contents: string): Promise<void> {
|
|
@@ -280,8 +297,7 @@ function errorMessage(error: unknown): string {
|
|
|
280
297
|
return error instanceof Error ? error.message : String(error);
|
|
281
298
|
}
|
|
282
299
|
|
|
283
|
-
async function loadTeamState(teamName: string): Promise<TeamState | null> {
|
|
284
|
-
// Review fix (Phase 1.6): the instance-scoped team-state.json is the
|
|
300
|
+
async function loadTeamState(teamName: string): Promise<TeamState | null> { // Review fix (Phase 1.6): the instance-scoped team-state.json is the
|
|
285
301
|
// primary state file, and when it EXISTS it is authoritative. A
|
|
286
302
|
// present-but-corrupt primary is a fatal error, never a silent fallback to
|
|
287
303
|
// the legacy snapshot - falling back would rewind the team to the
|
|
@@ -290,6 +306,11 @@ async function loadTeamState(teamName: string): Promise<TeamState | null> {
|
|
|
290
306
|
let primaryRaw: string | null = null;
|
|
291
307
|
try {
|
|
292
308
|
primaryRaw = await fs.readFile(teamStateFilePath(), "utf8");
|
|
309
|
+
// #270: baseline the mtime right after reading so a foreign write between
|
|
310
|
+
// load and our first save is detected (not blindly overwritten).
|
|
311
|
+
try {
|
|
312
|
+
teamStateMtime.set(teamStateFilePath(), (await fs.stat(teamStateFilePath())).mtimeMs);
|
|
313
|
+
} catch { /* stat race - next save re-baselines */ }
|
|
293
314
|
} catch (error) {
|
|
294
315
|
if (!isFileMissing(error)) {
|
|
295
316
|
throw new Error(
|
|
@@ -330,6 +351,41 @@ async function loadTeamState(teamName: string): Promise<TeamState | null> {
|
|
|
330
351
|
}
|
|
331
352
|
}
|
|
332
353
|
|
|
354
|
+
// #270 lazy merge-on-write: last mtime this process observed for the team
|
|
355
|
+
// state file. A disk file NEWER than this stamp means another process wrote
|
|
356
|
+
// it (multi-gateway sharing one store) - the next save merges instead of
|
|
357
|
+
// blindly overwriting (which is how tasks "evaporated": 155/81 -> 135/72).
|
|
358
|
+
// Single-process cost: one stat() per save; the 24MB re-read+merge only
|
|
359
|
+
// happens when a foreign write is actually detected.
|
|
360
|
+
const teamStateMtime = new Map<string, number>();
|
|
361
|
+
|
|
362
|
+
/** #270: fold foreign keys back in. Key-level policy - keys present in the
|
|
363
|
+
* foreign snapshot but missing from OUR in-memory state are re-added (they
|
|
364
|
+
* were created by another process and a blind full-file write would erase
|
|
365
|
+
* them). Keys we hold locally always win (this process is the most recent
|
|
366
|
+
* writer for them). Messages union by id. */
|
|
367
|
+
function mergeForeignTeamState(state: TeamState, disk: Partial<TeamState>): void {
|
|
368
|
+
const recordKeys = ["workers", "tasks", "controllerRuns", "projects", "clarifications", "previews", "reports"] as const;
|
|
369
|
+
for (const key of recordKeys) {
|
|
370
|
+
const foreign = disk[key] as Record<string, unknown> | undefined;
|
|
371
|
+
if (!foreign || typeof foreign !== "object") continue;
|
|
372
|
+
const ours = (state[key] ?? {}) as Record<string, unknown>;
|
|
373
|
+
for (const [k, v] of Object.entries(foreign)) {
|
|
374
|
+
if (!(k in ours)) ours[k] = v;
|
|
375
|
+
}
|
|
376
|
+
(state as Record<string, unknown>)[key] = ours;
|
|
377
|
+
}
|
|
378
|
+
const foreignMsgs = Array.isArray(disk.messages) ? disk.messages : [];
|
|
379
|
+
if (foreignMsgs.length) {
|
|
380
|
+
const seen = new Set(state.messages.map((m) => m.id));
|
|
381
|
+
for (const m of foreignMsgs) {
|
|
382
|
+
if (m && typeof m === "object" && typeof (m as TeamMessage).id === "string" && !seen.has((m as TeamMessage).id)) {
|
|
383
|
+
state.messages.push(m as TeamMessage);
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
|
|
333
389
|
async function saveTeamState(state: TeamState): Promise<void> {
|
|
334
390
|
await ensureDir(STATE_DIR);
|
|
335
391
|
const filePath = teamStateFilePath();
|
|
@@ -348,7 +404,22 @@ async function saveTeamState(state: TeamState): Promise<void> {
|
|
|
348
404
|
state.projects = state.projects && typeof state.projects === "object"
|
|
349
405
|
? state.projects
|
|
350
406
|
: {};
|
|
407
|
+
// #270: if the disk file is newer than what THIS process last observed,
|
|
408
|
+
// another gateway wrote it - fold its keys back in before overwriting.
|
|
409
|
+
try {
|
|
410
|
+
const st = await fs.stat(filePath);
|
|
411
|
+
const known = teamStateMtime.get(filePath);
|
|
412
|
+
if (known !== undefined && st.mtimeMs > known) {
|
|
413
|
+
const disk = JSON.parse(await fs.readFile(filePath, "utf8")) as Partial<TeamState>;
|
|
414
|
+
mergeForeignTeamState(state, disk);
|
|
415
|
+
}
|
|
416
|
+
} catch {
|
|
417
|
+
/* first save / stat race - proceed with a plain write */
|
|
418
|
+
}
|
|
351
419
|
await enqueueAtomicWrite(filePath, `${JSON.stringify(state, null, 2)}\n`);
|
|
420
|
+
try {
|
|
421
|
+
teamStateMtime.set(filePath, (await fs.stat(filePath)).mtimeMs);
|
|
422
|
+
} catch { /* renamed away mid-write - next save re-baselines */ }
|
|
352
423
|
}
|
|
353
424
|
|
|
354
425
|
// ---------------------------------------------------------------------------
|
|
@@ -54,11 +54,17 @@ export type GithubRepoInfo = {
|
|
|
54
54
|
};
|
|
55
55
|
|
|
56
56
|
export function createGithubClient(auth: GithubAuthManager) {
|
|
57
|
+
// #267-3: cumulative API-call counters; runSweep reads etagStats() before/
|
|
58
|
+
// after each sweep and stores the DELTA on the repo's sweep record, so the
|
|
59
|
+
// shared client still yields correct per-repo attribution (sweeps are
|
|
60
|
+
// serialized by the sweeping set).
|
|
61
|
+
const etagCounters = { calls: 0, hits: 0 };
|
|
57
62
|
async function request(
|
|
58
63
|
method: string,
|
|
59
64
|
urlPath: string,
|
|
60
65
|
options: { body?: unknown; etagKey?: string; etags?: EtagCache } = {},
|
|
61
66
|
): Promise<{ status: number; data: unknown; notModified: boolean }> {
|
|
67
|
+
etagCounters.calls += 1;
|
|
62
68
|
const headers: Record<string, string> = {
|
|
63
69
|
...(await auth.getAuthHeaders()),
|
|
64
70
|
"User-Agent": USER_AGENT,
|
|
@@ -99,6 +105,9 @@ export function createGithubClient(auth: GithubAuthManager) {
|
|
|
99
105
|
const message = (data as { message?: string } | null)?.message ?? `HTTP ${response.status}`;
|
|
100
106
|
throw new GithubClientError(message, response.status);
|
|
101
107
|
}
|
|
108
|
+
if (response.status >= 200 && response.status < 300) {
|
|
109
|
+
etagCounters.hits += 1; // #267-3: "hits" = calls that returned fresh data (non-304 successes)
|
|
110
|
+
}
|
|
102
111
|
return { status: response.status, data, notModified: false };
|
|
103
112
|
}
|
|
104
113
|
|
|
@@ -110,6 +119,11 @@ export function createGithubClient(auth: GithubAuthManager) {
|
|
|
110
119
|
return {
|
|
111
120
|
request,
|
|
112
121
|
|
|
122
|
+
/** #267-3: cumulative etag/API counters (see etagCounters above). */
|
|
123
|
+
etagStats(): { calls: number; hits: number } {
|
|
124
|
+
return { ...etagCounters };
|
|
125
|
+
},
|
|
126
|
+
|
|
113
127
|
async getRepoInfo(owner: string, repo: string): Promise<GithubRepoInfo> {
|
|
114
128
|
const data = await getJson<Record<string, unknown>>(`/repos/${owner}/${repo}`);
|
|
115
129
|
if (!data) {
|
|
@@ -224,6 +238,28 @@ export function createGithubClient(auth: GithubAuthManager) {
|
|
|
224
238
|
await request("POST", `/repos/${owner}/${repo}/issues/${issueNumber}/assignees`, { body: { assignees: [assignee] } });
|
|
225
239
|
},
|
|
226
240
|
|
|
241
|
+
/** Fresh issue state for claim-time re-checks (#268): the scan-time
|
|
242
|
+
* assignee snapshot is seconds stale by enqueue time - a human may have
|
|
243
|
+
* self-assigned in between, and claiming over a human is worse than not
|
|
244
|
+
* claiming. */
|
|
245
|
+
async getIssue(owner: string, repo: string, issueNumber: number): Promise<{ assignees: string[]; state: string; updatedAt: string }> {
|
|
246
|
+
const { data } = await request("GET", `/repos/${owner}/${repo}/issues/${issueNumber}`);
|
|
247
|
+
const raw = data as Record<string, unknown>;
|
|
248
|
+
return {
|
|
249
|
+
assignees: Array.isArray(raw.assignees) ? raw.assignees.map((a) => String((a as { login?: string }).login ?? "")).filter(Boolean) : [],
|
|
250
|
+
state: String(raw.state ?? "open"),
|
|
251
|
+
updatedAt: String(raw.updated_at ?? ""),
|
|
252
|
+
};
|
|
253
|
+
},
|
|
254
|
+
|
|
255
|
+
/** Login of the authenticated account (#268): the assignee string for
|
|
256
|
+
* self-claiming. Kept here (not on the auth manager) so the claim path
|
|
257
|
+
* stays client-only. */
|
|
258
|
+
async getAuthenticatedUser(): Promise<{ login: string }> {
|
|
259
|
+
const { data } = await request("GET", "/user");
|
|
260
|
+
return { login: String((data as { login?: string }).login ?? "") };
|
|
261
|
+
},
|
|
262
|
+
|
|
227
263
|
/** Open a PR from a task worktree branch (collaboration contract delivery). */
|
|
228
264
|
async createPullRequest(owner: string, repo: string, head: string, base: string, title: string, body: string): Promise<{ number: number; url: string }> {
|
|
229
265
|
const { data } = await request("POST", `/repos/${owner}/${repo}/pulls`, {
|
package/src/teamauto/scanner.ts
CHANGED
|
@@ -151,7 +151,15 @@ export async function sweepRepo(
|
|
|
151
151
|
role: "qa" as const,
|
|
152
152
|
writeMode: "read-only" as const,
|
|
153
153
|
};
|
|
154
|
-
|
|
154
|
+
// #269 6th case (ggcode#4785): an issue eligible for BOTH actions got
|
|
155
|
+
// two tasks in the same sweep, each delivering its own comment - the
|
|
156
|
+
// delivery layer correctly treats them as independent entries. Collapse
|
|
157
|
+
// at the source: when ownership applies (open + enabled) it wins and
|
|
158
|
+
// subsumes the triage read; issueReview fires only when ownership is
|
|
159
|
+
// disabled for this repo (or the issue is closed and un-reviewable via
|
|
160
|
+
// ownership, e.g. follow-up triage on a closed issue).
|
|
161
|
+
const ownershipApplies = repo.policy.actions.takeOwnership && issue.state === "open";
|
|
162
|
+
if (repo.policy.actions.issueReview && !ownershipApplies) {
|
|
155
163
|
candidates.push({
|
|
156
164
|
...base,
|
|
157
165
|
kind: "issueReview",
|