Skip to content

Commit 79fe1b1

Browse files
Pigbibiclaude
andcommitted
fix(worker): read RUNTIME_TARGET_JSON first with retry, bypass cache
Promise.all parallel reads can hit GitHub secondary rate limits, causing RUNTIME_TARGET_JSON to return empty. Read it separately before the parallel batch, and retry with skipCache on empty. Co-Authored-By: Claude <noreply@anthropic.com>
1 parent e3222b2 commit 79fe1b1

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

web/strategy-switch-console/worker.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -694,8 +694,9 @@ async function loadCurrentStrategies(accountOptions, env) {
694694
const repositories = platformRepositories(env);
695695

696696
const variableCache = new Map();
697-
const readVariable = (repository, scope, githubEnvironment, name) => {
697+
const readVariable = (repository, scope, githubEnvironment, name, { skipCache = false } = {}) => {
698698
const cacheKey = [repository, scope, githubEnvironment || "", name].join("|");
699+
if (skipCache) variableCache.delete(cacheKey);
699700
if (!variableCache.has(cacheKey)) {
700701
variableCache.set(cacheKey, fetchGithubVariable(token, repository, scope, githubEnvironment, name));
701702
}
@@ -867,6 +868,12 @@ async function resolveCurrentStrategyForAccount({ platform, option, optionsCount
867868
});
868869
// Await in parallel: each reads a different variable so
869870
// there is no risk of hammering the same GitHub API endpoint.
871+
// Read RUNTIME_TARGET_JSON first with retry — parallel reads inside
872+
// Promise.all can hit GitHub secondary rate limits and return empty.
873+
let runtimeTargetValue = await readVariable(repository, variableScope, githubEnvironment, "RUNTIME_TARGET_JSON");
874+
if (!runtimeTargetValue) {
875+
runtimeTargetValue = await readVariable(repository, variableScope, githubEnvironment, "RUNTIME_TARGET_JSON", { skipCache: true });
876+
}
870877
const [
871878
reservedCashPayload,
872879
incomeLayerPayload,
@@ -875,7 +882,6 @@ async function resolveCurrentStrategyForAccount({ platform, option, optionsCount
875882
dcaPayload,
876883
ibitZscorePayload,
877884
cashOnlyPayload,
878-
runtimeTargetValue,
879885
] = await Promise.all([
880886
reservedCashPayloadPromise,
881887
incomeLayerPayloadPromise,
@@ -884,7 +890,6 @@ async function resolveCurrentStrategyForAccount({ platform, option, optionsCount
884890
dcaPayloadPromise,
885891
ibitZscorePayloadPromise,
886892
cashOnlyPayloadPromise,
887-
readVariable(repository, variableScope, githubEnvironment, "RUNTIME_TARGET_JSON"),
888893
]);
889894
const runtimeTarget = parseJsonObject(runtimeTargetValue);
890895
const runtimeTargetMatches = runtimeTarget && runtimeTargetMatchesAccount(runtimeTarget, platform, option);

0 commit comments

Comments
 (0)