@teamclaws/teamclaw 2026.11.5 → 2026.11.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -11
- package/dist/src/config.js +3 -3
- package/dist/src/controller/config-routes.js +7 -3
- package/dist/src/controller/controller-service.js +12 -1
- package/dist/src/controller/http-server.js +2 -2
- package/dist/src/controller/managed-gateway-process.js +17 -1
- package/dist/src/controller/provisioning/container-shared.js +6 -1
- package/dist/src/controller/provisioning/docker.js +1 -1
- package/dist/src/controller/provisioning/kubernetes.js +1 -1
- package/dist/src/controller/provisioning/process-supervisor.js +23 -1
- package/dist/src/controller/provisioning-config.js +8 -0
- package/dist/src/controller/route-table.js +2 -2
- package/dist/src/controller/security.js +30 -15
- package/dist/src/controller/task-assignment.js +126 -2
- package/dist/src/controller/task-results.js +34 -3
- package/dist/src/controller/task-routes.js +63 -3
- package/dist/src/controller/tunnel-manager.js +11 -0
- package/dist/src/controller/tunnel-routes.js +11 -0
- package/dist/src/controller/worker-provisioning.js +35 -0
- package/dist/src/controller/worker-routes.js +21 -6
- package/dist/src/controller/workspace-routes.js +16 -2
- package/dist/src/openclaw-workspace.js +39 -20
- package/dist/src/task-executor.js +44 -3
- package/dist/src/teamauto/github-client.js +107 -5
- package/dist/src/teamauto/repo-sync.js +172 -26
- package/dist/src/teamauto/scanner.js +22 -1
- package/dist/src/teamauto/scheduler.js +988 -190
- package/dist/src/teamauto/store.js +171 -3
- package/dist/src/teamauto/write-payload-guard.js +209 -0
- package/dist/src/types.js +11 -3
- package/dist/src/ui/app.js +2 -2
- package/dist/src/worker/tools.js +5 -0
- package/dist/src/worker/worker-service.js +13 -1
- package/dist/src/workspace-browser.js +14 -0
- package/openclaw.plugin.json +5 -5
- package/package.json +4 -2
- package/src/config.ts +3 -3
- package/src/controller/config-routes.ts +7 -3
- package/src/controller/controller-service.ts +12 -1
- package/src/controller/http-server.ts +2 -2
- package/src/controller/managed-gateway-process.ts +17 -1
- package/src/controller/provisioning/backend-contract.ts +4 -0
- package/src/controller/provisioning/container-shared.ts +6 -1
- package/src/controller/provisioning/docker.ts +1 -1
- package/src/controller/provisioning/kubernetes.ts +1 -1
- package/src/controller/provisioning/process-supervisor.ts +23 -1
- package/src/controller/provisioning-config.ts +9 -0
- package/src/controller/route-table.ts +2 -2
- package/src/controller/security.ts +30 -15
- package/src/controller/task-assignment.ts +128 -1
- package/src/controller/task-results.ts +33 -3
- package/src/controller/task-routes.ts +64 -2
- package/src/controller/tunnel-manager.ts +12 -1
- package/src/controller/tunnel-routes.ts +11 -0
- package/src/controller/worker-provisioning.ts +35 -0
- package/src/controller/worker-routes.ts +21 -7
- package/src/controller/workspace-routes.ts +17 -2
- package/src/openclaw-workspace.ts +43 -23
- package/src/task-executor.ts +46 -3
- package/src/teamauto/github-client.ts +103 -5
- package/src/teamauto/repo-sync.ts +158 -23
- package/src/teamauto/scanner.ts +23 -2
- package/src/teamauto/scheduler.ts +883 -113
- package/src/teamauto/store.ts +205 -3
- package/src/teamauto/write-payload-guard.ts +222 -0
- package/src/types.ts +30 -7
- package/src/ui/app.js +2 -2
- package/src/worker/tools.ts +5 -0
- package/src/worker/worker-service.ts +15 -1
- package/src/workspace-browser.ts +15 -0
|
@@ -10,7 +10,7 @@ import { buildEmptyTaskCleanupSummary, deleteTaskCascade } from "./task-cleanup.
|
|
|
10
10
|
import { allowsNoChangeCompletion, applyTaskResult, buildEffectiveTaskResultContract, consolidateDiscoveredPatterns, ensureTaskResultContract, enrichWithFilesystemHtmlScan, filterStaleDeliverables, projectHasMeaningfulFileChanges, taskRequiresMeaningfulProjectChangeGate, } from "./task-results.js";
|
|
11
11
|
import { requestTaskClarification } from "./clarification-routes.js";
|
|
12
12
|
import { buildControllerParallelHelpMessage, resolveControllerWorkflowSessionKey, } from "./controller-planning.js";
|
|
13
|
-
import { ControllerIntakeSwitchInProgressError, runControllerIntake, } from "./controller-intake.js";
|
|
13
|
+
import { ControllerIntakeSwitchInProgressError, isStillWaitingResponse, runControllerIntake, } from "./controller-intake.js";
|
|
14
14
|
import { buildStartupReadinessMessage, shouldBlockControllerUntilProvisioningReady, } from "./worker-routes.js";
|
|
15
15
|
import { buildControllerNoWorkersMessage, shouldBlockControllerWithoutWorkers, } from "./controller-capacity.js";
|
|
16
16
|
// Same value as the SWITCH_TASK_SUBMISSION_RETRY_AFTER_SECONDS constant the
|
|
@@ -189,12 +189,25 @@ export async function handleTaskExecutionGetRequest(deps, res, pathname) {
|
|
|
189
189
|
}
|
|
190
190
|
// PATCH /api/v1/tasks/:id
|
|
191
191
|
export async function handleTaskPatchRequest(deps, req, res, pathname) {
|
|
192
|
-
const { updateTeamState, wsServer } = deps;
|
|
192
|
+
const { updateTeamState, wsServer, logger, getTeamState } = deps;
|
|
193
193
|
const taskId = pathname.split("/").pop();
|
|
194
194
|
const body = await parseJsonBody(req);
|
|
195
195
|
let statusEvent;
|
|
196
196
|
let progressEvent;
|
|
197
197
|
let progressContract;
|
|
198
|
+
// #5740 (ggcode, 2026-11-17): worker progress PATCHes now carry workerId;
|
|
199
|
+
// when present, the same stale-worker guard as the result routes applies
|
|
200
|
+
// so a dispatched-but-reverted (orphaned) run cannot keep mutating the
|
|
201
|
+
// task it no longer owns.
|
|
202
|
+
const patchWorkerId = typeof body.workerId === "string" ? body.workerId : undefined;
|
|
203
|
+
if (patchWorkerId) {
|
|
204
|
+
const currentTask = getTeamState()?.tasks[taskId];
|
|
205
|
+
if (currentTask && !canAcceptWorkerUpdate(currentTask, patchWorkerId)) {
|
|
206
|
+
logger.info(`Controller: ignoring stale task patch for ${taskId} from ${patchWorkerId}`);
|
|
207
|
+
sendJson(res, 202, { status: "ignored", reason: "stale-worker-update" });
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
198
211
|
const state = updateTeamState((s) => {
|
|
199
212
|
const task = s.tasks[taskId];
|
|
200
213
|
if (!task)
|
|
@@ -202,6 +215,16 @@ export async function handleTaskPatchRequest(deps, req, res, pathname) {
|
|
|
202
215
|
const previousStatus = task.status;
|
|
203
216
|
const previousProgress = task.progress;
|
|
204
217
|
const previousProgressContract = task.progressContract;
|
|
218
|
+
// #5740: a bare PATCH (no workerId, e.g. WebUI) must not flip a pending,
|
|
219
|
+
// unassigned task to in_progress - that is exactly the illegal
|
|
220
|
+
// unclaimed-execution state the claim gate exists to prevent. The
|
|
221
|
+
// progress text below still applies.
|
|
222
|
+
if (typeof body.status === "string"
|
|
223
|
+
&& body.status === "in_progress"
|
|
224
|
+
&& task.status === "pending"
|
|
225
|
+
&& !task.assignedWorkerId) {
|
|
226
|
+
delete body.status;
|
|
227
|
+
}
|
|
205
228
|
if (typeof body.status === "string")
|
|
206
229
|
task.status = body.status;
|
|
207
230
|
if (typeof body.progress === "string")
|
|
@@ -466,7 +489,7 @@ export async function handleTaskResultRequest(deps, req, res, pathname) {
|
|
|
466
489
|
const { logger, getTeamState, updateTeamState } = deps;
|
|
467
490
|
const taskId = pathname.split("/")[4];
|
|
468
491
|
const body = await parseJsonBody(req);
|
|
469
|
-
|
|
492
|
+
let result = typeof body.result === "string" ? body.result : "";
|
|
470
493
|
let error = typeof body.error === "string" ? body.error : undefined;
|
|
471
494
|
const workerId = typeof body.workerId === "string" ? body.workerId : undefined;
|
|
472
495
|
const currentTask = getTeamState()?.tasks[taskId];
|
|
@@ -551,6 +574,43 @@ export async function handleTaskResultRequest(deps, req, res, pathname) {
|
|
|
551
574
|
return;
|
|
552
575
|
}
|
|
553
576
|
const gatedTask = getTeamState()?.tasks[taskId];
|
|
577
|
+
// #5767 fourth hole: a worker that never produced work can "complete" by
|
|
578
|
+
// submitting the waiting SENTINEL as its result (live: f12efcdb completed
|
|
579
|
+
// with `TEAMCLAW_STILL_WAITING`). The sentinel means "not done yet" - it
|
|
580
|
+
// must never satisfy completion. Reject with an empty stored result so the
|
|
581
|
+
// failed-without-result semantics apply (terminal write-back, claim
|
|
582
|
+
// recovery re-opens the issue, the next sweep retries).
|
|
583
|
+
if (!error && gatedTask && isStillWaitingResponse(result)) {
|
|
584
|
+
error = "Task submitted the TEAMCLAW_STILL_WAITING placeholder as its result - the task is still waiting, not complete. Result discarded; the issue will be re-opened for the next sweep.";
|
|
585
|
+
recordTaskExecutionEvent(taskId, {
|
|
586
|
+
type: "warning",
|
|
587
|
+
phase: "completion_gate",
|
|
588
|
+
source: "controller",
|
|
589
|
+
status: "failed",
|
|
590
|
+
message: error,
|
|
591
|
+
workerId,
|
|
592
|
+
role: gatedTask.assignedRole,
|
|
593
|
+
}, deps);
|
|
594
|
+
result = "";
|
|
595
|
+
}
|
|
596
|
+
// #5770 leg A: a MID-FLIGHT narration is not a final result either (live:
|
|
597
|
+
// "Tree is clean. Now implementing the fix - first the helper in ...").
|
|
598
|
+
// Present-progressive openers mean the work has NOT finished; accepting
|
|
599
|
+
// them completes a task with zero product. Reject like the sentinel -
|
|
600
|
+
// fresh attempt on the next sweep once the worker actually finishes.
|
|
601
|
+
if (!error && gatedTask && /\b(?:now|currently|next)\s+(?:implementing|working on|fixing|writing|adding|refactoring|investigating|starting)\b/i.test(result.slice(0, 400))) {
|
|
602
|
+
error = "Task submitted a mid-flight narration (present-progressive) as its result - the work is still in progress, not complete. Result discarded; the issue will be re-opened for the next sweep.";
|
|
603
|
+
recordTaskExecutionEvent(taskId, {
|
|
604
|
+
type: "warning",
|
|
605
|
+
phase: "completion_gate",
|
|
606
|
+
source: "controller",
|
|
607
|
+
status: "failed",
|
|
608
|
+
message: error,
|
|
609
|
+
workerId,
|
|
610
|
+
role: gatedTask.assignedRole,
|
|
611
|
+
}, deps);
|
|
612
|
+
result = "";
|
|
613
|
+
}
|
|
554
614
|
if (!error
|
|
555
615
|
&& gatedTask
|
|
556
616
|
&& taskRequiresMeaningfulProjectChangeGate(gatedTask)
|
|
@@ -448,6 +448,17 @@ export function createTunnelManager(deps) {
|
|
|
448
448
|
const st = readTunnelState();
|
|
449
449
|
if (!st || st.tunnelId === "quick")
|
|
450
450
|
return null; // one-off, not recoverable
|
|
451
|
+
// ClawHub security review 2026.11.6 (finding 4): a self-hosted tunnel's
|
|
452
|
+
// custom hostname never matches the built-in gate suffixes, so its
|
|
453
|
+
// traffic arrives as a loopback peer and inherits trusted-host access.
|
|
454
|
+
// Device protection is the only thing standing between that public
|
|
455
|
+
// ingress and the API - do not reconnect one while protection is off;
|
|
456
|
+
// drop the stale state so the owner re-enables deliberately.
|
|
457
|
+
if (st.tunnelId === "self-hosted" && deps.isProtectionOn && !deps.isProtectionOn()) {
|
|
458
|
+
logger.warn("TeamClaw tunnel: NOT recovering the previous self-hosted tunnel - device protection is off and a custom-domain tunnel bypasses the sharing gate; enable device pairing (POST /api/v1/security/enable) and start it again from the Tunnel page");
|
|
459
|
+
clearTunnelState();
|
|
460
|
+
return null;
|
|
461
|
+
}
|
|
451
462
|
const bin = findCloudflared();
|
|
452
463
|
if (!bin) {
|
|
453
464
|
logger.warn("TeamClaw tunnel: previous share found but cloudflared is not installed; not recovering");
|
|
@@ -176,6 +176,17 @@ export function createTunnelManagementRoutes(tunnelManager, deps) {
|
|
|
176
176
|
if (!tunnelStartAllowedFrom(req, res)) {
|
|
177
177
|
return;
|
|
178
178
|
}
|
|
179
|
+
// ClawHub security review 2026.11.6 (finding 4): a self-hosted
|
|
180
|
+
// tunnel's custom hostname is outside the built-in gate, so its
|
|
181
|
+
// requests arrive as trusted loopback peers. Without device
|
|
182
|
+
// protection that is unauthenticated public access to the API.
|
|
183
|
+
if (!isProtectionOn(deps.getTeamState())) {
|
|
184
|
+
sendJson(res, 409, {
|
|
185
|
+
error: "device protection must be enabled before starting a self-hosted tunnel",
|
|
186
|
+
hint: "A custom-domain tunnel bypasses the sharing gate (its hostname is not *.teamclaw.dev), so every request reaches this controller as a trusted local peer. Enable device pairing first (POST /api/v1/security/enable from the controller host), then start the tunnel. Managed (*.teamclaw.dev) tunnels are gate-protected and unaffected.",
|
|
187
|
+
});
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
179
190
|
logger.info(`TeamClaw tunnel: start-self-hosted requested (${tunnelCaller(req)})`);
|
|
180
191
|
let token = "";
|
|
181
192
|
try {
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
// below keep their historical module path and signatures.
|
|
18
18
|
import fs from "node:fs/promises";
|
|
19
19
|
import net from "node:net";
|
|
20
|
+
import os from "node:os";
|
|
20
21
|
import path from "node:path";
|
|
21
22
|
import { generateId, generateLaunchToken, secretsEqual } from "../protocol.js";
|
|
22
23
|
// Issue #255 P0-1: the launch-token check at registration uses the shared
|
|
@@ -60,6 +61,39 @@ export class WorkerProvisioningManager {
|
|
|
60
61
|
constructor(deps) {
|
|
61
62
|
this.deps = deps;
|
|
62
63
|
this.backend = createProvisionerBackend(deps.config, deps.logger);
|
|
64
|
+
// #rate-limit-999 terminal fix: EMBEDDED workers (every in-gateway
|
|
65
|
+
// ProvisionedWorker - the common case) read the CONTROLLER's own agent
|
|
66
|
+
// scope (~/.openclaw/agents/teamclaw/agent/settings.json), not the
|
|
67
|
+
// per-worker state dirs the v2 fix stamped. That scope had been left at
|
|
68
|
+
// maxRetries=999 (the old config default), so embedded workers ground
|
|
69
|
+
// themselves to death retrying 429s. Heal it at startup - read-modify-
|
|
70
|
+
// write touching ONLY retry.provider.maxRetries, preserving other keys.
|
|
71
|
+
void this.healControllerAgentRetrySettings().catch((err) => {
|
|
72
|
+
deps.logger.warn?.(`Controller: failed to heal controller agent retry settings: ${String(err)}`);
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
async healControllerAgentRetrySettings() {
|
|
76
|
+
const stateRoot = process.env.OPENCLAW_STATE_DIR
|
|
77
|
+
? process.env.OPENCLAW_STATE_DIR
|
|
78
|
+
: path.join(os.homedir(), ".openclaw");
|
|
79
|
+
const settingsPath = path.join(stateRoot, "agents", "teamclaw", "agent", "settings.json");
|
|
80
|
+
let current = {};
|
|
81
|
+
try {
|
|
82
|
+
current = JSON.parse(await fs.readFile(settingsPath, "utf8"));
|
|
83
|
+
}
|
|
84
|
+
catch { /* absent or unreadable - stamp fresh */ }
|
|
85
|
+
const retry = (current.retry && typeof current.retry === "object") ? current.retry : {};
|
|
86
|
+
const provider = (retry.provider && typeof retry.provider === "object") ? retry.provider : {};
|
|
87
|
+
if (provider.maxRetries === this.deps.config.workerRateLimitMaxRetries) {
|
|
88
|
+
return; // already correct
|
|
89
|
+
}
|
|
90
|
+
provider.maxRetries = this.deps.config.workerRateLimitMaxRetries;
|
|
91
|
+
retry.enabled = retry.enabled !== false;
|
|
92
|
+
retry.provider = provider;
|
|
93
|
+
current.retry = retry;
|
|
94
|
+
await fs.mkdir(path.dirname(settingsPath), { recursive: true }).catch(() => { });
|
|
95
|
+
await fs.writeFile(settingsPath, JSON.stringify(current, null, 2) + "\n", { encoding: "utf8", mode: 0o600 });
|
|
96
|
+
this.deps.logger.info?.(`Controller: healed controller agent retry scope - provider.maxRetries=${this.deps.config.workerRateLimitMaxRetries} (${settingsPath})`);
|
|
63
97
|
}
|
|
64
98
|
/** Update the actual controller port after the HTTP server binds. */
|
|
65
99
|
setActualPort(port) {
|
|
@@ -525,6 +559,7 @@ export class WorkerProvisioningManager {
|
|
|
525
559
|
workspaceDir: getConfiguredWorkerWorkspaceDir(workerConfig),
|
|
526
560
|
env: this.buildForwardedEnv(controllerUrl),
|
|
527
561
|
configJson: `${JSON.stringify(workerConfig, null, 2)}\n`,
|
|
562
|
+
rateLimitMaxRetries: this.deps.config.workerRateLimitMaxRetries,
|
|
528
563
|
});
|
|
529
564
|
this.deps.updateTeamState((state) => {
|
|
530
565
|
const record = ensureProvisioningState(state).workers[workerId];
|
|
@@ -108,17 +108,32 @@ export async function handleWorkerListRequest(deps, res) {
|
|
|
108
108
|
}
|
|
109
109
|
// POST /api/v1/workers/:id/heartbeat
|
|
110
110
|
export async function handleWorkerHeartbeatRequest(deps, req, res, pathname) {
|
|
111
|
-
const { updateTeamState } = deps;
|
|
111
|
+
const { updateTeamState, logger } = deps;
|
|
112
112
|
const workerId = pathname.split("/")[4];
|
|
113
113
|
const body = await parseJsonBody(req);
|
|
114
114
|
const status = typeof body.status === "string" ? body.status : "idle";
|
|
115
|
-
const
|
|
115
|
+
const reportedTaskId = typeof body.currentTaskId === "string" ? body.currentTaskId : undefined;
|
|
116
|
+
// #busy-clamp (user report 2026-11-15: one QA worker visibly running TWO
|
|
117
|
+
// in-progress tasks): the registry must not TRUST a worker-reported idle
|
|
118
|
+
// while the SERVER has that worker bound to a task. A busy worker's
|
|
119
|
+
// heartbeat can lag its own truth (double-assigned before this fix, or a
|
|
120
|
+
// heartbeat fired between task boundaries) - honoring it flipped the
|
|
121
|
+
// registry to idle and the assigner re-picked the still-busy worker 14s
|
|
122
|
+
// later. Server-side assignment is the source of truth: busy + bound
|
|
123
|
+
// currentTaskId survives until the task itself settles (completion/failure
|
|
124
|
+
// paths clear it) or the worker reports THAT task id as done.
|
|
116
125
|
updateTeamState((s) => {
|
|
117
|
-
if (s.workers[workerId])
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
126
|
+
if (!s.workers[workerId])
|
|
127
|
+
return;
|
|
128
|
+
const w = s.workers[workerId];
|
|
129
|
+
w.lastHeartbeat = Date.now();
|
|
130
|
+
const serverBusy = w.status === "busy" && Boolean(w.currentTaskId);
|
|
131
|
+
if (serverBusy && status === "idle" && reportedTaskId !== w.currentTaskId) {
|
|
132
|
+
logger.warn?.(`Controller: heartbeat from ${workerId} claimed idle while bound to ${w.currentTaskId} - clamping to busy (server truth wins)`);
|
|
133
|
+
return; // keep busy + currentTaskId; only lastHeartbeat updated
|
|
121
134
|
}
|
|
135
|
+
w.status = status;
|
|
136
|
+
w.currentTaskId = reportedTaskId;
|
|
122
137
|
});
|
|
123
138
|
deps.workerProvisioningManager?.onWorkerHeartbeat(workerId, status);
|
|
124
139
|
if (status === "idle") {
|
|
@@ -19,6 +19,8 @@ function workspaceRequestErrorStatus(err) {
|
|
|
19
19
|
function workspaceRequestErrorMessage(err) {
|
|
20
20
|
return err instanceof Error ? err.message : "Workspace request failed";
|
|
21
21
|
}
|
|
22
|
+
// Active content the raw route must sandbox on direct navigation (finding 6).
|
|
23
|
+
const ACTIVE_CONTENT_TYPES = new Set(["text/html; charset=utf-8", "image/svg+xml"]);
|
|
22
24
|
function workspaceStatusRoute(ctx) {
|
|
23
25
|
const { res } = ctx;
|
|
24
26
|
sendJson(res, 200, {
|
|
@@ -181,7 +183,15 @@ async function workspaceRawFileRoute(ctx) {
|
|
|
181
183
|
try {
|
|
182
184
|
const relativePath = decodeURIComponent(rawPathname);
|
|
183
185
|
const file = await readWorkspaceRawFile(relativePath);
|
|
184
|
-
|
|
186
|
+
// ClawHub security review 2026.11.6 (finding 6): HTML/SVG served with
|
|
187
|
+
// their active MIME type under the controller origin execute with the
|
|
188
|
+
// owner's session on DIRECT navigation (the preview iframe's sandbox
|
|
189
|
+
// attribute does not travel with the "Open Raw" link). A response-level
|
|
190
|
+
// CSP sandbox without allow-same-origin gives the document an opaque
|
|
191
|
+
// origin even on top-level navigation: scripts may run (the preview
|
|
192
|
+
// already allows that) but cannot read controller cookies or call
|
|
193
|
+
// /api/v1/* same-origin. Mirrors the iframe flags byte for byte.
|
|
194
|
+
const headers = {
|
|
185
195
|
"Content-Type": file.contentType,
|
|
186
196
|
"Cache-Control": "no-store",
|
|
187
197
|
// Issue #23 security review follow-up: honor a CORS origin the
|
|
@@ -190,7 +200,11 @@ async function workspaceRawFileRoute(ctx) {
|
|
|
190
200
|
// historical "*" byte for byte (shared helper, see protocol.ts).
|
|
191
201
|
"Access-Control-Allow-Origin": pinnedCorsAllowOrigin(res),
|
|
192
202
|
"X-Content-Type-Options": "nosniff",
|
|
193
|
-
}
|
|
203
|
+
};
|
|
204
|
+
if (ACTIVE_CONTENT_TYPES.has(file.contentType)) {
|
|
205
|
+
headers["Content-Security-Policy"] = "sandbox allow-scripts allow-forms";
|
|
206
|
+
}
|
|
207
|
+
res.writeHead(200, headers);
|
|
194
208
|
res.end(file.content);
|
|
195
209
|
}
|
|
196
210
|
catch (err) {
|
|
@@ -661,34 +661,53 @@ export async function updateTeamClawModelConfig(update, logger, env = process.en
|
|
|
661
661
|
* pattern as updateTeamClawModelConfig). Only whitelisted fields are
|
|
662
662
|
* touched; unknown keys in the existing plugin config are preserved.
|
|
663
663
|
*/
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
664
|
+
// #hot-reload (user report 2026-11-15 13:48): persisting these three
|
|
665
|
+
// numbers into the HOST openclaw.json (plugins.entries.teamclaw.config)
|
|
666
|
+
// made the host CONFIG WATCHER drain+reload the ENTIRE teamclaw plugin on
|
|
667
|
+
// every PATCH - in-flight tasks interrupted, all workers restarted, a 2s
|
|
668
|
+
// main-thread stall, and the reload itself frequently FAILED (controller
|
|
669
|
+
// service stop timeout) which rolled the change back: the update visibly
|
|
670
|
+
// "caused a gateway restart" and then "did not apply". Pure numeric caps
|
|
671
|
+
// never needed host-config semantics - persist to the plugin's OWN state
|
|
672
|
+
// (provisioning-hot-config.json beside team-state.json) and re-apply on
|
|
673
|
+
// controller start. No host file change -> no plugin reload ->真热更新。
|
|
674
|
+
function provisioningHotConfigPath(env = process.env, homedir = os.homedir) {
|
|
675
|
+
const explicitStateDir = env.OPENCLAW_STATE_DIR?.trim();
|
|
676
|
+
const base = explicitStateDir
|
|
677
|
+
? path.join(explicitStateDir, "plugins", "teamclaw")
|
|
678
|
+
: path.join(homedir(), ".openclaw", "plugins", "teamclaw");
|
|
679
|
+
return path.join(base, "provisioning-hot-config.json");
|
|
680
|
+
}
|
|
681
|
+
export async function loadProvisioningHotConfig(env = process.env, homedir = os.homedir) {
|
|
667
682
|
try {
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
683
|
+
const raw = JSON5.parse(await fs.readFile(provisioningHotConfigPath(env, homedir), "utf8"));
|
|
684
|
+
const out = {};
|
|
685
|
+
for (const key of ["workerProvisioningMinPerRole", "workerProvisioningMaxPerRole", "workerProvisioningIdleTtlMs"]) {
|
|
686
|
+
const v = raw[key];
|
|
687
|
+
if (typeof v === "number" && Number.isFinite(v))
|
|
688
|
+
out[key] = v;
|
|
671
689
|
}
|
|
690
|
+
return Object.keys(out).length > 0 ? out : null;
|
|
672
691
|
}
|
|
673
|
-
catch
|
|
674
|
-
|
|
692
|
+
catch {
|
|
693
|
+
return null; // absent/first run - host-config defaults stand
|
|
675
694
|
}
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
const
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
695
|
+
}
|
|
696
|
+
export async function updateTeamClawProvisioningConfig(update, logger, env = process.env, homedir = os.homedir) {
|
|
697
|
+
const configPath = provisioningHotConfigPath(env, homedir);
|
|
698
|
+
let current = {};
|
|
699
|
+
try {
|
|
700
|
+
current = JSON5.parse(await fs.readFile(configPath, "utf8"));
|
|
701
|
+
}
|
|
702
|
+
catch { /* absent - start fresh */ }
|
|
682
703
|
for (const [key, value] of Object.entries(update)) {
|
|
683
704
|
if (typeof value === "number" && Number.isFinite(value)) {
|
|
684
|
-
|
|
705
|
+
current[key] = value;
|
|
685
706
|
}
|
|
686
707
|
}
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
await fs.writeFile(configPath, `${JSON.stringify(parsed, null, 2)}\n`, "utf8");
|
|
691
|
-
logger?.warn?.("TeamClaw: worker provisioning config persisted (hot-reload applies to the running controller)");
|
|
708
|
+
await fs.mkdir(path.dirname(configPath), { recursive: true });
|
|
709
|
+
await fs.writeFile(configPath, `${JSON.stringify(current, null, 2)}\n`, "utf8");
|
|
710
|
+
logger?.warn?.(`TeamClaw: worker provisioning config persisted to plugin state (${configPath}) - no host-config change, no plugin reload`);
|
|
692
711
|
return { configPath };
|
|
693
712
|
}
|
|
694
713
|
/**
|
|
@@ -27,7 +27,7 @@ export function createRoleTaskExecutor(deps) {
|
|
|
27
27
|
const roleSystemPrompt = roleDef
|
|
28
28
|
? roleDef.systemPrompt
|
|
29
29
|
: `You are a ${role} in a virtual software team. Complete the assigned task.`;
|
|
30
|
-
|
|
30
|
+
const executeOnce = async (taskDescription, assignment) => {
|
|
31
31
|
const taskId = assignment.taskId;
|
|
32
32
|
const sessionKey = getSessionKey(assignment);
|
|
33
33
|
const idempotencyKey = getIdempotencyKey?.(assignment);
|
|
@@ -538,6 +538,32 @@ export function createRoleTaskExecutor(deps) {
|
|
|
538
538
|
throw err;
|
|
539
539
|
}
|
|
540
540
|
};
|
|
541
|
+
// #5641 (user report 2026-11-15): the openclaw host's workspace-state guard
|
|
542
|
+
// THROWS BY CONTRACT ("retry workspace setup") when the shared workspace
|
|
543
|
+
// changes mid-preparation - e.g. the 02:00 fullReview batch racing the
|
|
544
|
+
// sweep's own repo sync. teamclaw used to surface that error straight to a
|
|
545
|
+
// terminal task failure (architect leg died in seconds, 3 days straight).
|
|
546
|
+
// Bounded retry honoring the host's retryable contract; the inner run is
|
|
547
|
+
// idempotent via idempotencyKey.
|
|
548
|
+
const RETRYABLE_WORKSPACE_GUARD = /Workspace filesystem changed while preparing state|WorkspaceAliasRepointed/;
|
|
549
|
+
return async (taskDescription, assignment) => {
|
|
550
|
+
const MAX_ATTEMPTS = 3;
|
|
551
|
+
const BACKOFF_MS = [5_000, 15_000];
|
|
552
|
+
for (let attempt = 1;; attempt++) {
|
|
553
|
+
try {
|
|
554
|
+
return await executeOnce(taskDescription, assignment);
|
|
555
|
+
}
|
|
556
|
+
catch (err) {
|
|
557
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
558
|
+
if (attempt < MAX_ATTEMPTS && RETRYABLE_WORKSPACE_GUARD.test(msg)) {
|
|
559
|
+
logger.warn(`TeamClaw: retryable workspace-state failure (attempt ${attempt}/${MAX_ATTEMPTS}) for task ${assignment.taskId}: ${msg.slice(0, 140)}`);
|
|
560
|
+
await delay(BACKOFF_MS[attempt - 1] ?? 15_000);
|
|
561
|
+
continue;
|
|
562
|
+
}
|
|
563
|
+
throw err;
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
};
|
|
541
567
|
}
|
|
542
568
|
function formatDuration(timeoutMs) {
|
|
543
569
|
const totalSeconds = Math.ceil(timeoutMs / 1000);
|
|
@@ -917,7 +943,7 @@ function buildAssistantTurnSnapshot(text, toolCalls = []) {
|
|
|
917
943
|
backgroundPending: yielded || isBackgroundWorkPendingMessage(normalizedText),
|
|
918
944
|
};
|
|
919
945
|
}
|
|
920
|
-
function extractLastAssistantTurn(messages) {
|
|
946
|
+
export function extractLastAssistantTurn(messages) {
|
|
921
947
|
const assistantMessages = messages.filter((message) => {
|
|
922
948
|
if (!message || typeof message !== "object") {
|
|
923
949
|
return false;
|
|
@@ -950,7 +976,22 @@ function extractLastAssistantTurn(messages) {
|
|
|
950
976
|
return buildAssistantTurnSnapshot(textBlocks.join("\n"), toolCalls);
|
|
951
977
|
}
|
|
952
978
|
}
|
|
953
|
-
|
|
979
|
+
// Some transports hand the text block directly as the content object.
|
|
980
|
+
if (!!lastAssistant.content
|
|
981
|
+
&& typeof lastAssistant.content === "object"
|
|
982
|
+
&& typeof lastAssistant.content.text === "string") {
|
|
983
|
+
return buildAssistantTurnSnapshot(lastAssistant.content.text);
|
|
984
|
+
}
|
|
985
|
+
// #5704 (ggcode, 2026-11-16): no recoverable text. The legacy fallback
|
|
986
|
+
// serialized the whole message object, so an empty transport frame
|
|
987
|
+
// (content:[] plus api/provider/usage metadata) reached GitHub verbatim
|
|
988
|
+
// as the worker's "final reply" - comment bodies (ggcode #5699) and even
|
|
989
|
+
// a whole PR body (#5703). Intended text lives ONLY in content (string,
|
|
990
|
+
// text blocks, or a direct text object - all handled above); anything
|
|
991
|
+
// else is frame metadata. Return empty text: the task completes without
|
|
992
|
+
// a textual result and the write-back ladder surfaces that terminally
|
|
993
|
+
// instead of posting frame JSON.
|
|
994
|
+
return buildAssistantTurnSnapshot("");
|
|
954
995
|
}
|
|
955
996
|
function isRateLimitMessage(value) {
|
|
956
997
|
return /(rate[_ ]limit|too many requests|429\b|resource has been exhausted|tokens per day|quota|throttl)/i.test(String(value || ""));
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { sanitizeGithubWriteBody } from "./write-payload-guard.js";
|
|
1
2
|
/**
|
|
2
3
|
* Minimal GitHub REST client for TeamAuto: ETag-conditional GETs, light
|
|
3
4
|
* pagination, and the write endpoints we need. All requests ride the stored
|
|
@@ -30,7 +31,16 @@ export function createGithubClient(auth) {
|
|
|
30
31
|
if (options.body !== undefined) {
|
|
31
32
|
headers["Content-Type"] = "application/json";
|
|
32
33
|
}
|
|
33
|
-
const etagKey = options.etagKey ? `${method} ${urlPath}` : undefined;
|
|
34
|
+
const etagKey = options.etagKey && !urlPath.includes("/issues?") ? `${method} ${urlPath}` : undefined;
|
|
35
|
+
// #5706 (ggcode, 2026-11-16): the ISSUE-SCAN URL must not use conditional
|
|
36
|
+
// requests. Live evidence: the gateway process received 304 for
|
|
37
|
+
// state=open&sort=updated&since=<cursor> while the byte-identical request
|
|
38
|
+
// (same etag, same plugin token) from a shell returned 200 with 13 items -
|
|
39
|
+
// GitHub's weak-validation on since-filtered, updated-sorted lists can
|
|
40
|
+
// serve a stale 304 to the long-lived process, starving EVERY sweep to
|
|
41
|
+
// "fetched 0" (three re-opened issues starved 3h, historical cases 4h20m).
|
|
42
|
+
// The scan fetches <=50 items; 304 savings are negligible. Pulls/commits
|
|
43
|
+
// and all write paths keep their etag handling.
|
|
34
44
|
if (etagKey && options.etags?.[etagKey]) {
|
|
35
45
|
headers["If-None-Match"] = options.etags[etagKey];
|
|
36
46
|
}
|
|
@@ -47,6 +57,12 @@ export function createGithubClient(auth) {
|
|
|
47
57
|
}
|
|
48
58
|
}
|
|
49
59
|
if (response.status === 304) {
|
|
60
|
+
// #5706: a 304 on the ISSUE SCAN URL while the identical request from
|
|
61
|
+
// a shell (same etag) returns 200/12 items is the live divergence -
|
|
62
|
+
// log it loudly so the next sweep pins the layer.
|
|
63
|
+
if (urlPath.includes("/issues?")) {
|
|
64
|
+
console.warn(`[teamclaw#5706] issues scan 304: ${urlPath.slice(0, 140)}`);
|
|
65
|
+
}
|
|
50
66
|
return { status: 304, data: null, notModified: true };
|
|
51
67
|
}
|
|
52
68
|
const text = await response.text();
|
|
@@ -65,6 +81,11 @@ export function createGithubClient(auth) {
|
|
|
65
81
|
}
|
|
66
82
|
if (response.status >= 200 && response.status < 300) {
|
|
67
83
|
etagCounters.hits += 1; // #267-3: "hits" = calls that returned fresh data (non-304 successes)
|
|
84
|
+
// #5706: empty-array 200s on the scan URL are suspicious in exactly
|
|
85
|
+
// the starvation scenario - make them visible.
|
|
86
|
+
if (urlPath.includes("/issues?") && Array.isArray(data) && data.length === 0) {
|
|
87
|
+
console.warn(`[teamclaw#5706] issues scan 200-but-EMPTY: ${urlPath.slice(0, 140)}`);
|
|
88
|
+
}
|
|
68
89
|
}
|
|
69
90
|
return { status: response.status, data, notModified: false };
|
|
70
91
|
}
|
|
@@ -139,6 +160,24 @@ export function createGithubClient(auth) {
|
|
|
139
160
|
};
|
|
140
161
|
});
|
|
141
162
|
},
|
|
163
|
+
/** #5785: PRs (any state) whose head is exactly this branch - the
|
|
164
|
+
* PR-face evidence surface. The settle audit asks "did this WRITE task's
|
|
165
|
+
* PR ever come into existence", which no comment surface can answer (an
|
|
166
|
+
* issue direct-post masks the missing PR). Mirrors the sentinel's
|
|
167
|
+
* pulls?head= REST probe. */
|
|
168
|
+
async listPullsByHead(owner, repo, branch) {
|
|
169
|
+
const { data } = await request("GET", `/repos/${owner}/${repo}/pulls?head=${encodeURIComponent(`${owner}:${branch}`)}&state=all&per_page=10`);
|
|
170
|
+
if (!Array.isArray(data)) {
|
|
171
|
+
return [];
|
|
172
|
+
}
|
|
173
|
+
return data
|
|
174
|
+
.map((raw) => ({
|
|
175
|
+
number: Number(raw.number ?? 0),
|
|
176
|
+
state: String(raw.state ?? ""),
|
|
177
|
+
htmlUrl: String(raw.html_url ?? ""),
|
|
178
|
+
}))
|
|
179
|
+
.filter((p) => p.number > 0);
|
|
180
|
+
},
|
|
142
181
|
async listCommits(owner, repo, sinceSha) {
|
|
143
182
|
const suffix = sinceSha ? `?sha=${encodeURIComponent(sinceSha)}` : "?per_page=20";
|
|
144
183
|
void suffix;
|
|
@@ -162,15 +201,47 @@ export function createGithubClient(auth) {
|
|
|
162
201
|
},
|
|
163
202
|
// ---- write side (require Contents/Issues/PR write on the App) ----
|
|
164
203
|
async postIssueComment(owner, repo, issueNumber, body) {
|
|
165
|
-
|
|
204
|
+
// #5704: LLM envelope frames must never land as comment bodies.
|
|
205
|
+
const safeBody = sanitizeGithubWriteBody(body, `issue comment ${owner}/${repo}#${issueNumber}`);
|
|
206
|
+
const { data } = await request("POST", `/repos/${owner}/${repo}/issues/${issueNumber}/comments`, { body: { body: safeBody } });
|
|
166
207
|
return Number(data.id ?? 0);
|
|
167
208
|
},
|
|
168
209
|
async postPullReviewComment(owner, repo, pullNumber, body) {
|
|
169
|
-
|
|
210
|
+
// #5704: same write-channel guard on the PR review surface.
|
|
211
|
+
const safeBody = sanitizeGithubWriteBody(body, `pull review ${owner}/${repo}#${pullNumber}`);
|
|
212
|
+
await request("POST", `/repos/${owner}/${repo}/pulls/${pullNumber}/reviews`, { body: { event: "COMMENT", body: safeBody } });
|
|
213
|
+
},
|
|
214
|
+
/** #5660: normalized feedback bodies already on a PR - review bodies AND
|
|
215
|
+
* issue-style comments (a worker may post through either surface during
|
|
216
|
+
* its execution window while the write-back ladder delivers the same
|
|
217
|
+
* text moments later). Whitespace-collapsed so footer spacing cannot
|
|
218
|
+
* defeat the comparison. */
|
|
219
|
+
async getPullFeedbackBodies(owner, repo, pullNumber) {
|
|
220
|
+
const bodies = [];
|
|
221
|
+
const norm = (raw) => String(raw ?? "").replace(/\s+/g, " ").trim();
|
|
222
|
+
try {
|
|
223
|
+
const { data } = await request("GET", `/repos/${owner}/${repo}/pulls/${pullNumber}/reviews?per_page=30`);
|
|
224
|
+
if (Array.isArray(data)) {
|
|
225
|
+
for (const r of data)
|
|
226
|
+
bodies.push(norm(r.body));
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
catch { /* reviews listing failed - degrade to comments-only check */ }
|
|
230
|
+
try {
|
|
231
|
+
const { data } = await request("GET", `/repos/${owner}/${repo}/issues/${pullNumber}/comments?per_page=30`);
|
|
232
|
+
if (Array.isArray(data)) {
|
|
233
|
+
for (const c of data)
|
|
234
|
+
bodies.push(norm(c.body));
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
catch { /* comments listing failed - degrade to reviews-only check */ }
|
|
238
|
+
return bodies.filter(Boolean);
|
|
170
239
|
},
|
|
171
240
|
async createIssue(owner, repo, title, body, labels) {
|
|
241
|
+
// #5704: umbrella/section bodies get the same frame guard.
|
|
242
|
+
const safeBody = sanitizeGithubWriteBody(body, `create issue ${owner}/${repo}`);
|
|
172
243
|
const { data } = await request("POST", `/repos/${owner}/${repo}/issues`, {
|
|
173
|
-
body: { title, body, ...(labels?.length ? { labels } : {}) },
|
|
244
|
+
body: { title, body: safeBody, ...(labels?.length ? { labels } : {}) },
|
|
174
245
|
});
|
|
175
246
|
return Number(data.number ?? 0);
|
|
176
247
|
},
|
|
@@ -183,6 +254,34 @@ export function createGithubClient(auth) {
|
|
|
183
254
|
async removeIssueAssignees(owner, repo, issueNumber, assignees) {
|
|
184
255
|
await request("DELETE", `/repos/${owner}/${repo}/issues/${issueNumber}/assignees`, { body: { assignees } });
|
|
185
256
|
},
|
|
257
|
+
/** #claim-dequeue: comments on an issue since a timestamp, for the
|
|
258
|
+
* dequeue-time external-collaboration check (authors + times only). */
|
|
259
|
+
async getIssueCommentsSince(owner, repo, issueNumber, sinceIso) {
|
|
260
|
+
try {
|
|
261
|
+
const { data } = await request("GET", `/repos/${owner}/${repo}/issues/${issueNumber}/comments?since=${encodeURIComponent(sinceIso)}&per_page=20`);
|
|
262
|
+
if (!Array.isArray(data))
|
|
263
|
+
return [];
|
|
264
|
+
return data.map((c) => ({
|
|
265
|
+
user: String(c.user?.login ?? ""),
|
|
266
|
+
createdAt: String(c.created_at ?? ""),
|
|
267
|
+
body: String(c.body ?? ""),
|
|
268
|
+
})).filter((c) => c.user);
|
|
269
|
+
}
|
|
270
|
+
catch {
|
|
271
|
+
return []; // listing failed - degrade to assignee check only
|
|
272
|
+
}
|
|
273
|
+
},
|
|
274
|
+
async getIssueCommentBodies(owner, repo, issueNumber) {
|
|
275
|
+
try {
|
|
276
|
+
const { data } = await request("GET", `/repos/${owner}/${repo}/issues/${issueNumber}/comments?per_page=30`);
|
|
277
|
+
if (!Array.isArray(data))
|
|
278
|
+
return [];
|
|
279
|
+
return data.map((c) => String(c.body ?? ""));
|
|
280
|
+
}
|
|
281
|
+
catch {
|
|
282
|
+
return []; // listing failed - degrade to posting (duplicate risk < lost delivery)
|
|
283
|
+
}
|
|
284
|
+
},
|
|
186
285
|
/** Fresh issue state for claim-time re-checks (#268): the scan-time
|
|
187
286
|
* assignee snapshot is seconds stale by enqueue time - a human may have
|
|
188
287
|
* self-assigned in between, and claiming over a human is worse than not
|
|
@@ -205,8 +304,11 @@ export function createGithubClient(auth) {
|
|
|
205
304
|
},
|
|
206
305
|
/** Open a PR from a task worktree branch (collaboration contract delivery). */
|
|
207
306
|
async createPullRequest(owner, repo, head, base, title, body) {
|
|
307
|
+
// #5704 case 3: a bare frame as the whole PR body consumed the deliverable
|
|
308
|
+
// surface (ggcode #5703) - guard the PR body like every other write.
|
|
309
|
+
const safeBody = sanitizeGithubWriteBody(body, `create PR ${owner}/${repo} head=${head}`);
|
|
208
310
|
const { data } = await request("POST", `/repos/${owner}/${repo}/pulls`, {
|
|
209
|
-
body: { title, head, base, body },
|
|
311
|
+
body: { title, head, base, body: safeBody },
|
|
210
312
|
});
|
|
211
313
|
const item = data;
|
|
212
314
|
return { number: Number(item.number ?? 0), url: String(item.html_url ?? "") };
|