Skip to content
Draft
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
22 changes: 12 additions & 10 deletions .cursor/skills/dag-task-runner/scripts/run_dag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,12 +337,7 @@ async function runTask(
? `${upstreamContext}\n\n---\n\n${task.subtask_prompt}`
: task.subtask_prompt;

const agent = await Agent.create({
apiKey: process.env.CURSOR_API_KEY!,
model: { id: ts.model },
local: { cwd },
});

let agent: Awaited<ReturnType<typeof Agent.create>> | undefined;
let run: RunnerTaskRun | undefined;
const buffer = new BoundedTextBuffer(STREAM_CAP);
let lastPublishAt = 0;
Expand All @@ -357,6 +352,11 @@ async function runTask(
const deadline = Date.now() + taskTimeoutMs;

try {
agent = await Agent.create({
apiKey: process.env.CURSOR_API_KEY!,
model: { id: ts.model },
local: { cwd },
});
run = (await agent.send(stitched)) as RunnerTaskRun;
const iterator = run.stream()[Symbol.asyncIterator]();
while (true) {
Expand Down Expand Up @@ -456,10 +456,12 @@ async function runTask(
await bestEffortCancel(run, task.id);
}
publishIfDue(true);
try {
await (agent as unknown as AsyncDisposable)[Symbol.asyncDispose]();
} catch {
// ignore dispose errors
if (agent) {
try {
await (agent as unknown as AsyncDisposable)[Symbol.asyncDispose]();
} catch {
// ignore dispose errors
}
}
writer.schedule(structuredCloneState(state));
}
Expand Down
22 changes: 12 additions & 10 deletions sdk/dag-task-runner/src/run_dag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,12 +337,7 @@ async function runTask(
? `${upstreamContext}\n\n---\n\n${task.subtask_prompt}`
: task.subtask_prompt;

const agent = await Agent.create({
apiKey: process.env.CURSOR_API_KEY!,
model: { id: ts.model },
local: { cwd },
});

let agent: Awaited<ReturnType<typeof Agent.create>> | undefined;
let run: RunnerTaskRun | undefined;
const buffer = new BoundedTextBuffer(STREAM_CAP);
let lastPublishAt = 0;
Expand All @@ -357,6 +352,11 @@ async function runTask(
const deadline = Date.now() + taskTimeoutMs;

try {
agent = await Agent.create({
apiKey: process.env.CURSOR_API_KEY!,
model: { id: ts.model },
local: { cwd },
});
run = (await agent.send(stitched)) as RunnerTaskRun;
const iterator = run.stream()[Symbol.asyncIterator]();
while (true) {
Expand Down Expand Up @@ -456,10 +456,12 @@ async function runTask(
await bestEffortCancel(run, task.id);
}
publishIfDue(true);
try {
await (agent as unknown as AsyncDisposable)[Symbol.asyncDispose]();
} catch {
// ignore dispose errors
if (agent) {
try {
await (agent as unknown as AsyncDisposable)[Symbol.asyncDispose]();
} catch {
// ignore dispose errors
}
}
writer.schedule(structuredCloneState(state));
}
Expand Down