mirror of
https://github.com/Sea-Haven-Industries/open-swe.git
synced 2026-10-03 22:33:19 +00:00
fix: Better handling of updating sandbox timeout (#41)
This commit is contained in:
parent
d079c63424
commit
2381e9f703
3 changed files with 36 additions and 7 deletions
|
|
@ -54,6 +54,7 @@ You MUST adhere to the following criteria when executing the task:
|
||||||
- When using the \`shell\` tool, always take advantage of the \`workdir\` parameter to run commands inside the repo directory. You should not try to generate a command with \`cd <some path>\` as passing that path to \`workdir\` is much more efficient.
|
- When using the \`shell\` tool, always take advantage of the \`workdir\` parameter to run commands inside the repo directory. You should not try to generate a command with \`cd <some path>\` as passing that path to \`workdir\` is much more efficient.
|
||||||
- Always use the correct package manager to install dependencies. If the package manager is not already installed in the sandbox, use the \`shell\` tool to install it.
|
- Always use the correct package manager to install dependencies. If the package manager is not already installed in the sandbox, use the \`shell\` tool to install it.
|
||||||
- If the package manager fails to install, or you have issues installing dependencies, do not try to use a different package manager. Instead, skip installing dependencies.
|
- If the package manager fails to install, or you have issues installing dependencies, do not try to use a different package manager. Instead, skip installing dependencies.
|
||||||
|
- If installing dependencies fails, it can be useful to try again passing in a much longer timeout than the default.
|
||||||
- If completing the user's task requires writing or modifying files:
|
- If completing the user's task requires writing or modifying files:
|
||||||
- Your code and final answer should follow these *CODING GUIDELINES*:
|
- Your code and final answer should follow these *CODING GUIDELINES*:
|
||||||
- Avoid writing to files which you have not already read.
|
- Avoid writing to files which you have not already read.
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,7 @@ const shellToolSchema = z.object({
|
||||||
|
|
||||||
export const shellTool = tool(
|
export const shellTool = tool(
|
||||||
async (input): Promise<{ result: string; status: "success" | "error" }> => {
|
async (input): Promise<{ result: string; status: "success" | "error" }> => {
|
||||||
|
let sandbox: Sandbox | undefined;
|
||||||
try {
|
try {
|
||||||
const state = getCurrentTaskInput<GraphState>();
|
const state = getCurrentTaskInput<GraphState>();
|
||||||
const { sandboxSessionId } = state;
|
const { sandboxSessionId } = state;
|
||||||
|
|
@ -42,14 +43,12 @@ export const shellTool = tool(
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const sandbox = await Sandbox.connect(sandboxSessionId);
|
sandbox = await Sandbox.connect(sandboxSessionId);
|
||||||
const { command, workdir, timeout } = input;
|
const { command, workdir, timeout } = input;
|
||||||
const result = await sandbox.commands.run(command.join(" "), {
|
const result = await sandbox.commands.run(command.join(" "), {
|
||||||
timeoutMs: timeout ?? DEFAULT_COMMAND_TIMEOUT,
|
timeoutMs: timeout ?? DEFAULT_COMMAND_TIMEOUT,
|
||||||
cwd: workdir,
|
cwd: workdir,
|
||||||
});
|
});
|
||||||
// Add an extra 5 min timeout to the sandbox.
|
|
||||||
await sandbox.setTimeout(TIMEOUT_MS);
|
|
||||||
|
|
||||||
if (result.error) {
|
if (result.error) {
|
||||||
logger.error("Failed to run command", {
|
logger.error("Failed to run command", {
|
||||||
|
|
@ -92,6 +91,17 @@ export const shellTool = tool(
|
||||||
"FAILED TO RUN COMMAND: " +
|
"FAILED TO RUN COMMAND: " +
|
||||||
(e instanceof Error ? e.message : "Unknown error"),
|
(e instanceof Error ? e.message : "Unknown error"),
|
||||||
);
|
);
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
if (sandbox) {
|
||||||
|
// Add an extra 5 min timeout to the sandbox.
|
||||||
|
await sandbox.setTimeout(TIMEOUT_MS);
|
||||||
|
}
|
||||||
|
} catch (_) {
|
||||||
|
logger.warn(
|
||||||
|
"Failed to set timeout for sandbox inside 'finally' block for shell tool.",
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -47,8 +47,6 @@ async function readFileFunc(
|
||||||
const readOutput = await sandbox.commands.run(`cat "${filePath}"`, {
|
const readOutput = await sandbox.commands.run(`cat "${filePath}"`, {
|
||||||
cwd: args?.workDir,
|
cwd: args?.workDir,
|
||||||
});
|
});
|
||||||
// Add an extra 5 min timeout to the sandbox.
|
|
||||||
await sandbox.setTimeout(TIMEOUT_MS);
|
|
||||||
|
|
||||||
if (readOutput.exitCode !== 0) {
|
if (readOutput.exitCode !== 0) {
|
||||||
logger.error(`Error reading file '${filePath}' from sandbox via cat:`, {
|
logger.error(`Error reading file '${filePath}' from sandbox via cat:`, {
|
||||||
|
|
@ -102,6 +100,17 @@ async function readFileFunc(
|
||||||
success: false,
|
success: false,
|
||||||
output: outputMessage,
|
output: outputMessage,
|
||||||
};
|
};
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
if (sandbox) {
|
||||||
|
// Add an extra 5 min timeout to the sandbox.
|
||||||
|
await sandbox.setTimeout(TIMEOUT_MS);
|
||||||
|
}
|
||||||
|
} catch (_) {
|
||||||
|
logger.warn(
|
||||||
|
"Failed to set timeout for sandbox inside 'finally' block for read file.",
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -128,8 +137,6 @@ ${delimiter}`;
|
||||||
const writeOutput = await sandbox.commands.run(writeCommand, {
|
const writeOutput = await sandbox.commands.run(writeCommand, {
|
||||||
cwd: args?.workDir,
|
cwd: args?.workDir,
|
||||||
});
|
});
|
||||||
// Add an extra 5 min timeout to the sandbox.
|
|
||||||
await sandbox.setTimeout(TIMEOUT_MS);
|
|
||||||
|
|
||||||
if (writeOutput.exitCode !== 0) {
|
if (writeOutput.exitCode !== 0) {
|
||||||
logger.error(`Error writing file '${filePath}' to sandbox via cat:`, {
|
logger.error(`Error writing file '${filePath}' to sandbox via cat:`, {
|
||||||
|
|
@ -171,6 +178,17 @@ ${delimiter}`;
|
||||||
success: false,
|
success: false,
|
||||||
output: outputMessage,
|
output: outputMessage,
|
||||||
};
|
};
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
if (sandbox) {
|
||||||
|
// Add an extra 5 min timeout to the sandbox.
|
||||||
|
await sandbox.setTimeout(TIMEOUT_MS);
|
||||||
|
}
|
||||||
|
} catch (_) {
|
||||||
|
logger.warn(
|
||||||
|
"Failed to set timeout for sandbox inside 'finally' block for write file.",
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue