Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions apps/server/src/handlers/task/task.decompose.handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,17 +117,23 @@ export class TaskDecomposeHandler {

// Get worker's working directory from instance metadata
let workingDirectory: string | undefined;
if (ctx.instanceId) {
const instanceKey = `cb:instance:${ctx.instanceId}`;
// First check if a specific worker was requested in the input metadata
const requestedWorkerId = input.metadata?.workerId;
const workerId = requestedWorkerId || ctx.instanceId;

if (workerId) {
const instanceKey = `cb:instance:${workerId}`;
const instanceMetadata = await redis.pub.hget(instanceKey, 'metadata');
if (instanceMetadata) {
try {
const metadata = JSON.parse(instanceMetadata);
workingDirectory = metadata.workingDirectory;
console.log(`[TaskDecompose] Using working directory from instance ${ctx.instanceId}: ${workingDirectory}`);
console.log(`[TaskDecompose] Using working directory from instance ${workerId}: ${workingDirectory}`);
} catch (e) {
console.warn(`[TaskDecompose] Failed to parse instance metadata:`, e);
console.warn(`[TaskDecompose] Failed to parse instance metadata for ${workerId}:`, e);
}
} else if (requestedWorkerId) {
console.warn(`[TaskDecompose] Requested worker ${requestedWorkerId} not found or has no metadata`);
}
}

Expand Down
16 changes: 14 additions & 2 deletions apps/web/src/services/event-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,16 @@ export class EventClient {
const id = ++this.requestId;

// Use longer timeout for context generation and other long-running operations
const longRunningMethods = ['task.context', 'swarm.context', 'swarm.decompose', 'swarm.synthesize', 'swarm.resolve'];
const longRunningMethods = [
'task.context',
'task.decompose',
'task.create_project',
'swarm.context',
'swarm.decompose',
'swarm.synthesize',
'swarm.resolve',
'swarm.create_project'
];
const isLongRunning = longRunningMethods.includes(method);
const originalTimeout = this.config.timeout;

Expand All @@ -106,8 +115,11 @@ export class EventClient {

let lastError: Error | undefined;

// For long-running operations, don't retry automatically as they may not be idempotent
const maxAttempts = isLongRunning ? 1 : this.config.retries + 1;

try {
for (let attempt = 0; attempt <= this.config.retries; attempt++) {
for (let attempt = 0; attempt < maxAttempts; attempt++) {
try {
const response = await this.sendRequest(request);

Expand Down