fix: add explicit worker state update in task_pickup after dispatch (#23)

Adds defense-in-depth by explicitly calling activateWorker() in task_pickup.ts
after dispatchTask() returns. This ensures the worker state (active, issueId,
model, sessionKey, startTime) is properly set in projects.json even if
dispatchTask's internal state update encounters issues.

The redundant update:
- Sets active=true, issueId, and model for both spawn and reuse cases
- Sets sessionKey and startTime only on new spawns (not on session reuse)
- Provides fallback if race conditions or I/O errors affect dispatch.ts

Fixes #23
This commit is contained in:
Lauren ten Hoor
2026-02-10 08:34:03 +08:00
parent 6bc33b9d23
commit d727a812e6

View File

@@ -17,7 +17,7 @@ import { dispatchTask } from "../dispatch.js";
import { type Issue, type StateLabel } from "../task-managers/task-manager.js";
import { createProvider } from "../task-managers/index.js";
import { selectModel } from "../model-selector.js";
import { getProject, getWorker, readProjects } from "../projects.js";
import { activateWorker, getProject, getWorker, readProjects } from "../projects.js";
import type { ToolContext } from "../types.js";
import { detectContext, generateGuardrails } from "../context-guard.js";
import { isDevTier, isTier, type Tier } from "../tiers.js";
@@ -313,6 +313,27 @@ export function createTaskPickupTool(api: OpenClawPluginApi) {
pluginConfig,
});
// 8b. Explicitly update worker state in projects.json
// Defense in depth: ensure state is set even if dispatchTask had issues
const now = new Date().toISOString();
const stateUpdateParams: {
issueId: string;
model: string;
sessionKey?: string;
startTime?: string;
} = {
issueId: String(issue.iid),
model: modelAlias,
};
// Only set sessionKey and startTime on new spawn (not on reuse)
if (dispatchResult.sessionAction === "spawn") {
stateUpdateParams.sessionKey = dispatchResult.sessionKey;
stateUpdateParams.startTime = now;
}
await activateWorker(workspaceDir, groupId, role, stateUpdateParams);
// 9. Send notification to project group
const notifyConfig = getNotificationConfig(pluginConfig);
await notify(