Skip to content

Conversation

github-actions[bot]
Copy link

Closes #430

Applied changes based on Issue #430.

I’ve updated run() in src/main.ts so that your configured timeout‑in‑seconds now actually bounds the overall runAction(...) execution, not just the Codex CLI invocation. In particular:

  • Doc‑update: Clarified in the JSDoc that we “execute the main action logic within the configured timeout budget.”
  • Timeout‑wrapper: Replaced the raw await runAction(...) with a Promise.race that races runAction against a setTimeout-driven rejection after config.timeoutSeconds.
  • Cleanup: We clear the timer in a finally block so there’s no leftover timer if the action completes (or fails) first.

Diff of src/main.ts (click to expand)
diff --git a/src/main.ts b/src/main.ts
index 81d0860..47fdca3 100644
--- a/src/main.ts
+++ b/src/main.ts
@@ -19,7 +19,7 @@ import { checkPermission } from './security/security.js';
  * Orchestrate the action's workflow.
  *
- * Retrieves configuration, processes the event, checks permissions,
- * and executes the main action logic.
+ * Retrieves configuration, processes the event, checks permissions,
+ * and executes the main action logic within the configured timeout budget.
  * @returns A promise that resolves when the action completes.
  */

@@ -75,8 +75,22 @@ export async function run(): Promise<void> {
     if (!hasPermission) {
       core.warning('Permission check failed. Exiting process.');
       return;
     }

-    // Event is valid and prompt exists, run the main action logic
-    await runAction(config, processedEvent);
+    // Event is valid and prompt exists, run the main action logic with timeout control
+    const timeoutMs = config.timeoutSeconds * 1000;
+    let timer: ReturnType<typeof setTimeout>;
+    try {
+      await Promise.race([
+        runAction(config, processedEvent),
+        new Promise<never>((_, reject) => {
+          timer = setTimeout(
+            () => reject(new Error(`Action timed out after ${config.timeoutSeconds} seconds`)),
+            timeoutMs,
+          );
+        }),
+      ]);
+    } finally {
+      clearTimeout(timer!);
+    }

This ensures that if the overall action logic (including cloning, prompting, Codex runs, patching, etc.) exceeds your timeout input, it will abort and fail cleanly rather than run indefinitely. Let me know if you’d like any tweaks to the timeout‑error handling (e.g. posting a comment on the PR/issue).

@YiweiShen YiweiShen merged commit 6ec9505 into main Jul 14, 2025
3 checks passed
@YiweiShen YiweiShen deleted the codez-fix-430-main-enforce-timeout-flag-on-runaction-3067779337 branch July 14, 2025 04:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Verify how the timeout flag functions within the model runtime budget, and if it is not functioning correctly, please propose a fix.

1 participant