Repository navigation
fix(worker): propagate concurrency override via claim-sim response - #173
Conversation
Runtime override changes didn't reach workers that don't have WORKER_API_URL reachable from the API (push /config path fails), and since #150 dropped per-heartbeat reads, the worker would keep its startup-loaded value until restart. Piggyback the current override on the existing claim-sim poll as the X-Max-Concurrent-Override header. Worker applies it on every poll, so changes propagate within one poll interval (~3s) without requiring externally-reachable worker APIs. Co-Authored-By: Claude Opus 4.7 <[email protected]>
|
@claude do a code review |
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 addresses an issue where worker concurrency settings were not being applied to running workers due to network reachability constraints. By piggybacking the concurrency override onto the existing simulation polling mechanism, the system now ensures that configuration changes are picked up by workers within a single poll interval, regardless of their network environment. Highlights
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. Footnotes
|
|
Claude finished @TytaniumDev's task in 1m 52s —— View job Code Review
Overall this is a clean, pragmatic fix. The approach is solid — piggybacking on a frequent, already-authenticated poll rather than requiring externally-reachable worker APIs. A few observations below, ordered by severity.
|
There was a problem hiding this comment.
Code Review
This pull request implements a fallback mechanism for propagating concurrency overrides to workers using the X-Max-Concurrent-Override header in the claim-sim response. This ensures that workers behind NAT or without a reachable API URL can still receive runtime configuration changes. The changes include documentation updates, server-side header injection, and client-side header parsing. Feedback was provided regarding an inconsistency in the worker's parsing logic, where a hardcoded maximum value of 20 was applied to the override, potentially restricting valid configurations on high-performance machines.
| return; | ||
| } | ||
| const n = parseInt(header, 10); | ||
| if (Number.isInteger(n) && n >= 1 && n <= 20) { |
There was a problem hiding this comment.
The concurrency override is hardcoded to a maximum of 20 here, but the applyOverride function (line 490) does not have this restriction and only enforces a minimum of 1. This creates an inconsistency between the push-based /config path and this new header-based path. On high-core machines, a user might legitimately want to set concurrency higher than 20. Consider removing this upper bound to match the behavior of applyOverride.
| if (Number.isInteger(n) && n >= 1 && n <= 20) { | |
| if (Number.isInteger(n) && n >= 1) { |
References
- Address valid code quality suggestions immediately within the current pull request, even if it expands the scope. Do not defer them to a follow-up task.
There was a problem hiding this comment.
Code Review - Changes Requested
The implementation is logically correct and the design is sound — the best-effort .catch(() => undefined) properly isolates store failures from claim failures, the 'none'/integer encoding is consistent between emitter and parser, the 1–20 range check in applyOverrideFromHeader matches the write-time validation in api/app/api/workers/[id]/route.ts, and DATA_FLOW.md is updated.
Issue: Missing test coverage for new behavior (CLAUDE.md requirement)
CLAUDE.md states: "Ensure test coverage exists for the part of the flow you changed — see the test files listed in DATA_FLOW.md." DATA_FLOW.md was updated in this PR to document the X-Max-Concurrent-Override header as part of the claim-sim flow, which triggers this requirement.
The PR lists claim-sim.test.ts (6/6 pass) as evidence of coverage, but those 6 tests only exercise claimNextSim — the SQLite DB function — and were written before this change. They do not touch the route handler at all. The two new code paths have no test coverage:
-
Route handler header emission (
api/app/api/jobs/claim-sim/route.ts): the logic that readsoverrideResultand builds theX-Max-Concurrent-Overrideheader (including theoverrideResult == null ? 'none' : String(overrideResult)encoding). Specifically untested: the 204 path with header, the 200 path with header, and the best-effort omission when the store call throws. -
applyOverrideFromHeader(worker/src/worker.ts, line 526): the parsing logic for'none'→ clear override, valid integer string → apply, and malformed/out-of-range → ignore.
Please add tests covering these paths. The route handler behavior could be covered by extending claim-sim.test.ts (or a new route-level test), and applyOverrideFromHeader is a pure function that is straightforward to unit-test.
- Extract header encode/parse into pure modules (api/lib/override-header.ts and worker/src/override.ts) with unit tests covering null/'none'/valid integer/malformed cases - Drop the 1-20 upper bound from the worker parser per Gemini review; the value is already validated on write by PATCH /api/workers/:id and the /config endpoint, so the parser trusts any positive integer from the API (matches applyOverride's contract) - Wire the new worker tests into scripts/test.sh and api/package.json so they run in CI Co-Authored-By: Claude Opus 4.7 <[email protected]>
There was a problem hiding this comment.
Code Review - Approved
No issues found. Checked for bugs, security issues, and CLAUDE.md compliance.
The fallback override-via-poll-header feature is implemented correctly:
- Encode/decode separation:
api/lib/override-header.tsandworker/src/override.tsare independent packages with matching wire formats; duplication is intentional and correct. - Type safety:
overrideResultisnumber | null | undefined; the!== undefinedguard correctly narrows tonumber | nullbefore callingencodeOverrideHeader, matching its signature. - Best-effort header:
.catch(() => undefined)ensures a store failure never orphans a successful claim — the worker simply keeps its last-known override. - Header applied on 200 and 204: Correct — override propagates even when there is no work to claim.
- Parse strictness:
String(n) === headerround-trip check inparseOverrideHeadercorrectly rejects trailing garbage and non-integer inputs. - Test coverage: Both encoder and parser have unit tests; new tests are wired into
api/package.json,worker/package.json, andscripts/test.sh. tsxdependency: Already present inworker/package.json(^4.7.0); newtest:unitscript works.- DATA_FLOW.md updated: Per CLAUDE.md requirement, step 3 documents the new header behavior.
Summary
/configendpoint — which requiresWORKER_API_URLto be set and reachable from Cloud Run.setup-worker.shnever configuresWORKER_API_URL, and user-hosted workers are typically behind NAT anyway, so push silently fails (pushResult: 'no_url') and the worker keeps its startup value until restart./api/jobs/claim-simpoll response as theX-Max-Concurrent-Overrideheader (value: positive integer, ornone). The worker applies it via the existingapplyOverridepath on every poll, so changes propagate within one poll interval (~3s) without requiring externally-reachable worker APIs..catch(() => undefined)) — a transient Firestore hiccup omits the header rather than orphaning a successful claim. Push/configpath is untouched and still works when available.Test plan
npm run lint --prefix apipassesnpx tsc --noEmitinworker/passesnpx tsx lib/claim-sim.test.ts— 6/6 passkillExcessSimulationspath🤖 Generated with Claude Code