Repository navigation
chore: make hardcoded timeouts and constants configurable via env vars - #79
Conversation
#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]>
Summary of ChangesHello, 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
Changelog
Activity
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
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.
| 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 |
There was a problem hiding this comment.
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.
| 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
- This suggestion is a valid code quality improvement that should be addressed immediately within the current pull request, rather than being deferred.
| 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 |
There was a problem hiding this comment.
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.
| 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
- 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]>
Summary
New environment variables:
CONTAINER_TIMEOUT_MSSYSTEM_RESERVE_MBCPUS_PER_SIMAPI_TIMEOUT_MSHEARTBEAT_INTERVAL_MSSTALE_PENDING_THRESHOLD_MSSTALE_RUNNING_THRESHOLD_MSREQUEUE_COOLDOWN_MSAddresses architecture issues #6 and #9 from
docs/ARCHITECTURE_ISSUES.md.Test plan
parseInt(process.env.X || 'default', 10)patternnpm run lint --prefix apipassesnpm run build --prefix apipasses🤖 Generated with Claude Code