@teamclaws/teamclaw 2026.11.4 → 2026.11.6
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/config-routes.js +7 -3
- package/dist/src/controller/controller-service.js +12 -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 +12 -1
- package/dist/src/controller/provisioning-config.js +8 -0
- package/dist/src/controller/task-assignment.js +65 -2
- package/dist/src/controller/task-results.js +34 -3
- package/dist/src/controller/task-routes.js +24 -1
- package/dist/src/controller/worker-provisioning.js +35 -0
- package/dist/src/controller/worker-routes.js +21 -6
- package/dist/src/openclaw-workspace.js +39 -20
- package/dist/src/task-executor.js +44 -3
- package/dist/src/teamauto/github-client.js +88 -5
- package/dist/src/teamauto/repo-sync.js +90 -5
- package/dist/src/teamauto/scanner.js +22 -1
- package/dist/src/teamauto/scheduler.js +587 -182
- package/dist/src/teamauto/store.js +46 -0
- package/dist/src/teamauto/write-payload-guard.js +209 -0
- package/dist/src/types.js +6 -0
- package/dist/src/worker/tools.js +5 -0
- package/openclaw.plugin.json +1 -1
- package/package.json +1 -1
- package/src/controller/config-routes.ts +7 -3
- package/src/controller/controller-service.ts +12 -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 +12 -1
- package/src/controller/provisioning-config.ts +9 -0
- package/src/controller/task-assignment.ts +71 -1
- package/src/controller/task-results.ts +33 -3
- package/src/controller/task-routes.ts +25 -1
- package/src/controller/worker-provisioning.ts +35 -0
- package/src/controller/worker-routes.ts +21 -7
- package/src/openclaw-workspace.ts +43 -23
- package/src/task-executor.ts +46 -3
- package/src/teamauto/github-client.ts +83 -5
- package/src/teamauto/repo-sync.ts +100 -4
- package/src/teamauto/scanner.ts +23 -2
- package/src/teamauto/scheduler.ts +503 -106
- package/src/teamauto/store.ts +72 -0
- package/src/teamauto/write-payload-guard.ts +222 -0
- package/src/types.ts +21 -0
- package/src/worker/tools.ts +5 -0
|
@@ -46,7 +46,10 @@ function teamConfigGetRoute(ctx) {
|
|
|
46
46
|
workerProvisioningMaxPerRole: c.workerProvisioningMaxPerRole,
|
|
47
47
|
workerProvisioningIdleTtlMs: c.workerProvisioningIdleTtlMs,
|
|
48
48
|
// k8s controllers run on ephemeral container FS: declare it up front.
|
|
49
|
-
|
|
49
|
+
// #hot-reload: persistence is PLUGIN-STATE (beside team-state.json), not
|
|
50
|
+
// host config - a host-config write made the host reload the whole
|
|
51
|
+
// plugin on every PATCH (see openclaw-workspace.ts #hot-reload note).
|
|
52
|
+
persistenceMode: "plugin-state",
|
|
50
53
|
});
|
|
51
54
|
}
|
|
52
55
|
async function teamConfigPatchRoute(ctx) {
|
|
@@ -97,8 +100,9 @@ async function teamConfigPatchRoute(ctx) {
|
|
|
97
100
|
deps.config.workerProvisioningMaxPerRole = minR;
|
|
98
101
|
applied.workerProvisioningMaxPerRole = minR;
|
|
99
102
|
}
|
|
100
|
-
// 2) Persist
|
|
101
|
-
//
|
|
103
|
+
// 2) Persist to PLUGIN STATE (never the host config - see
|
|
104
|
+
// openclaw-workspace.ts #hot-reload: host writes triggered full plugin
|
|
105
|
+
// reloads that killed in-flight work and usually failed to apply).
|
|
102
106
|
const memoryOnly = deps.config.workerProvisioningType === "kubernetes";
|
|
103
107
|
let persisted = false;
|
|
104
108
|
if (!memoryOnly) {
|
|
@@ -15,7 +15,7 @@ import { resumeTeamProfileSwitch } from "./profile-switch.js";
|
|
|
15
15
|
import { TaskRouter } from "./task-router.js";
|
|
16
16
|
import { MessageRouter } from "./message-router.js";
|
|
17
17
|
import { TeamWebSocketServer } from "./websocket.js";
|
|
18
|
-
import { ensureOpenClawWorkspaceMemoryDir, buildTeamClawAgentSessionKey } from "../openclaw-workspace.js";
|
|
18
|
+
import { ensureOpenClawWorkspaceMemoryDir, buildTeamClawAgentSessionKey, loadProvisioningHotConfig } from "../openclaw-workspace.js";
|
|
19
19
|
import { ensureControllerGitRepo } from "../git-collaboration.js";
|
|
20
20
|
import { WorkerProvisioningManager } from "./worker-provisioning.js";
|
|
21
21
|
import { PreviewManager } from "./preview-manager.js";
|
|
@@ -51,6 +51,17 @@ export function createControllerService(deps) {
|
|
|
51
51
|
async start(_ctx) {
|
|
52
52
|
const serviceStartedAt = Date.now();
|
|
53
53
|
await ensureOpenClawWorkspaceMemoryDir(logger);
|
|
54
|
+
// #hot-reload: re-apply the persisted hot-config overrides (provisioning
|
|
55
|
+
// caps) from PLUGIN STATE - they intentionally live outside the host
|
|
56
|
+
// config so a PATCH never triggers a plugin reload (see
|
|
57
|
+
// openclaw-workspace.ts #hot-reload for the failure mode this replaces).
|
|
58
|
+
const hotOverrides = await loadProvisioningHotConfig();
|
|
59
|
+
if (hotOverrides) {
|
|
60
|
+
for (const [key, value] of Object.entries(hotOverrides)) {
|
|
61
|
+
config[key] = value;
|
|
62
|
+
}
|
|
63
|
+
logger.info(`Controller: provisioning hot-config re-applied from plugin state: ${JSON.stringify(hotOverrides)}`);
|
|
64
|
+
}
|
|
54
65
|
// Load or create team state. The active profile is resolved FIRST (from
|
|
55
66
|
// the restored TeamState.profileId, or the config bootstrap value on
|
|
56
67
|
// first initialization) so that capability-dependent startup wiring
|
|
@@ -40,7 +40,7 @@ function sanitizeTrailingSegment(value, maxLength, fallback) {
|
|
|
40
40
|
const normalized = sanitizePathSegment(value).slice(-maxLength).replace(/^-+|-+$/g, "");
|
|
41
41
|
return normalized || fallback;
|
|
42
42
|
}
|
|
43
|
-
export function buildContainerBootstrapScript() {
|
|
43
|
+
export function buildContainerBootstrapScript(rateLimitMaxRetries) {
|
|
44
44
|
return [
|
|
45
45
|
"set -eu",
|
|
46
46
|
"mkdir -p \"$OPENCLAW_STATE_DIR\"",
|
|
@@ -59,6 +59,11 @@ export function buildContainerBootstrapScript() {
|
|
|
59
59
|
// creates it owner-only). Chosen over unlink-then-write to avoid the
|
|
60
60
|
// no-config window mid-rewrite.
|
|
61
61
|
"node -e 'const fs=require(\"fs\"); const configPath=process.env.OPENCLAW_CONFIG_PATH; const raw=Buffer.from(process.env.TEAMCLAW_BOOTSTRAP_CONFIG_B64||\"\", \"base64\").toString(\"utf8\"); fs.mkdirSync(require(\"path\").dirname(configPath), { recursive: true }); try { fs.chmodSync(configPath, 0o600); } catch (err) { if (err.code !== \"ENOENT\") throw err; } fs.writeFileSync(configPath, raw, { mode: 0o600 });'",
|
|
62
|
+
// #rate-limit-999 (v2): openclaw reads retry settings from its AGENT scope
|
|
63
|
+
// <stateDir>/agents/teamclaw/agent/settings.json (settings-manager:
|
|
64
|
+
// join(agentDir, "settings.json")), NOT from the state dir root. Write the
|
|
65
|
+
// real layer first, plus the legacy root copy for other layouts.
|
|
66
|
+
`node -e 'const fs=require("fs"); const p=require("path"); const sd=p.dirname(process.env.OPENCLAW_CONFIG_PATH); const ad=p.join(sd, "agents", "teamclaw", "agent"); fs.mkdirSync(ad, { recursive: true }); fs.writeFileSync(p.join(ad, "settings.json"), JSON.stringify({retry:{enabled:true,provider:{maxRetries:${rateLimitMaxRetries}}}}, null, 2)+"\\n", { mode: 0o600 }); fs.writeFileSync(p.join(sd, "settings.json"), JSON.stringify({retry:{enabled:true,provider:{maxRetries:${rateLimitMaxRetries}}}}, null, 2)+"\\n", { mode: 0o600 });'`,
|
|
62
67
|
"exec node dist/index.js gateway --allow-unconfigured",
|
|
63
68
|
].join("\n");
|
|
64
69
|
}
|
|
@@ -59,7 +59,7 @@ export class DockerProvisioner {
|
|
|
59
59
|
}
|
|
60
60
|
const containerConfig = {
|
|
61
61
|
Image: this.config.workerProvisioningImage,
|
|
62
|
-
Cmd: ["sh", "-lc", buildContainerBootstrapScript()],
|
|
62
|
+
Cmd: ["sh", "-lc", buildContainerBootstrapScript(spec.rateLimitMaxRetries)],
|
|
63
63
|
Env: Object.entries(env).map(([key, value]) => `${key}=${value}`),
|
|
64
64
|
User: "root",
|
|
65
65
|
Labels: {
|
|
@@ -179,7 +179,7 @@ export class KubernetesProvisioner {
|
|
|
179
179
|
name: "worker",
|
|
180
180
|
image: this.config.workerProvisioningImage,
|
|
181
181
|
command: ["sh", "-lc"],
|
|
182
|
-
args: [buildContainerBootstrapScript()],
|
|
182
|
+
args: [buildContainerBootstrapScript(spec.rateLimitMaxRetries)],
|
|
183
183
|
env: Object.entries(env).map(([name, value]) => ({ name, value })),
|
|
184
184
|
volumeMounts: hasPersistentWorkspace
|
|
185
185
|
? [
|
|
@@ -8,7 +8,7 @@ import fs from "node:fs/promises";
|
|
|
8
8
|
import path from "node:path";
|
|
9
9
|
import readline from "node:readline";
|
|
10
10
|
import { spawn } from "node:child_process";
|
|
11
|
-
import { resolveControllerTeamclawEntryPath } from "../provisioning-config.js";
|
|
11
|
+
import { resolveControllerTeamclawEntryPath, workerRetrySettingsJson } from "../provisioning-config.js";
|
|
12
12
|
import { resolveDefaultOpenClawConfigPath, resolveDefaultTeamClawRuntimeRootDir, } from "../../openclaw-workspace.js";
|
|
13
13
|
import { pathExists, sanitizePathSegment } from "../../shared/utils.js";
|
|
14
14
|
import { copyControllerAuthProfiles } from "../provisioning-config.js";
|
|
@@ -73,6 +73,17 @@ export class ProcessProvisioner {
|
|
|
73
73
|
throw err;
|
|
74
74
|
});
|
|
75
75
|
await fs.writeFile(configPath, spec.configJson, { encoding: "utf8", mode: 0o600 });
|
|
76
|
+
// #rate-limit-999 (v2, user report 2026-11-14 night: retries STILL stopped
|
|
77
|
+
// at 9): openclaw does NOT read stateDir/settings.json - its global scope
|
|
78
|
+
// is <stateDir>/agents/<agentId>/agent/settings.json (verified live:
|
|
79
|
+
// agents/teamclaw/agent/ exists in every provisioned worker; settings-
|
|
80
|
+
// manager reads join(agentDir, "settings.json")). The agent id for our
|
|
81
|
+
// workers is deterministic ("teamclaw"). Write BOTH layers: the real one
|
|
82
|
+
// plus the legacy stateDir copy (harmless; future-proofs other layouts).
|
|
83
|
+
const workerAgentSettingsDir = path.join(stateDir, "agents", "teamclaw", "agent");
|
|
84
|
+
await fs.mkdir(workerAgentSettingsDir, { recursive: true }).catch(() => { });
|
|
85
|
+
await fs.writeFile(path.join(workerAgentSettingsDir, "settings.json"), workerRetrySettingsJson(spec.rateLimitMaxRetries), { encoding: "utf8", mode: 0o600 }).catch(() => { });
|
|
86
|
+
await fs.writeFile(path.join(stateDir, "settings.json"), workerRetrySettingsJson(spec.rateLimitMaxRetries), { encoding: "utf8", mode: 0o600 }).catch(() => { });
|
|
76
87
|
// #task-stuck (13th layer, physical half): the worker sandbox has no
|
|
77
88
|
// teamclaw installation of its own, and entries.enabled does not resolve
|
|
78
89
|
// the plugin. Symlink the controller's teamclaw package into the
|
|
@@ -181,6 +181,14 @@ export function buildProvisionedWorkerConfig(baseConfig, controllerConfig, spec)
|
|
|
181
181
|
config.plugins = plugins;
|
|
182
182
|
return config;
|
|
183
183
|
}
|
|
184
|
+
/** #rate-limit-999: settings.json content (global settings scope for a
|
|
185
|
+
* worker instance home) raising provider rate-limit retries. Shared by the
|
|
186
|
+
* process backend's file write; docker/kubernetes mirror it in the bootstrap
|
|
187
|
+
* script with the same value baked in from the plugin config. */
|
|
188
|
+
export const TEAMCLAW_RATE_LIMIT_MAX_RETRIES_DEFAULT = 999;
|
|
189
|
+
export function workerRetrySettingsJson(maxRetries) {
|
|
190
|
+
return JSON.stringify({ retry: { enabled: true, provider: { maxRetries } } }, null, 2) + "\n";
|
|
191
|
+
}
|
|
184
192
|
export async function loadOpenClawConfig(configPath) {
|
|
185
193
|
const raw = await fs.readFile(configPath, "utf8");
|
|
186
194
|
return parseLooseJsonObject(raw, configPath);
|
|
@@ -12,7 +12,7 @@ import { getActiveRoles, resolveActiveRoleSkills } from "../profile-loader.js";
|
|
|
12
12
|
import { buildRepoSyncInfo } from "../git-collaboration.js";
|
|
13
13
|
import { buildTeamClawProjectWorkspacePath, resolveTeamClawProjectsDir, resolveTeamClawWorkspaceDir, } from "../openclaw-workspace.js";
|
|
14
14
|
import { refreshControllerRepoState } from "./repo-routes.js";
|
|
15
|
-
import { appendTaskExecutionEvent, broadcastTaskExecutionEvent, buildTaskExecutionIdentity, normalizeControllerIntakeSessionKey, recordTaskExecutionEvent, resetTaskForFreshAttempt, serializeTask, withWorkerDispatchToken, } from "./task-execution.js";
|
|
15
|
+
import { appendTaskExecutionEvent, broadcastTaskExecutionEvent, buildTaskExecutionIdentity, cancelTaskExecution, normalizeControllerIntakeSessionKey, recordTaskExecutionEvent, resetTaskForFreshAttempt, serializeTask, withWorkerDispatchToken, } from "./task-execution.js";
|
|
16
16
|
const MAX_RECENT_TASK_CONTEXT = 3;
|
|
17
17
|
const MAX_TASK_CONTEXT_SUMMARY_CHARS = 500;
|
|
18
18
|
export function summarizeTaskForAssignment(task) {
|
|
@@ -227,7 +227,7 @@ export function buildConsolidatedPatternsContext() {
|
|
|
227
227
|
return "";
|
|
228
228
|
}
|
|
229
229
|
}
|
|
230
|
-
export function revertTaskAssignment(taskId, workerId, deps) {
|
|
230
|
+
export function revertTaskAssignment(taskId, workerId, deps, options) {
|
|
231
231
|
const { updateTeamState, wsServer } = deps;
|
|
232
232
|
let revertEvent;
|
|
233
233
|
const state = updateTeamState((s) => {
|
|
@@ -238,6 +238,13 @@ export function revertTaskAssignment(taskId, workerId, deps) {
|
|
|
238
238
|
if (task.assignedWorkerId === workerId) {
|
|
239
239
|
task.status = "pending";
|
|
240
240
|
task.assignedWorkerId = undefined;
|
|
241
|
+
// #5740 (ggcode, 2026-11-17): optional assignment hold so a reverted
|
|
242
|
+
// claim-eligibility retry does not immediately re-dispatch (outage
|
|
243
|
+
// churn); the heartbeat-driven auto-assign passes retry after expiry.
|
|
244
|
+
if (options?.holdMs && options.holdMs > 0) {
|
|
245
|
+
task.assignmentHoldCount = (task.assignmentHoldCount ?? 0) + 1;
|
|
246
|
+
task.assignmentHoldUntil = Date.now() + options.holdMs;
|
|
247
|
+
}
|
|
241
248
|
task.updatedAt = Date.now();
|
|
242
249
|
revertEvent = appendTaskExecutionEvent(task, {
|
|
243
250
|
type: "error",
|
|
@@ -267,6 +274,27 @@ export function revertTaskAssignment(taskId, workerId, deps) {
|
|
|
267
274
|
}
|
|
268
275
|
return updatedTask;
|
|
269
276
|
}
|
|
277
|
+
/** #5740 (ggcode): assignment hold after a reverted claim-eligibility check -
|
|
278
|
+
* 20s doubling per consecutive failure, capped at 160s, so a network blip
|
|
279
|
+
* costs one ~20s wait while a sustained outage retries at a bounded cadence
|
|
280
|
+
* instead of assign/cancel churn (and never bypasses the conflict gate). */
|
|
281
|
+
export function claimEligibilityHoldMs(consecutiveFailures) {
|
|
282
|
+
const capped = Math.min(Math.max(consecutiveFailures, 1), 4);
|
|
283
|
+
return Math.min(20_000 * 2 ** (capped - 1), 160_000);
|
|
284
|
+
}
|
|
285
|
+
/** #5740 (ggcode): any conclusive claim outcome (claimed, stood down, or a
|
|
286
|
+
* WRITE failure that legitimately continues unclaimed) ends the retry cycle -
|
|
287
|
+
* reset the backoff so a future blip starts at the base hold again. */
|
|
288
|
+
export function clearAssignmentHold(taskId, deps) {
|
|
289
|
+
deps.updateTeamState((s) => {
|
|
290
|
+
const task = s.tasks[taskId];
|
|
291
|
+
if (task && (task.assignmentHoldUntil !== undefined || task.assignmentHoldCount !== undefined)) {
|
|
292
|
+
delete task.assignmentHoldUntil;
|
|
293
|
+
delete task.assignmentHoldCount;
|
|
294
|
+
task.updatedAt = Date.now();
|
|
295
|
+
}
|
|
296
|
+
});
|
|
297
|
+
}
|
|
270
298
|
export async function dispatchTaskToWorker(taskId, worker, deps) {
|
|
271
299
|
const { getTeamState, logger, updateTeamState } = deps;
|
|
272
300
|
const state = getTeamState();
|
|
@@ -479,6 +507,9 @@ export async function runAutoAssignRound(deps, preferredWorkerId, attemptedPairs
|
|
|
479
507
|
const candidateAssignments = (await taskRouter
|
|
480
508
|
.autoAssignPendingTasks(state.tasks, state.workers))
|
|
481
509
|
.filter(({ task, worker }) => !attemptedPairs.has(`${task.id}:${worker.id}`))
|
|
510
|
+
// #5740 (ggcode): a task reverted by a failed claim-eligibility check
|
|
511
|
+
// sits out its exponential assignment hold before re-entering candidacy.
|
|
512
|
+
.filter(({ task }) => !(typeof task.assignmentHoldUntil === "number" && task.assignmentHoldUntil > Date.now()))
|
|
482
513
|
.filter(({ task }) => {
|
|
483
514
|
const root = taskWriteRoot(task);
|
|
484
515
|
return !(root && busyWriteRoots.has(root));
|
|
@@ -499,6 +530,38 @@ export async function runAutoAssignRound(deps, preferredWorkerId, attemptedPairs
|
|
|
499
530
|
assignedRole: nextAssignment.task.assignedRole,
|
|
500
531
|
});
|
|
501
532
|
if (updatedTask?.status === "assigned" && updatedTask.assignedWorkerId === nextAssignment.worker.id) {
|
|
533
|
+
// #claim-dequeue (2026-11-15): the GitHub claim happens HERE, at
|
|
534
|
+
// dequeue - after the fresh conflict check (assignees / external
|
|
535
|
+
// comments since enqueue) inside claimTaskAtDequeue. Non-takeOwnership
|
|
536
|
+
// tasks are a no-op there.
|
|
537
|
+
// #5740 (ggcode, 2026-11-17): an ELIGIBILITY-CHECK failure (network)
|
|
538
|
+
// must revert the assignment - the conflict gate never ran, so the
|
|
539
|
+
// task may not proceed. Back to pending; the next auto-assign pass
|
|
540
|
+
// re-checks (a blip costs ~20s, an outage loops at cadence instead of
|
|
541
|
+
// bypassing the gate). Write-phase claim failures still continue
|
|
542
|
+
// unclaimed per the original 2026-11-15 semantics.
|
|
543
|
+
deps.getTeamAutoScheduler?.()?.claimTaskAtDequeue(updatedTask).then((claim) => {
|
|
544
|
+
if (claim?.retryEligibility) {
|
|
545
|
+
logger.warn(`Controller: claim eligibility check failed for ${updatedTask.id} - reverting assignment to retry`);
|
|
546
|
+
// Unlike the #191 dispatch-failure path, the dispatch SUCCEEDED
|
|
547
|
+
// here: cancel the already-dispatched execution before reverting
|
|
548
|
+
// so the orphaned run cannot keep executing (and PATCH the task
|
|
549
|
+
// back to in_progress) while the controller re-queues it. The
|
|
550
|
+
// exponential assignment hold bounds the outage retry cadence.
|
|
551
|
+
void (async () => {
|
|
552
|
+
await cancelTaskExecution(updatedTask.id, nextAssignment.worker.id, "claim eligibility retry (#5740)", deps);
|
|
553
|
+
const failures = (deps.getTeamState()?.tasks[updatedTask.id]?.assignmentHoldCount ?? 0) + 1;
|
|
554
|
+
revertTaskAssignment(updatedTask.id, nextAssignment.worker.id, deps, {
|
|
555
|
+
holdMs: claimEligibilityHoldMs(failures),
|
|
556
|
+
});
|
|
557
|
+
})().catch(() => { });
|
|
558
|
+
}
|
|
559
|
+
else {
|
|
560
|
+
// Claim attempt concluded definitively (claimed / stood down /
|
|
561
|
+
// WRITE failure continuing unclaimed): end the retry cycle.
|
|
562
|
+
clearAssignmentHold(updatedTask.id, deps);
|
|
563
|
+
}
|
|
564
|
+
}).catch(() => { });
|
|
502
565
|
wsServer.broadcastUpdate({ type: "task:updated", data: serializeTask(updatedTask) });
|
|
503
566
|
logger.info(`Controller: auto-assigned pending task ${updatedTask.id} to ${nextAssignment.worker.id}`);
|
|
504
567
|
assignedTasks.push(updatedTask);
|
|
@@ -166,6 +166,19 @@ export function taskRequiresMeaningfulProjectChangeGate(task) {
|
|
|
166
166
|
if (/(审计|审核|验证|复检|复查|确认|测试|检查)/u.test(text)) {
|
|
167
167
|
return false;
|
|
168
168
|
}
|
|
169
|
+
// #5719 (ggcode, 2026-11-16): analysis-family tasks deliver their product
|
|
170
|
+
// in the result/comment, not in files - perf forensics, research,
|
|
171
|
+
// diagnostics, triage. The write-verb regex below matches their issue
|
|
172
|
+
// CONTEXT ("fix the growth", "add instrumentation") even though the task
|
|
173
|
+
// itself only investigates; a file-change gate on them is a 100% false
|
|
174
|
+
// no-op (live: takeOwnership #5701 completed with jsonl evidence in the
|
|
175
|
+
// claim comment, gate failed it, write-back went terminal, requeue loop).
|
|
176
|
+
if (/\b(perf|profile|investigat|diagnos|research|analy[sz]|evidence|forensic|triage|observ)\b/u.test(text)) {
|
|
177
|
+
return false;
|
|
178
|
+
}
|
|
179
|
+
if (/(性能|取证|调研|分析|诊断|排查|观察)/u.test(text)) {
|
|
180
|
+
return false;
|
|
181
|
+
}
|
|
169
182
|
return /\b(implement|build|fix|rework|update|add|enhanc|deliver|write|create)\b/u.test(text);
|
|
170
183
|
}
|
|
171
184
|
export function projectHasMeaningfulDeliverableEvidence(task, contract) {
|
|
@@ -221,10 +234,22 @@ export function projectHasMeaningfulFileChanges(task, contract) {
|
|
|
221
234
|
// Collaboration contract: write tasks deliver in a dedicated worktree.
|
|
222
235
|
// An mtime scan is the wrong test there (committed files keep old mtimes
|
|
223
236
|
// and the gate may run before the flush) - ask git instead: does HEAD carry
|
|
224
|
-
// commits beyond the
|
|
237
|
+
// commits beyond the task's BASE branch?
|
|
225
238
|
if (task.projectDir.includes("__task-")) {
|
|
239
|
+
// #5654 (ggcode, 2026-11-15): the old probe counted UNPUSHED commits
|
|
240
|
+
// (`HEAD --not --remotes`). A worker that pushes its branch BEFORE
|
|
241
|
+
// submitting - the encouraged flow since the #5651 rebase-delivery path -
|
|
242
|
+
// always drained to 0 and got rejected as a no-op (live d4ddd1bd:
|
|
243
|
+
// delivered + pushed a3638d1da, gate said 0, task failed + issue
|
|
244
|
+
// reopened). Substantive means HEAD carries commits beyond the BASE
|
|
245
|
+
// branch (origin/<default>), whether or not they were already pushed.
|
|
246
|
+
let base = "origin/main";
|
|
247
|
+
try {
|
|
248
|
+
base = execFileSync("git", ["symbolic-ref", "--short", "refs/remotes/origin/HEAD"], { cwd: projectRoot }).toString().trim() || base;
|
|
249
|
+
}
|
|
250
|
+
catch { /* no origin/HEAD - conventional fallback above */ }
|
|
226
251
|
try {
|
|
227
|
-
const out = execFileSync("git", ["rev-list", "--count", "HEAD", "--not",
|
|
252
|
+
const out = execFileSync("git", ["rev-list", "--count", "HEAD", "--not", base], { cwd: projectRoot }).toString();
|
|
228
253
|
return Number(out.trim()) > 0;
|
|
229
254
|
}
|
|
230
255
|
catch {
|
|
@@ -285,9 +310,15 @@ export function allowsNoChangeCompletion(task, contract, resultText) {
|
|
|
285
310
|
|| /\b(go test|go vet|npm test|pnpm test|yarn test|pytest|cargo test|verified|verification|passes|all tests pass|no remaining)\b/u.test(evidenceText);
|
|
286
311
|
const noChangeIsExpected = /\b(qa|audit|review|verify|verification|validate|test|retest|confirm|check)\b/u.test(taskText)
|
|
287
312
|
|| /(审计|审核|验证|复检|复查|确认|测试|检查)/u.test(taskText)
|
|
313
|
+
// #5719: analysis-family work products live in the result itself.
|
|
314
|
+
|| /\b(perf|profile|investigat|diagnos|research|analy[sz]|evidence|forensic|triage|observ)\b/u.test(taskText)
|
|
315
|
+
|| /(性能|取证|调研|分析|诊断|排查|观察)/u.test(taskText)
|
|
288
316
|
|| /\b(already fixed|already resolved|no further changes|no code changes|no file changes|no additional changes|verified existing fix)\b/u.test(evidenceText)
|
|
289
317
|
|| /(已修复|已解决|无需改动|无需修改|没有额外修改|无需额外变更|只需验证)/u.test(evidenceText);
|
|
290
|
-
|
|
318
|
+
// #5719: for analysis-family tasks the substantive result text IS the
|
|
319
|
+
// verification evidence (metrics, traces, conclusions).
|
|
320
|
+
const analysisFamily = /\b(perf|profile|investigat|diagnos|research|analy[sz]|evidence|forensic|triage|observ)\b/u.test(taskText) || /(性能|取证|调研|分析|诊断|排查|观察)/u.test(taskText);
|
|
321
|
+
return (hasVerificationEvidence || (analysisFamily && resultText.trim().length > 200)) && noChangeIsExpected;
|
|
291
322
|
}
|
|
292
323
|
export function applyTaskResult(taskId, result, error, deps) {
|
|
293
324
|
const { logger, updateTeamState, wsServer } = deps;
|
|
@@ -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")
|
|
@@ -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") {
|
|
@@ -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 || ""));
|