Skip to content

fix: make agent run timeout configurable - #101

Open
Twil3akine wants to merge 7 commits into
CopilotKit:mainfrom
Twil3akine:fix/configurable-agent-run-timeout
Open

Twil3akine wants to merge 7 commits into
CopilotKit:mainfrom
Twil3akine:fix/configurable-agent-run-timeout

Conversation

@Twil3akine

@Twil3akine Twil3akine commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Make the 90-second agent run limit configurable with AGENT_RUN_TIMEOUT_MS for interactive and scheduled/background runs. Preserve 90 seconds as the default.

Changes

  • Validate the setting at startup: reject non-integer, non-positive and timer-overflow values.
  • Pass the configured timeout to DotAgent and the background Runner.
  • Forward the setting through the app service in compose.yml and document it in .env.example.
  • Keep each background worker lease valid for max(180000, timeout × 2) milliseconds. This prevents a second worker sharing the database from interrupting a valid long-running task at the old 180-second deadline.
AGENT_RUN_TIMEOUT_MS=240000

The default remains a 90-second timeout and 180-second lease. At a 240-second timeout, the lease becomes 480 seconds; recovering a crashed worker can therefore take longer. Explicit cancellation and permission revocation remain effective.

Validation

  • Two Runners and two Stores sharing a real SQLite file reproduce the original interruption at 180001ms before the lease fix. Afterward, a 200-second execution completes and a non-completing execution still times out at 240 seconds.
  • Tests cover defaults, invalid values, interactive and background timeouts, lease expiry, explicit retry and rejection of stale claims.
  • All 261 tests, format, lint, typecheck and build pass on the PR branch.
  • A temporary integration with upstream main 625452e passes all 309 tests and the same static/build checks without merge conflicts.
  • Local HTTP fixtures were tested with environment proxy routing disabled and non-loopback connections blocked.
  • Docker CLI is unavailable, so actual docker compose config rendering was not verified; YAML syntax and unset/empty/custom-value interpolation were checked.

Prepared with AI assistance using gwitg, a GPT-6.1 Sol project lead and GPT-6 Luna workers.

@jerelvelarde jerelvelarde left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Useful configuration improvement with good scope, but hold merge for the two integration issues below. All 32 focused timeout/runner/store/headless/channel tests pass. Defaults, invalid values and timer bounds were checked; the findings were reproduced with two workers sharing SQLite and with rendered Docker Compose configuration.

Comment thread src/server/runner.ts
),
),
90_000,
this.runTimeoutMs,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Keep the task lease valid for the configured run duration. With AGENT_RUN_TIMEOUT_MS=240000, another worker polling the same database interrupts the active run at 180 seconds, before the configured timeout. A two-Runner/two-Store fixture reproduces “Worker lease expired” at 180001ms and no result. The task is held interrupted, not automatically run twice. Update lease duration or renewal together with the timeout and cover this interaction.

Comment thread src/server/index.ts
apiKey: process.env.OPENAI_API_KEY,
model: process.env.OPENAI_MODEL,
baseUrl: process.env.OPENAI_BASE_URL ?? 'https://api.openai.com/v1',
agentRunTimeoutMs: agentRunTimeoutMsFromEnv(process.env),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Forward AGENT_RUN_TIMEOUT_MS through the app service in compose.yml. Setting the documented option in .env currently leaves Docker deployments at the 90-second default because the variable never reaches the container. docker compose config confirms the app environment omits the variable even when set to 240000.

Copy link
Copy Markdown
Contributor Author

Thanks for the review. I'll address both issues: keeping the worker lease valid for the configured run timeout and forwarding AGENT_RUN_TIMEOUT_MS through Docker Compose. I'll also add regression coverage for the shared-database worker interaction.

Copy link
Copy Markdown
Contributor Author

I've pushed fixes for both review findings and updated the PR description with the validation results and remaining limitations. Sorry for the extra review work, and thank you for catching these issues. Could you take another look when you have time?

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.

2 participants