openthrottle 0.1.14 → 0.1.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/run.js +22 -16
  2. package/package.json +1 -1
package/dist/run.js CHANGED
@@ -107,26 +107,32 @@ export default async function run() {
107
107
  });
108
108
  console.log(`[run] Sandbox created: ${sandboxName}`);
109
109
  console.log(`[run] Streaming logs (timeout: ${taskTimeout}s)...`);
110
- // Stream entrypoint logs blocks until entrypoint exits
111
- const logStreamDone = sandbox.process.getEntrypointLogs((chunk) => process.stdout.write(chunk), (chunk) => process.stderr.write(chunk));
112
- await Promise.race([
113
- logStreamDone,
114
- new Promise((_, reject) => setTimeout(() => reject(new Error(`Task timeout (${taskTimeout}s) exceeded`)), taskTimeout * 1000)),
115
- ]);
116
- // Get exit code
110
+ // Stream entrypoint logs in background
111
+ sandbox.process.getEntrypointLogs((chunk) => process.stdout.write(chunk), (chunk) => process.stderr.write(chunk)).catch(() => { }); // stream may error when sandbox stops — that's fine
112
+ // Poll for entrypoint completion. getEntrypointLogs() may not resolve
113
+ // when the entrypoint exits because Daytona keeps the container alive.
114
+ const POLL_MS = 5_000;
117
115
  let exitCode = 0;
118
- try {
119
- const session = await sandbox.process.getEntrypointSession();
120
- const commands = session?.commands || [];
121
- if (commands.length > 0) {
122
- const last = commands[commands.length - 1];
123
- if (last.exitCode !== undefined && last.exitCode !== null) {
124
- exitCode = last.exitCode;
116
+ const deadline = Date.now() + taskTimeout * 1000;
117
+ while (Date.now() < deadline) {
118
+ await new Promise((r) => setTimeout(r, POLL_MS));
119
+ try {
120
+ const session = await sandbox.process.getEntrypointSession();
121
+ const commands = session?.commands || [];
122
+ if (commands.length > 0) {
123
+ const last = commands[commands.length - 1];
124
+ if (last.exitCode !== undefined && last.exitCode !== null) {
125
+ exitCode = last.exitCode;
126
+ break;
127
+ }
125
128
  }
126
129
  }
130
+ catch {
131
+ // sandbox may not be ready yet — keep polling
132
+ }
127
133
  }
128
- catch {
129
- // default to 0
134
+ if (Date.now() >= deadline) {
135
+ throw new Error(`Task timeout (${taskTimeout}s) exceeded`);
130
136
  }
131
137
  console.log(`[run] Finished (exit code: ${exitCode})`);
132
138
  await cleanup();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openthrottle",
3
- "version": "0.1.14",
3
+ "version": "0.1.15",
4
4
  "description": "CLI for Open Throttle — ship prompts to Daytona sandboxes.",
5
5
  "type": "module",
6
6
  "bin": {