Skip to content

Commit 2a89306

Browse files
committed
fix(gateway): budget repeated shared-store prewarm
1 parent 1f42783 commit 2a89306

2 files changed

Lines changed: 19 additions & 11 deletions

File tree

‎src/config/sessions/combined-store-gateway.ts‎

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -229,18 +229,19 @@ export function canPrewarmCombinedSessionStoresForGateway(
229229
cfg: OpenClawConfig,
230230
params: { agentIds: readonly string[]; maxRows: number },
231231
): boolean {
232-
const resolvedTargets = params.agentIds.flatMap((agentId) => {
233-
const resolved = resolveGatewaySessionStoreTargets(cfg, { agentId });
234-
return [...resolved.durableTargets, ...resolved.incognitoTargets];
235-
});
236-
const targets = dedupeSessionStoreTargetsBySqliteTarget(resolvedTargets, {
237-
defaultAgentId: normalizeAgentId(resolveDefaultAgentId(cfg)),
238-
});
232+
const defaultAgentId = normalizeAgentId(resolveDefaultAgentId(cfg));
239233
let totalRows = 0;
240-
for (const target of targets) {
241-
totalRows += countSessionEntryRowsReadOnly(target);
242-
if (totalRows > params.maxRows) {
243-
return false;
234+
for (const agentId of params.agentIds) {
235+
const resolved = resolveGatewaySessionStoreTargets(cfg, { agentId });
236+
const projectionTargets = dedupeSessionStoreTargetsBySqliteTarget(
237+
[...resolved.durableTargets, ...resolved.incognitoTargets],
238+
{ defaultAgentId },
239+
);
240+
for (const target of projectionTargets) {
241+
totalRows += countSessionEntryRowsReadOnly(target);
242+
if (totalRows > params.maxRows) {
243+
return false;
244+
}
244245
}
245246
}
246247
return true;

‎src/gateway/session-utils.subagent.test.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1408,6 +1408,13 @@ describe("loadCombinedSessionStoreForGateway includes disk-only agents (#32804)"
14081408
"main",
14091409
);
14101410

1411+
expect(
1412+
canPrewarmCombinedSessionStoresForGateway(cfg, {
1413+
agentIds: ["main", "ops"],
1414+
maxRows: 1,
1415+
}),
1416+
).toBe(false);
1417+
14111418
const { diagnostics, store } = loadCombinedSessionStoreForGateway(cfg);
14121419
expect(store["agent:main:main"]?.sessionId).toBe("s-main-unscoped");
14131420
expect(store["agent:ops:main"]).toBeUndefined();

0 commit comments

Comments
 (0)