@teamclaws/teamclaw 2026.11.3 → 2026.11.4
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/teamauto/github-client.js +6 -0
- package/dist/src/teamauto/scheduler.js +76 -0
- package/dist/src/teamauto/store.js +4 -0
- package/openclaw.plugin.json +1 -1
- package/package.json +1 -1
- package/src/teamauto/github-client.ts +7 -0
- package/src/teamauto/scheduler.ts +77 -0
- package/src/teamauto/store.ts +9 -0
|
@@ -177,6 +177,12 @@ export function createGithubClient(auth) {
|
|
|
177
177
|
async assignIssue(owner, repo, issueNumber, assignee) {
|
|
178
178
|
await request("POST", `/repos/${owner}/${repo}/issues/${issueNumber}/assignees`, { body: { assignees: [assignee] } });
|
|
179
179
|
},
|
|
180
|
+
/** #claim-recovery: remove the bot's own assignment from an issue whose
|
|
181
|
+
* ownership task failed, so skipAssignedToHumans does not block the
|
|
182
|
+
* re-candidate (other human assignees are untouched). */
|
|
183
|
+
async removeIssueAssignees(owner, repo, issueNumber, assignees) {
|
|
184
|
+
await request("DELETE", `/repos/${owner}/${repo}/issues/${issueNumber}/assignees`, { body: { assignees } });
|
|
185
|
+
},
|
|
180
186
|
/** Fresh issue state for claim-time re-checks (#268): the scan-time
|
|
181
187
|
* assignee snapshot is seconds stale by enqueue time - a human may have
|
|
182
188
|
* self-assigned in between, and claiming over a human is worse than not
|
|
@@ -39,6 +39,20 @@ export const TRANSIENT_FAILURE_RE = /workspace filesystem changed|ai service nee
|
|
|
39
39
|
export function idempotencyMarker(candidate) {
|
|
40
40
|
return `Idempotency-Key: ${candidate.key}:${candidate.kind}`;
|
|
41
41
|
}
|
|
42
|
+
/** #claim-recovery: parse the marker back out of a (failed) task's
|
|
43
|
+
* description - `{ repoId, number, kind, key }` or null. Issue candidates
|
|
44
|
+
* only (PR keys `#pr-` are not claim-bearing). */
|
|
45
|
+
export function parseClaimMarker(description) {
|
|
46
|
+
const m = /Idempotency-Key: ([^:\s]+)#issue-(\d+):(\w+)/.exec(description);
|
|
47
|
+
if (!m) {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
const number = Number(m[2]);
|
|
51
|
+
if (!m[1] || !Number.isFinite(number)) {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
return { repoId: m[1], number, kind: m[3], key: `${m[1]}#issue-${number}` };
|
|
55
|
+
}
|
|
42
56
|
/** Failed task attempts for a candidate (task history is the attempt log). */
|
|
43
57
|
export function failedAttemptCount(state, candidate) {
|
|
44
58
|
const marker = idempotencyMarker(candidate);
|
|
@@ -237,6 +251,7 @@ export function createTeamAutoScheduler(deps) {
|
|
|
237
251
|
let running = false;
|
|
238
252
|
let store = null;
|
|
239
253
|
let writebackTimer = null;
|
|
254
|
+
let claimRecoveryTimer = null;
|
|
240
255
|
async function ensureStore() {
|
|
241
256
|
if (!store) {
|
|
242
257
|
store = await loadTeamAutoStore();
|
|
@@ -1017,6 +1032,60 @@ export function createTeamAutoScheduler(deps) {
|
|
|
1017
1032
|
}
|
|
1018
1033
|
})();
|
|
1019
1034
|
}
|
|
1035
|
+
/** #claim-recovery: a task that CLAIMED an issue (takeOwnership stamps the
|
|
1036
|
+
* seen cursor AND self-assigns the bot at enqueue time; issueReview stamps
|
|
1037
|
+
* the cursor) locks the issue twice against re-candidacy. When the task
|
|
1038
|
+
* fails, the issue must not be orphaned - nobody (human or bot) would ever
|
|
1039
|
+
* pick it up again. Once per failed taskId: clear the seen stamp so the
|
|
1040
|
+
* next sweep re-candidates naturally, and for takeOwnership remove the
|
|
1041
|
+
* bot's own assignment (human assignees untouched). The existing
|
|
1042
|
+
* dead-letter caps (3 hard / 6 transient) bound how often this can loop. */
|
|
1043
|
+
async function recoverFailedClaims() {
|
|
1044
|
+
const teamState = deps.getTeamState();
|
|
1045
|
+
if (!teamState) {
|
|
1046
|
+
return;
|
|
1047
|
+
}
|
|
1048
|
+
const s = await ensureStore();
|
|
1049
|
+
s.failedClaimRecovery ??= {};
|
|
1050
|
+
let changed = false;
|
|
1051
|
+
for (const [taskId, task] of Object.entries(teamState.tasks ?? {})) {
|
|
1052
|
+
if (task?.status !== "failed" || typeof task.description !== "string" || !task.description.includes("Idempotency-Key:")) {
|
|
1053
|
+
continue;
|
|
1054
|
+
}
|
|
1055
|
+
if (s.failedClaimRecovery[taskId]) {
|
|
1056
|
+
continue;
|
|
1057
|
+
}
|
|
1058
|
+
const parsed = parseClaimMarker(task.description);
|
|
1059
|
+
const repo = parsed ? s.repos.find((r) => r.id === parsed.repoId) : undefined;
|
|
1060
|
+
if (!parsed || !repo) {
|
|
1061
|
+
continue;
|
|
1062
|
+
}
|
|
1063
|
+
delete repo.cursors.seen[parsed.key];
|
|
1064
|
+
s.failedClaimRecovery[taskId] = Date.now();
|
|
1065
|
+
changed = true;
|
|
1066
|
+
recordActivity(s, { at: Date.now(), repoId: repo.id, kind: "sweep", text: `recovered failed task ${taskId}: issue #${parsed.number} re-opened for the next sweep` });
|
|
1067
|
+
if (parsed.kind === "takeOwnership") {
|
|
1068
|
+
void (async () => {
|
|
1069
|
+
try {
|
|
1070
|
+
const client = createGithubClient(auth);
|
|
1071
|
+
const { login } = await client.getAuthenticatedUser();
|
|
1072
|
+
const [owner, name] = repo.id.split("/");
|
|
1073
|
+
await client.removeIssueAssignees(owner, name, parsed.number, [login]);
|
|
1074
|
+
}
|
|
1075
|
+
catch (err) {
|
|
1076
|
+
logger.warn(`TeamAuto: unassign for failed claim ${repo.id}#${parsed.number} failed (scanner may skip it until a human clears the assignee): ${err instanceof Error ? err.message : String(err)}`);
|
|
1077
|
+
}
|
|
1078
|
+
})();
|
|
1079
|
+
}
|
|
1080
|
+
}
|
|
1081
|
+
if (changed) {
|
|
1082
|
+
const entries = Object.entries(s.failedClaimRecovery).sort((a, b) => a[1] - b[1]);
|
|
1083
|
+
if (entries.length > 200) {
|
|
1084
|
+
s.failedClaimRecovery = Object.fromEntries(entries.slice(entries.length - 200));
|
|
1085
|
+
}
|
|
1086
|
+
await saveTeamAutoStore(s);
|
|
1087
|
+
}
|
|
1088
|
+
}
|
|
1020
1089
|
// ---------- scheduling loop ----------
|
|
1021
1090
|
function scheduleRepo(repo) {
|
|
1022
1091
|
const previous = timers.get(repo.id);
|
|
@@ -1097,6 +1166,10 @@ export function createTeamAutoScheduler(deps) {
|
|
|
1097
1166
|
void reconcileWritebacks();
|
|
1098
1167
|
}, 20_000);
|
|
1099
1168
|
writebackTimer.unref?.();
|
|
1169
|
+
claimRecoveryTimer = setInterval(() => {
|
|
1170
|
+
void recoverFailedClaims();
|
|
1171
|
+
}, 60_000);
|
|
1172
|
+
claimRecoveryTimer.unref?.();
|
|
1100
1173
|
// Boot reconciliation: heal leftover task worktrees whose task is
|
|
1101
1174
|
// terminal (or gone entirely) - the pre-cleanup backlog never shrinks
|
|
1102
1175
|
// on its own. Safety-checked: undelivered work is kept and logged.
|
|
@@ -1160,6 +1233,9 @@ export function createTeamAutoScheduler(deps) {
|
|
|
1160
1233
|
timers.clear();
|
|
1161
1234
|
if (writebackTimer) {
|
|
1162
1235
|
clearInterval(writebackTimer);
|
|
1236
|
+
if (claimRecoveryTimer) {
|
|
1237
|
+
clearInterval(claimRecoveryTimer);
|
|
1238
|
+
}
|
|
1163
1239
|
writebackTimer = null;
|
|
1164
1240
|
}
|
|
1165
1241
|
}
|
|
@@ -44,6 +44,7 @@ function emptyStore() {
|
|
|
44
44
|
repos: [],
|
|
45
45
|
writebacks: [],
|
|
46
46
|
activity: [],
|
|
47
|
+
failedClaimRecovery: {},
|
|
47
48
|
budget: {
|
|
48
49
|
maxTasksPerDay: 150,
|
|
49
50
|
firstSweepDryRun: true,
|
|
@@ -101,6 +102,9 @@ export async function loadTeamAutoStore() {
|
|
|
101
102
|
if (Array.isArray(parsed.activity)) {
|
|
102
103
|
store.activity = parsed.activity.slice(-TEAMAUTO_ACTIVITY_LIMIT);
|
|
103
104
|
}
|
|
105
|
+
if (parsed.failedClaimRecovery && typeof parsed.failedClaimRecovery === "object") {
|
|
106
|
+
store.failedClaimRecovery = parsed.failedClaimRecovery;
|
|
107
|
+
}
|
|
104
108
|
store.budget = { ...store.budget, ...(parsed.budget ?? {}) };
|
|
105
109
|
return store;
|
|
106
110
|
}
|
package/openclaw.plugin.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"id": "teamclaw",
|
|
3
3
|
"name": "TeamClaw",
|
|
4
4
|
"description": "Virtual team collaboration - multiple OpenClaw instances form a virtual software company with role-based task routing.",
|
|
5
|
-
"version": "2026.11.
|
|
5
|
+
"version": "2026.11.4",
|
|
6
6
|
"activation": {
|
|
7
7
|
"onStartup": true
|
|
8
8
|
},
|
package/package.json
CHANGED
|
@@ -238,6 +238,13 @@ export function createGithubClient(auth: GithubAuthManager) {
|
|
|
238
238
|
await request("POST", `/repos/${owner}/${repo}/issues/${issueNumber}/assignees`, { body: { assignees: [assignee] } });
|
|
239
239
|
},
|
|
240
240
|
|
|
241
|
+
/** #claim-recovery: remove the bot's own assignment from an issue whose
|
|
242
|
+
* ownership task failed, so skipAssignedToHumans does not block the
|
|
243
|
+
* re-candidate (other human assignees are untouched). */
|
|
244
|
+
async removeIssueAssignees(owner: string, repo: string, issueNumber: number, assignees: string[]): Promise<void> {
|
|
245
|
+
await request("DELETE", `/repos/${owner}/${repo}/issues/${issueNumber}/assignees`, { body: { assignees } });
|
|
246
|
+
},
|
|
247
|
+
|
|
241
248
|
/** Fresh issue state for claim-time re-checks (#268): the scan-time
|
|
242
249
|
* assignee snapshot is seconds stale by enqueue time - a human may have
|
|
243
250
|
* self-assigned in between, and claiming over a human is worse than not
|
|
@@ -76,6 +76,21 @@ export function idempotencyMarker(candidate: { key: string; kind: string }): str
|
|
|
76
76
|
return `Idempotency-Key: ${candidate.key}:${candidate.kind}`;
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
+
/** #claim-recovery: parse the marker back out of a (failed) task's
|
|
80
|
+
* description - `{ repoId, number, kind, key }` or null. Issue candidates
|
|
81
|
+
* only (PR keys `#pr-` are not claim-bearing). */
|
|
82
|
+
export function parseClaimMarker(description: string): { repoId: string; number: number; kind: string; key: string } | null {
|
|
83
|
+
const m = /Idempotency-Key: ([^:\s]+)#issue-(\d+):(\w+)/.exec(description);
|
|
84
|
+
if (!m) {
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
const number = Number(m[2]);
|
|
88
|
+
if (!m[1] || !Number.isFinite(number)) {
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
return { repoId: m[1], number, kind: m[3], key: `${m[1]}#issue-${number}` };
|
|
92
|
+
}
|
|
93
|
+
|
|
79
94
|
/** Failed task attempts for a candidate (task history is the attempt log). */
|
|
80
95
|
export function failedAttemptCount(
|
|
81
96
|
state: { tasks: Record<string, { description: string; status: string; error?: string }> },
|
|
@@ -315,6 +330,7 @@ export function createTeamAutoScheduler(deps: TeamAutoSchedulerDeps) {
|
|
|
315
330
|
let running = false;
|
|
316
331
|
let store: TeamAutoStore | null = null;
|
|
317
332
|
let writebackTimer: NodeJS.Timeout | null = null;
|
|
333
|
+
let claimRecoveryTimer: NodeJS.Timeout | null = null;
|
|
318
334
|
|
|
319
335
|
async function ensureStore(): Promise<TeamAutoStore> {
|
|
320
336
|
if (!store) {
|
|
@@ -1098,6 +1114,60 @@ export function createTeamAutoScheduler(deps: TeamAutoSchedulerDeps) {
|
|
|
1098
1114
|
})();
|
|
1099
1115
|
}
|
|
1100
1116
|
|
|
1117
|
+
/** #claim-recovery: a task that CLAIMED an issue (takeOwnership stamps the
|
|
1118
|
+
* seen cursor AND self-assigns the bot at enqueue time; issueReview stamps
|
|
1119
|
+
* the cursor) locks the issue twice against re-candidacy. When the task
|
|
1120
|
+
* fails, the issue must not be orphaned - nobody (human or bot) would ever
|
|
1121
|
+
* pick it up again. Once per failed taskId: clear the seen stamp so the
|
|
1122
|
+
* next sweep re-candidates naturally, and for takeOwnership remove the
|
|
1123
|
+
* bot's own assignment (human assignees untouched). The existing
|
|
1124
|
+
* dead-letter caps (3 hard / 6 transient) bound how often this can loop. */
|
|
1125
|
+
async function recoverFailedClaims(): Promise<void> {
|
|
1126
|
+
const teamState = deps.getTeamState();
|
|
1127
|
+
if (!teamState) {
|
|
1128
|
+
return;
|
|
1129
|
+
}
|
|
1130
|
+
const s = await ensureStore();
|
|
1131
|
+
s.failedClaimRecovery ??= {};
|
|
1132
|
+
let changed = false;
|
|
1133
|
+
for (const [taskId, task] of Object.entries(teamState.tasks ?? {})) {
|
|
1134
|
+
if (task?.status !== "failed" || typeof task.description !== "string" || !task.description.includes("Idempotency-Key:")) {
|
|
1135
|
+
continue;
|
|
1136
|
+
}
|
|
1137
|
+
if (s.failedClaimRecovery[taskId]) {
|
|
1138
|
+
continue;
|
|
1139
|
+
}
|
|
1140
|
+
const parsed = parseClaimMarker(task.description);
|
|
1141
|
+
const repo = parsed ? s.repos.find((r) => r.id === parsed.repoId) : undefined;
|
|
1142
|
+
if (!parsed || !repo) {
|
|
1143
|
+
continue;
|
|
1144
|
+
}
|
|
1145
|
+
delete repo.cursors.seen[parsed.key];
|
|
1146
|
+
s.failedClaimRecovery[taskId] = Date.now();
|
|
1147
|
+
changed = true;
|
|
1148
|
+
recordActivity(s, { at: Date.now(), repoId: repo.id, kind: "sweep", text: `recovered failed task ${taskId}: issue #${parsed.number} re-opened for the next sweep` });
|
|
1149
|
+
if (parsed.kind === "takeOwnership") {
|
|
1150
|
+
void (async () => {
|
|
1151
|
+
try {
|
|
1152
|
+
const client = createGithubClient(auth);
|
|
1153
|
+
const { login } = await client.getAuthenticatedUser();
|
|
1154
|
+
const [owner, name] = repo.id.split("/");
|
|
1155
|
+
await client.removeIssueAssignees(owner, name, parsed.number, [login]);
|
|
1156
|
+
} catch (err) {
|
|
1157
|
+
logger.warn(`TeamAuto: unassign for failed claim ${repo.id}#${parsed.number} failed (scanner may skip it until a human clears the assignee): ${err instanceof Error ? err.message : String(err)}`);
|
|
1158
|
+
}
|
|
1159
|
+
})();
|
|
1160
|
+
}
|
|
1161
|
+
}
|
|
1162
|
+
if (changed) {
|
|
1163
|
+
const entries = Object.entries(s.failedClaimRecovery).sort((a, b) => a[1] - b[1]);
|
|
1164
|
+
if (entries.length > 200) {
|
|
1165
|
+
s.failedClaimRecovery = Object.fromEntries(entries.slice(entries.length - 200));
|
|
1166
|
+
}
|
|
1167
|
+
await saveTeamAutoStore(s);
|
|
1168
|
+
}
|
|
1169
|
+
}
|
|
1170
|
+
|
|
1101
1171
|
// ---------- scheduling loop ----------
|
|
1102
1172
|
|
|
1103
1173
|
function scheduleRepo(repo: TeamAutoRepo): void {
|
|
@@ -1176,6 +1246,10 @@ export function createTeamAutoScheduler(deps: TeamAutoSchedulerDeps) {
|
|
|
1176
1246
|
void reconcileWritebacks();
|
|
1177
1247
|
}, 20_000);
|
|
1178
1248
|
writebackTimer.unref?.();
|
|
1249
|
+
claimRecoveryTimer = setInterval(() => {
|
|
1250
|
+
void recoverFailedClaims();
|
|
1251
|
+
}, 60_000);
|
|
1252
|
+
claimRecoveryTimer.unref?.();
|
|
1179
1253
|
// Boot reconciliation: heal leftover task worktrees whose task is
|
|
1180
1254
|
// terminal (or gone entirely) - the pre-cleanup backlog never shrinks
|
|
1181
1255
|
// on its own. Safety-checked: undelivered work is kept and logged.
|
|
@@ -1237,6 +1311,9 @@ export function createTeamAutoScheduler(deps: TeamAutoSchedulerDeps) {
|
|
|
1237
1311
|
timers.clear();
|
|
1238
1312
|
if (writebackTimer) {
|
|
1239
1313
|
clearInterval(writebackTimer);
|
|
1314
|
+
if (claimRecoveryTimer) {
|
|
1315
|
+
clearInterval(claimRecoveryTimer);
|
|
1316
|
+
}
|
|
1240
1317
|
writebackTimer = null;
|
|
1241
1318
|
}
|
|
1242
1319
|
}
|
package/src/teamauto/store.ts
CHANGED
|
@@ -168,6 +168,11 @@ export type TeamAutoStore = {
|
|
|
168
168
|
tasksToday: number;
|
|
169
169
|
dayStamp: string;
|
|
170
170
|
};
|
|
171
|
+
/** #claim-recovery: taskId -> recoveredAt. A failed task whose candidate
|
|
172
|
+
* claimed an issue must not orphan it - the recovery pass clears the seen
|
|
173
|
+
* stamp (and the bot's self-assignment) once per taskId so the next sweep
|
|
174
|
+
* re-candidates naturally, while the dead-letter caps bound retries. */
|
|
175
|
+
failedClaimRecovery?: Record<string, number>;
|
|
171
176
|
};
|
|
172
177
|
|
|
173
178
|
export function defaultPolicy(): TeamAutoRepoPolicy {
|
|
@@ -191,6 +196,7 @@ function emptyStore(): TeamAutoStore {
|
|
|
191
196
|
repos: [],
|
|
192
197
|
writebacks: [],
|
|
193
198
|
activity: [],
|
|
199
|
+
failedClaimRecovery: {},
|
|
194
200
|
budget: {
|
|
195
201
|
maxTasksPerDay: 150,
|
|
196
202
|
firstSweepDryRun: true,
|
|
@@ -249,6 +255,9 @@ export async function loadTeamAutoStore(): Promise<TeamAutoStore> {
|
|
|
249
255
|
if (Array.isArray(parsed.activity)) {
|
|
250
256
|
store.activity = parsed.activity.slice(-TEAMAUTO_ACTIVITY_LIMIT);
|
|
251
257
|
}
|
|
258
|
+
if (parsed.failedClaimRecovery && typeof parsed.failedClaimRecovery === "object") {
|
|
259
|
+
store.failedClaimRecovery = parsed.failedClaimRecovery as Record<string, number>;
|
|
260
|
+
}
|
|
252
261
|
store.budget = { ...store.budget, ...(parsed.budget ?? {}) };
|
|
253
262
|
return store;
|
|
254
263
|
} catch {
|