Skip to content

Commit db92f27

Browse files
committed
Remove abort signal handling from LocalRuntime operations
Local file operations (readFile, writeFile, stat, renameWorkspace, deleteWorkspace) are fast and don't need cancellation support. The abort signal parameters remain in the interface for SSHRuntime, but LocalRuntime now ignores them with a comment explaining why. This simplifies LocalRuntime while keeping abort signal support where it matters most - in SSHRuntime's network-bound operations.
1 parent a4421ef commit db92f27

File tree

1 file changed

+5
-46
lines changed

1 file changed

+5
-46
lines changed

src/runtime/LocalRuntime.ts

Lines changed: 5 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -210,27 +210,14 @@ export class LocalRuntime implements Runtime {
210210
}
211211

212212
readFile(filePath: string, abortSignal?: AbortSignal): ReadableStream<Uint8Array> {
213+
// Note: abortSignal ignored for local operations (fast, no need for cancellation)
213214
const nodeStream = fs.createReadStream(filePath);
214215

215216
// Handle errors by wrapping in a transform
216217
const webStream = Readable.toWeb(nodeStream) as unknown as ReadableStream<Uint8Array>;
217218

218219
return new ReadableStream<Uint8Array>({
219220
async start(controller: ReadableStreamDefaultController<Uint8Array>) {
220-
// Check if already aborted
221-
if (abortSignal?.aborted) {
222-
controller.error(new Error("Read operation aborted"));
223-
nodeStream.destroy();
224-
return;
225-
}
226-
227-
// Set up abort listener
228-
const abortHandler = () => {
229-
controller.error(new Error("Read operation aborted"));
230-
nodeStream.destroy();
231-
};
232-
abortSignal?.addEventListener("abort", abortHandler);
233-
234221
try {
235222
const reader = webStream.getReader();
236223
while (true) {
@@ -247,24 +234,18 @@ export class LocalRuntime implements Runtime {
247234
err instanceof Error ? err : undefined
248235
)
249236
);
250-
} finally {
251-
abortSignal?.removeEventListener("abort", abortHandler);
252237
}
253238
},
254239
});
255240
}
256241

257242
writeFile(filePath: string, abortSignal?: AbortSignal): WritableStream<Uint8Array> {
243+
// Note: abortSignal ignored for local operations (fast, no need for cancellation)
258244
let tempPath: string;
259245
let writer: WritableStreamDefaultWriter<Uint8Array>;
260246

261247
return new WritableStream<Uint8Array>({
262248
async start() {
263-
// Check if already aborted
264-
if (abortSignal?.aborted) {
265-
throw new Error("Write operation aborted");
266-
}
267-
268249
// Create parent directories if they don't exist
269250
const parentDir = path.dirname(filePath);
270251
await fsPromises.mkdir(parentDir, { recursive: true });
@@ -274,19 +255,8 @@ export class LocalRuntime implements Runtime {
274255
const nodeStream = fs.createWriteStream(tempPath);
275256
const webStream = Writable.toWeb(nodeStream) as WritableStream<Uint8Array>;
276257
writer = webStream.getWriter();
277-
278-
// Set up abort listener
279-
const abortHandler = () => {
280-
writer.abort("Write operation aborted").catch(() => {
281-
// Ignore errors during abort
282-
});
283-
};
284-
abortSignal?.addEventListener("abort", abortHandler);
285258
},
286259
async write(chunk: Uint8Array) {
287-
if (abortSignal?.aborted) {
288-
throw new Error("Write operation aborted");
289-
}
290260
await writer.write(chunk);
291261
},
292262
async close() {
@@ -319,11 +289,7 @@ export class LocalRuntime implements Runtime {
319289
}
320290

321291
async stat(filePath: string, abortSignal?: AbortSignal): Promise<FileStat> {
322-
// Check if already aborted
323-
if (abortSignal?.aborted) {
324-
throw new Error("Stat operation aborted");
325-
}
326-
292+
// Note: abortSignal ignored for local operations (fast, no need for cancellation)
327293
try {
328294
const stats = await fsPromises.stat(filePath);
329295
return {
@@ -504,10 +470,7 @@ export class LocalRuntime implements Runtime {
504470
): Promise<
505471
{ success: true; oldPath: string; newPath: string } | { success: false; error: string }
506472
> {
507-
// Check if already aborted
508-
if (abortSignal?.aborted) {
509-
return { success: false, error: "Rename operation aborted" };
510-
}
473+
// Note: abortSignal ignored for local operations (fast, no need for cancellation)
511474
// Compute workspace paths using canonical method
512475
const oldPath = this.getWorkspacePath(projectPath, oldName);
513476
const newPath = this.getWorkspacePath(projectPath, newName);
@@ -530,11 +493,7 @@ export class LocalRuntime implements Runtime {
530493
force: boolean,
531494
abortSignal?: AbortSignal
532495
): Promise<{ success: true; deletedPath: string } | { success: false; error: string }> {
533-
// Check if already aborted
534-
if (abortSignal?.aborted) {
535-
return { success: false, error: "Delete operation aborted" };
536-
}
537-
496+
// Note: abortSignal ignored for local operations (fast, no need for cancellation)
538497
// Compute workspace path using the canonical method
539498
const deletedPath = this.getWorkspacePath(projectPath, workspaceName);
540499

0 commit comments

Comments
 (0)