Skip to content

chore: make hardcoded timeouts and constants configurable via env vars - #79

Merged
TytaniumDev merged 2 commits into
mainfrom
chore/configurable-constants
Feb 27, 2026
Merged

TytaniumDev merged 2 commits into
mainfrom
chore/configurable-constants

Conversation

@TytaniumDev

Copy link
Copy Markdown
Owner

Summary

  • Make worker container timeout, CPU/memory reserves, and API timeout configurable via env vars
  • Make API stale job thresholds and requeue cooldown configurable
  • Make heartbeat interval configurable
  • All constants retain their current values as defaults

New environment variables:

Variable Default Location
CONTAINER_TIMEOUT_MS 7200000 (2h) worker
SYSTEM_RESERVE_MB 2048 worker
CPUS_PER_SIM 2 worker
API_TIMEOUT_MS 10000 worker
HEARTBEAT_INTERVAL_MS 15000 worker
STALE_PENDING_THRESHOLD_MS 300000 (5min) api
STALE_RUNNING_THRESHOLD_MS 9000000 (2.5h) api
REQUEUE_COOLDOWN_MS 120000 (2min) api

Addresses architecture issues #6 and #9 from docs/ARCHITECTURE_ISSUES.md.

Test plan

  • All constants use parseInt(process.env.X || 'default', 10) pattern
  • Default values match the original hardcoded values
  • npm run lint --prefix api passes
  • npm run build --prefix api passes
  • All existing unit tests still pass (187/187)

🤖 Generated with Claude Code

#6, #9)

Make the following constants configurable via environment variables while
retaining their original values as defaults:

Worker (docker-runner.ts):
- SYSTEM_RESERVE_MB (default: 2048)
- CONTAINER_TIMEOUT_MS (default: 7200000 / 2 hours)
- CPUS_PER_SIM (default: 2)

Worker (worker.ts):
- API_TIMEOUT_MS (default: 10000)
- HEARTBEAT_INTERVAL_MS (default: 15000)

API (job-store-factory.ts):
- STALE_PENDING_THRESHOLD_MS (default: 300000 / 5 min)
- STALE_RUNNING_THRESHOLD_MS (default: 9000000 / 2.5 hours)
- REQUEUE_COOLDOWN_MS (default: 120000 / 2 min)

All use the parseInt(process.env.X || 'default', 10) pattern. The
REQUEUE_COOLDOWN_MS constant is shared between the "not stuck yet" check
and the per-job cooldown check in recoverStaleQueuedJob.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@gemini-code-assist

Copy link
Copy Markdown

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request externalizes several critical system constants into environment variables across the API and worker services. The primary goal is to enhance the configurability and operational flexibility of the application, allowing for easier adaptation to different deployment environments and performance tuning without requiring code modifications. This change addresses architectural issues related to hardcoded values, making the system more robust and manageable.

Highlights

  • Configurable Worker Settings: Worker container timeout, CPU/memory reserves, and API timeout are now configurable via environment variables, allowing for dynamic adjustment of worker behavior.
  • Configurable API Stale Job Thresholds: API stale job thresholds (pending and running) and the requeue cooldown period can now be set using environment variables, enhancing flexibility in job management.
  • Configurable Heartbeat Interval: The heartbeat interval for workers is now configurable via an environment variable, enabling administrators to fine-tune monitoring frequency.
  • Default Value Preservation: All newly introduced environment variables retain their original hardcoded values as defaults, ensuring backward compatibility and stable operation without immediate configuration changes.
Changelog
  • api/lib/job-store-factory.ts
    • Made STALE_PENDING_THRESHOLD_MS configurable via process.env.STALE_PENDING_THRESHOLD_MS.
    • Made STALE_RUNNING_THRESHOLD_MS configurable via process.env.STALE_RUNNING_THRESHOLD_MS.
    • Introduced and made REQUEUE_COOLDOWN_MS configurable via process.env.REQUEUE_COOLDOWN_MS.
    • Replaced hardcoded 120_000 values with REQUEUE_COOLDOWN_MS in job requeue logic.
  • worker/src/docker-runner.ts
    • Made SYSTEM_RESERVE_MB configurable via process.env.SYSTEM_RESERVE_MB.
    • Made CONTAINER_TIMEOUT_MS configurable via process.env.CONTAINER_TIMEOUT_MS.
    • Made CPUS_PER_SIM configurable via process.env.CPUS_PER_SIM.
  • worker/src/worker.ts
    • Made API_TIMEOUT_MS configurable via process.env.API_TIMEOUT_MS.
    • Made HEARTBEAT_INTERVAL_MS configurable via process.env.HEARTBEAT_INTERVAL_MS.
Activity
  • No activity has been recorded for this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request does a great job of making hardcoded constants configurable through environment variables, which significantly improves the application's flexibility. My feedback focuses on improving the consistency and readability of how default values are defined for these new environment variables, aligning with our policy to address valid code quality suggestions immediately.

Comment thread api/lib/job-store-factory.ts Outdated
Comment on lines +256 to +258
const STALE_PENDING_THRESHOLD_MS = parseInt(process.env.STALE_PENDING_THRESHOLD_MS || String(5 * 60 * 1000), 10); // Default: 5 min
// Should exceed CONTAINER_TIMEOUT_MS (default 2h) to avoid false positives
const STALE_RUNNING_THRESHOLD_MS = parseInt(process.env.STALE_RUNNING_THRESHOLD_MS || String(2.5 * 60 * 60 * 1000), 10); // Default: 2.5 hours

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

For consistency and readability, it's better to use string literals for the default values, especially since REQUEUE_COOLDOWN_MS already does. This avoids having to mentally compute the values when reading the code.

Suggested change
const STALE_PENDING_THRESHOLD_MS = parseInt(process.env.STALE_PENDING_THRESHOLD_MS || String(5 * 60 * 1000), 10); // Default: 5 min
// Should exceed CONTAINER_TIMEOUT_MS (default 2h) to avoid false positives
const STALE_RUNNING_THRESHOLD_MS = parseInt(process.env.STALE_RUNNING_THRESHOLD_MS || String(2.5 * 60 * 60 * 1000), 10); // Default: 2.5 hours
const STALE_PENDING_THRESHOLD_MS = parseInt(process.env.STALE_PENDING_THRESHOLD_MS || '300000', 10); // Default: 5 min
// Should exceed CONTAINER_TIMEOUT_MS (default 2h) to avoid false positives
const STALE_RUNNING_THRESHOLD_MS = parseInt(process.env.STALE_RUNNING_THRESHOLD_MS || '9000000', 10); // Default: 2.5 hours
References
  1. This suggestion is a valid code quality improvement that should be addressed immediately within the current pull request, rather than being deferred.

Comment thread worker/src/docker-runner.ts Outdated
const SYSTEM_RESERVE_MB = 2048;
const CONTAINER_TIMEOUT_MS = 2 * 60 * 60 * 1000; // 2 hours (4 sequential games per container)
const SYSTEM_RESERVE_MB = parseInt(process.env.SYSTEM_RESERVE_MB || '2048', 10);
const CONTAINER_TIMEOUT_MS = parseInt(process.env.CONTAINER_TIMEOUT_MS || String(2 * 60 * 60 * 1000), 10); // Default: 2 hours

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

For consistency with other newly configurable constants in this file (SYSTEM_RESERVE_MB, CPUS_PER_SIM), it would be more readable to use a string literal for the default value of CONTAINER_TIMEOUT_MS.

Suggested change
const CONTAINER_TIMEOUT_MS = parseInt(process.env.CONTAINER_TIMEOUT_MS || String(2 * 60 * 60 * 1000), 10); // Default: 2 hours
const CONTAINER_TIMEOUT_MS = parseInt(process.env.CONTAINER_TIMEOUT_MS || '7200000', 10); // Default: 2 hours
References
  1. This suggestion is a valid code quality improvement that should be addressed immediately within the current pull request, rather than being deferred.

Addresses Gemini review feedback — replace `String(N * M * ...)` expressions
with pre-computed string literals ('300000', '9000000', '7200000') for better
readability. The inline comments already document the human-readable durations.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@TytaniumDev
TytaniumDev merged commit 5a57805 into main Feb 27, 2026
3 checks passed
@TytaniumDev
TytaniumDev deleted the chore/configurable-constants branch February 27, 2026 07:26
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.

1 participant