@teamclaws/teamclaw 2026.11.5 → 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.
Files changed (47) hide show
  1. package/dist/src/controller/config-routes.js +7 -3
  2. package/dist/src/controller/controller-service.js +12 -1
  3. package/dist/src/controller/provisioning/container-shared.js +6 -1
  4. package/dist/src/controller/provisioning/docker.js +1 -1
  5. package/dist/src/controller/provisioning/kubernetes.js +1 -1
  6. package/dist/src/controller/provisioning/process-supervisor.js +12 -1
  7. package/dist/src/controller/provisioning-config.js +8 -0
  8. package/dist/src/controller/task-assignment.js +65 -2
  9. package/dist/src/controller/task-results.js +34 -3
  10. package/dist/src/controller/task-routes.js +24 -1
  11. package/dist/src/controller/worker-provisioning.js +35 -0
  12. package/dist/src/controller/worker-routes.js +21 -6
  13. package/dist/src/openclaw-workspace.js +39 -20
  14. package/dist/src/task-executor.js +44 -3
  15. package/dist/src/teamauto/github-client.js +88 -5
  16. package/dist/src/teamauto/repo-sync.js +77 -5
  17. package/dist/src/teamauto/scanner.js +22 -1
  18. package/dist/src/teamauto/scheduler.js +556 -180
  19. package/dist/src/teamauto/store.js +46 -0
  20. package/dist/src/teamauto/write-payload-guard.js +209 -0
  21. package/dist/src/types.js +6 -0
  22. package/dist/src/worker/tools.js +5 -0
  23. package/openclaw.plugin.json +1 -1
  24. package/package.json +1 -1
  25. package/src/controller/config-routes.ts +7 -3
  26. package/src/controller/controller-service.ts +12 -1
  27. package/src/controller/provisioning/backend-contract.ts +4 -0
  28. package/src/controller/provisioning/container-shared.ts +6 -1
  29. package/src/controller/provisioning/docker.ts +1 -1
  30. package/src/controller/provisioning/kubernetes.ts +1 -1
  31. package/src/controller/provisioning/process-supervisor.ts +12 -1
  32. package/src/controller/provisioning-config.ts +9 -0
  33. package/src/controller/task-assignment.ts +71 -1
  34. package/src/controller/task-results.ts +33 -3
  35. package/src/controller/task-routes.ts +25 -1
  36. package/src/controller/worker-provisioning.ts +35 -0
  37. package/src/controller/worker-routes.ts +21 -7
  38. package/src/openclaw-workspace.ts +43 -23
  39. package/src/task-executor.ts +46 -3
  40. package/src/teamauto/github-client.ts +83 -5
  41. package/src/teamauto/repo-sync.ts +75 -4
  42. package/src/teamauto/scanner.ts +23 -2
  43. package/src/teamauto/scheduler.ts +472 -103
  44. package/src/teamauto/store.ts +72 -0
  45. package/src/teamauto/write-payload-guard.ts +222 -0
  46. package/src/types.ts +21 -0
  47. package/src/worker/tools.ts +5 -0
@@ -18,6 +18,10 @@ export type TeamAutoActionPolicy = {
18
18
  prReview: boolean;
19
19
  createPR: boolean;
20
20
  fullReview: "off" | "weekly" | "daily";
21
+ /** #pr-rework: pick up fresh review activity on OUR delivered PRs and
22
+ * rework them (developer role, write mode). Default true - closing the
23
+ * loop is the expected behavior for every deployment. */
24
+ prRework?: boolean;
21
25
  };
22
26
 
23
27
  export type TeamAutoKeywordFilter = {
@@ -65,6 +69,11 @@ export type TeamAutoRepo = {
65
69
  addedAt: number;
66
70
  lastSweepAt: number;
67
71
  lastSweepSummary: string | null;
72
+ // #5641: task failures surfaced in the next sweep summary. Incremented
73
+ // whenever a write-back is dead-lettered because its task failed without
74
+ // a result; read + reset by the sweep so owners see "failed N" next to
75
+ // "created N/N" instead of a silently dying leg.
76
+ failedTasksSinceLastSweep?: number;
68
77
  pausedReason: string | null;
69
78
  /** Consecutive auto-paused sweep failures; drives retry backoff (0/undefined = healthy). */
70
79
  sweepFailures?: number;
@@ -95,6 +104,8 @@ export type TeamAutoWriteBack = {
95
104
  error: string | null;
96
105
  /** Joint full-review cycle id: same-cycle sections share one umbrella issue. */
97
106
  cycleKey?: string;
107
+ /** #5735: delivery-shape disambiguation for the ok activity line (umbrella-created vs section-appended-to-umbrella). */
108
+ deliveryNote?: string;
98
109
  /**
99
110
  * Issue #24: failed delivery attempts so far. Drives the retry backoff and
100
111
  * the terminal give-up marker instead of a sticky error that nothing ever
@@ -173,6 +184,21 @@ export type TeamAutoStore = {
173
184
  * stamp (and the bot's self-assignment) once per taskId so the next sweep
174
185
  * re-candidates naturally, while the dead-letter caps bound retries. */
175
186
  failedClaimRecovery?: Record<string, number>;
187
+ /** #5725: once-per-task guard for orphan-result alarms (completed with result, no write-back entry, no delivery line). */
188
+ orphanResultAlarms?: Record<string, number>;
189
+ /** #5736: durable delivered-ledger. doneAt write-back entries are pruned
190
+ * every pass and the activity ring is tiny - without this ledger every
191
+ * normally-delivered task re-alarms as an orphan hours later. taskId -> deliveredAt. */
192
+ deliveredResults?: Record<string, number>;
193
+ /** #5738: one-time ledger migration marker (seed from task state, pardoning pre-deploy history once). */
194
+ deliveredResultsInit?: boolean;
195
+ /** #5685 (ggcode, 2026-11-16): "repoId|cycleKey" -> umbrella issue number
196
+ * for joint full reviews. Done write-back entries are pruned at end-of-pass,
197
+ * so an in-store peer scan cannot carry the umbrella pointer across passes
198
+ * (or restarts) and same-cycle sections each minted a duplicate umbrella
199
+ * (live: cycle 20772 -> ggcode issues #5686/#5687/#5688, zero section
200
+ * comments). Bounded to the newest 100 cycles. */
201
+ fullReviewUmbrellas?: Record<string, number>;
176
202
  };
177
203
 
178
204
  export function defaultPolicy(): TeamAutoRepoPolicy {
@@ -197,6 +223,9 @@ function emptyStore(): TeamAutoStore {
197
223
  writebacks: [],
198
224
  activity: [],
199
225
  failedClaimRecovery: {},
226
+ orphanResultAlarms: {},
227
+ deliveredResults: {},
228
+ fullReviewUmbrellas: {},
200
229
  budget: {
201
230
  maxTasksPerDay: 150,
202
231
  firstSweepDryRun: true,
@@ -258,6 +287,28 @@ export async function loadTeamAutoStore(): Promise<TeamAutoStore> {
258
287
  if (parsed.failedClaimRecovery && typeof parsed.failedClaimRecovery === "object") {
259
288
  store.failedClaimRecovery = parsed.failedClaimRecovery as Record<string, number>;
260
289
  }
290
+ if (parsed.fullReviewUmbrellas && typeof parsed.fullReviewUmbrellas === "object") {
291
+ store.fullReviewUmbrellas = parsed.fullReviewUmbrellas as Record<string, number>;
292
+ }
293
+ // #5736 (ggcode): the orphan-alarm chain (#5725 -> #5736 -> #5738) learned
294
+ // this the hard way three times over - loadTeamAutoStore rebuilds the store
295
+ // field-by-field, so a persistence field missing from this copy list is
296
+ // dropped on EVERY 20s settle reload even though saveTeamAutoStore writes
297
+ // it to disk. With all three alarm fields missing, the alarm silently
298
+ // disarmed: deliveredResultsInit dropped => the one-time migration re-ran
299
+ // each pass and pardoned every completed in-window task (genuine #5725
300
+ // registration loss could never alarm again); deliveredResults dropped =>
301
+ // prune-time delivery records evaporated; orphanResultAlarms dropped =>
302
+ // the once-per-task gate reset (99 alarm lines in 80s live).
303
+ if (parsed.orphanResultAlarms && typeof parsed.orphanResultAlarms === "object") {
304
+ store.orphanResultAlarms = parsed.orphanResultAlarms as Record<string, number>;
305
+ }
306
+ if (parsed.deliveredResults && typeof parsed.deliveredResults === "object") {
307
+ store.deliveredResults = parsed.deliveredResults as Record<string, number>;
308
+ }
309
+ if (typeof parsed.deliveredResultsInit === "boolean") {
310
+ store.deliveredResultsInit = parsed.deliveredResultsInit;
311
+ }
261
312
  store.budget = { ...store.budget, ...(parsed.budget ?? {}) };
262
313
  return store;
263
314
  } catch {
@@ -265,6 +316,27 @@ export async function loadTeamAutoStore(): Promise<TeamAutoStore> {
265
316
  }
266
317
  }
267
318
 
319
+ /** #5677 (ggcode, 2026-11-15): store-level async mutex. The 20s write-back
320
+ * reconcile re-reads the store from disk and saves the whole object; the
321
+ * sweep transaction (registerWriteback + summary) does the same. Without
322
+ * serialization their read-modify-write cycles interleave: reconcile reads
323
+ * BEFORE the sweep's entry save, then its tail-save clobbers the entry the
324
+ * sweep just persisted (live: b3f688c6/#5676 write-back vanished; 3 earlier
325
+ * legs survived by timing luck). Every load→mutate→save section must hold
326
+ * this lock; it is process-local (single controller per state dir). */
327
+ const storeLock: { tail: Promise<void> } = { tail: Promise.resolve() };
328
+ export async function withStoreLock<T>(section: () => Promise<T>): Promise<T> {
329
+ const prev = storeLock.tail;
330
+ let release!: () => void;
331
+ storeLock.tail = new Promise<void>((r) => { release = r; });
332
+ await prev;
333
+ try {
334
+ return await section();
335
+ } finally {
336
+ release();
337
+ }
338
+ }
339
+
268
340
  export async function saveTeamAutoStore(store: TeamAutoStore): Promise<void> {
269
341
  const { storeFile } = resolveTeamAutoPaths();
270
342
  await fs.mkdir(path.dirname(storeFile), { recursive: true });
@@ -0,0 +1,222 @@
1
+ /**
2
+ * #5704 (ggcode, 2026-11-16): LLM envelope/frame leakage into GitHub write
3
+ * surfaces. Three documented cases - a raw transport frame posted verbatim as
4
+ * an issue comment (#5699), a write timeout with nothing landed (#5687), and
5
+ * a PR body that was nothing but the frame JSON (#5703, PR<->issue linkage
6
+ * survived only via title). The frame shape:
7
+ *
8
+ * {"role":"assistant","content":[],"api":"openai-completions","provider":"zai",
9
+ * "model":"glm-5.3","usage":{...},"usageReport":{...},"contextUsage":{...}}
10
+ *
11
+ * reached GitHub because the reply-extraction fallback serialized the whole
12
+ * message object as prose (fixed at the extraction site in task-executor.ts),
13
+ * and nothing between task.result and the REST call ever asked "is this
14
+ * intended text?". This module is the write-channel half of the fix: every
15
+ * GitHub write body funnels through sanitizeGithubWriteBody - ordinary text
16
+ * passes through untouched, a frame with recoverable content is repaired to
17
+ * that content, a frame without recoverable content is rejected loudly
18
+ * (EnvelopeLeakError) so the write-back ladder fails terminally instead of
19
+ * retrying deterministic corruption or posting frame JSON.
20
+ */
21
+
22
+ /** Error-message prefix the write-back ladder keys terminal classification on. */
23
+ export const ENVELOPE_LEAK_MARKER = "[envelope-leak]";
24
+
25
+ export class EnvelopeLeakError extends Error {
26
+ constructor(message: string) {
27
+ super(ENVELOPE_LEAK_MARKER + " " + message);
28
+ this.name = "EnvelopeLeakError";
29
+ }
30
+ }
31
+
32
+ /** True when the message starts with a "{" and closes a top-level object. */
33
+ function leadingJsonObject(text: string): Record<string, unknown> | null {
34
+ const trimmed = String(text ?? "").trimStart();
35
+ if (!trimmed.startsWith("{")) {
36
+ return null;
37
+ }
38
+ let depth = 0;
39
+ let inString = false;
40
+ let escaped = false;
41
+ for (let i = 0; i < trimmed.length; i++) {
42
+ const ch = trimmed[i];
43
+ if (inString) {
44
+ if (escaped) {
45
+ escaped = false;
46
+ } else if (ch === "\\") {
47
+ escaped = true;
48
+ } else if (ch === '"') {
49
+ inString = false;
50
+ }
51
+ continue;
52
+ }
53
+ if (ch === '"') {
54
+ inString = true;
55
+ } else if (ch === "{") {
56
+ depth++;
57
+ } else if (ch === "}") {
58
+ depth--;
59
+ if (depth === 0) {
60
+ try {
61
+ const parsed: unknown = JSON.parse(trimmed.slice(0, i + 1));
62
+ if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
63
+ return parsed as Record<string, unknown>;
64
+ }
65
+ return null;
66
+ } catch {
67
+ return null;
68
+ }
69
+ }
70
+ }
71
+ }
72
+ return null;
73
+ }
74
+
75
+ /**
76
+ * Frame signature: transport metadata keys that never appear in intended
77
+ * prose. role==="assistant" plus any one transport key is decisive (chat
78
+ * turns carry none of these); without the assistant role we require at
79
+ * least two transport keys AND a content field, so ordinary JSON bodies
80
+ * (result contracts, settings objects) never trip the guard.
81
+ */
82
+ export function looksLikeLlmEnvelopeFrame(value: Record<string, unknown>): boolean {
83
+ const transportKeys = ["api", "usage", "provider", "usageReport", "contextUsage"].filter(
84
+ (key) => key in value,
85
+ );
86
+ if (value.role === "assistant" && transportKeys.length >= 1) {
87
+ return true;
88
+ }
89
+ return transportKeys.length >= 2 && "content" in value;
90
+ }
91
+
92
+ /** Recover intended text from a frame's content field (string or text blocks). */
93
+ export function envelopeFrameContentText(frame: Record<string, unknown>): string | null {
94
+ const content: unknown = frame.content;
95
+ if (typeof content === "string") {
96
+ return content.trim() ? content : null;
97
+ }
98
+ if (Array.isArray(content)) {
99
+ const text = content
100
+ .filter(
101
+ (block): block is { type?: unknown; text?: unknown } =>
102
+ !!block && typeof block === "object" && (block as { type?: unknown }).type === "text",
103
+ )
104
+ .map((block) => (typeof block.text === "string" ? block.text : ""))
105
+ .filter(Boolean)
106
+ .join("\n")
107
+ .trim();
108
+ return text ? text : null;
109
+ }
110
+ return null;
111
+ }
112
+
113
+ /**
114
+ * Split a write payload into (frame?, recoverable text?).
115
+ * Returns false when the body is not a frame (ordinary text - pass through),
116
+ * null when it is a frame with no recoverable text (reject), and the
117
+ * recovered string when the frame carries content (repair). The scan reads
118
+ * only the LEADING object, so our own marker footer appended after the frame
119
+ * does not defeat detection, and prose that merely MENTIONS frame keys in
120
+ * backticks (audit reports like the #5704 watchdog sweep) passes untouched.
121
+ */
122
+ export function splitLlmEnvelopeFrame(body: string): string | null | false {
123
+ const frame = leadingJsonObject(body);
124
+ if (!frame || !looksLikeLlmEnvelopeFrame(frame)) {
125
+ return false;
126
+ }
127
+ return envelopeFrameContentText(frame);
128
+ }
129
+
130
+ /** A whole body line that is exactly one frame object (umbrella section
131
+ * bodies embed task.result as a block between the section header and the
132
+ * marker footer, so the leading-object scan alone cannot see them). */
133
+ function parseStandaloneFrameLine(line: string): Record<string, unknown> | null {
134
+ const trimmed = line.trim();
135
+ if (!trimmed.startsWith("{") || !trimmed.endsWith("}")) {
136
+ return null;
137
+ }
138
+ try {
139
+ const parsed: unknown = JSON.parse(trimmed);
140
+ if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
141
+ const frame = parsed as Record<string, unknown>;
142
+ return looksLikeLlmEnvelopeFrame(frame) ? frame : null;
143
+ }
144
+ } catch {
145
+ /* not JSON - ordinary prose line */
146
+ }
147
+ return null;
148
+ }
149
+
150
+ /** Structural chrome around a deliverable: section headers, marker footers
151
+ * (the live footer shape is a bare "---" line followed by a
152
+ * "[teamclaw:<role>] autonomous via TeamClaw" line). */
153
+ function isNonSubstantiveLine(line: string): boolean {
154
+ const trimmed = line.trim();
155
+ if (!trimmed) {
156
+ return true;
157
+ }
158
+ if (trimmed.startsWith("#")) {
159
+ return true;
160
+ }
161
+ if (trimmed === "---" || trimmed === "***") {
162
+ return true;
163
+ }
164
+ if (/^\[teamclaw:/.test(trimmed)) {
165
+ return true;
166
+ }
167
+ return false;
168
+ }
169
+
170
+ /**
171
+ * Write-channel validator (#5704). Apply to every body GitHub-bound write
172
+ * sends. Ordinary text (including JSON that is not a transport frame) is
173
+ * returned unchanged; frames are repaired or rejected.
174
+ *
175
+ * Two detection shapes:
176
+ * 1. the payload IS a frame (with our footer possibly appended) - repair to
177
+ * the recovered content text, or reject when none exists;
178
+ * 2. the payload EMBEDS standalone frame lines (umbrella section bodies) -
179
+ * each is replaced by its recovered text (dropped when textless), and the
180
+ * write is rejected when nothing substantive remains besides chrome.
181
+ */
182
+ export function sanitizeGithubWriteBody(body: string, context: string): string {
183
+ const outcome = splitLlmEnvelopeFrame(body);
184
+ if (typeof outcome === "string") {
185
+ return outcome;
186
+ }
187
+ if (outcome === null) {
188
+ throw new EnvelopeLeakError(
189
+ context +
190
+ ": payload is a raw LLM transport envelope frame with no recoverable content text - write rejected (#5704)",
191
+ );
192
+ }
193
+
194
+ const lines = String(body ?? "").split("\n");
195
+ const mapped: string[] = [];
196
+ let touched = false;
197
+ let recoveredAny = false;
198
+ for (const line of lines) {
199
+ const frame = parseStandaloneFrameLine(line);
200
+ if (frame) {
201
+ touched = true;
202
+ const recovered = envelopeFrameContentText(frame);
203
+ if (recovered) {
204
+ recoveredAny = true;
205
+ mapped.push(recovered);
206
+ }
207
+ continue;
208
+ }
209
+ mapped.push(line);
210
+ }
211
+ if (!touched) {
212
+ return body;
213
+ }
214
+ const substantive = mapped.filter((line) => !isNonSubstantiveLine(line));
215
+ if (!recoveredAny && substantive.length === 0) {
216
+ throw new EnvelopeLeakError(
217
+ context +
218
+ ": payload embeds only LLM transport envelope frame lines with no recoverable text - write rejected (#5704)",
219
+ );
220
+ }
221
+ return mapped.join("\n");
222
+ }
package/src/types.ts CHANGED
@@ -158,6 +158,16 @@ export type TaskInfo = {
158
158
  /** Surviving progress snapshot for interrupted executions (resume support). */
159
159
  checkpoint?: TaskCheckpoint;
160
160
  resumeAttempt?: number;
161
+ /**
162
+ * #5740 (ggcode, 2026-11-17): assignment backoff after a claim-at-dequeue
163
+ * ELIGIBILITY-CHECK failure reverted a dispatched assignment. While
164
+ * assignmentHoldUntil is in the future, the auto-assign round skips this
165
+ * pending task; assignmentHoldCount grows the hold exponentially (20s
166
+ * doubling, 160s cap) across consecutive failures and is reset by any
167
+ * conclusive claim outcome.
168
+ */
169
+ assignmentHoldUntil?: number;
170
+ assignmentHoldCount?: number;
161
171
  /**
162
172
  * Design 2.4 workflow-chain membership: set ONLY by the workflow engine
163
173
  * (controller/workflow-routes.ts) when it creates a step task, never by
@@ -614,6 +624,11 @@ export type PluginConfig = {
614
624
  workerProvisioningControllerUrl: string;
615
625
  workerProvisioningRoles: RoleId[];
616
626
  workerProvisioningMinPerRole: number;
627
+ /** #rate-limit-999: provider rate-limit retries for provisioned workers
628
+ * (passed through to every provisioner backend and written into the
629
+ * worker's settings.json). teamclaw workloads are long-running and
630
+ * unattended - the host default of 9 abandons tasks nobody watches. */
631
+ workerRateLimitMaxRetries: number;
617
632
  workerProvisioningMaxPerRole: number;
618
633
  workerProvisioningIdleTtlMs: number;
619
634
  workerProvisioningStartupTimeoutMs: number;
@@ -958,6 +973,11 @@ export function parsePluginConfig(raw: Record<string, unknown> = {}): PluginConf
958
973
  ? Math.floor(raw.workerProvisioningMaxPerRole)
959
974
  : 3;
960
975
  const workerProvisioningMaxPerRole = Math.max(rawProvisioningMaxPerRole, workerProvisioningMinPerRole);
976
+ const workerRateLimitMaxRetries = typeof raw.workerRateLimitMaxRetries === "number" && raw.workerRateLimitMaxRetries >= 0
977
+ ? Math.floor(raw.workerRateLimitMaxRetries)
978
+ : 999; // #retry-999: operators WANT persistent retries (999); the host-side
979
+ // hard ceiling that clamped everything to 9 is exempted for explicit
980
+ // budgets (see openclaw failover-retry-controller #retry-999).
961
981
  const workerProvisioningIdleTtlMs = typeof raw.workerProvisioningIdleTtlMs === "number" && raw.workerProvisioningIdleTtlMs >= 1000
962
982
  ? raw.workerProvisioningIdleTtlMs
963
983
  : 120_000;
@@ -1050,6 +1070,7 @@ export function parsePluginConfig(raw: Record<string, unknown> = {}): PluginConf
1050
1070
  workerProvisioningMinPerRole,
1051
1071
  workerProvisioningMaxPerRole,
1052
1072
  workerProvisioningIdleTtlMs,
1073
+ workerRateLimitMaxRetries,
1053
1074
  workerProvisioningStartupTimeoutMs,
1054
1075
  workerProvisioningImage,
1055
1076
  workerProvisioningPassEnv,
@@ -587,6 +587,11 @@ export function createWorkerTools(deps: WorkerToolsDeps) {
587
587
  if (status) {
588
588
  patch.status = status;
589
589
  }
590
+ // #5740 (ggcode): identify the reporting worker so the controller
591
+ // can apply the same stale-worker guard as the result routes.
592
+ if (typeof identity.workerId === "string" && identity.workerId) {
593
+ patch.workerId = identity.workerId;
594
+ }
590
595
  if (progressContract) {
591
596
  patch.progressContract = progressContract;
592
597
  }