Skip to content

Commit 27536bf

Browse files
committed
fix(sdk): an empty or null concurrency value is rejected, not silently dropped
Truthiness guards at the trigger call sites swallowed falsey concurrency values before validation, so a JavaScript caller passing an empty string or null started the session without the intended limits. Only undefined counts as absent now; everything else flows into validation and throws.
1 parent bd11832 commit 27536bf

5 files changed

Lines changed: 25 additions & 4 deletions

File tree

‎packages/trigger-sdk/src/v3/ai.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11822,7 +11822,7 @@ function createChatStartSessionAction<TChat extends AnyTask = AnyTask>(
1182211822
...(options?.triggerConfig?.queue || params.triggerConfig?.queue
1182311823
? { queue: params.triggerConfig?.queue ?? options?.triggerConfig?.queue }
1182411824
: {}),
11825-
...(concurrency ? triggerConcurrencyBody(concurrency) : {}),
11825+
...(concurrency !== undefined ? triggerConcurrencyBody(concurrency) : {}),
1182611826
...(concurrencyKey !== undefined ? { concurrencyKey } : {}),
1182711827
tags,
1182811828
...(maxAttempts !== undefined ? { maxAttempts } : {}),

‎packages/trigger-sdk/src/v3/chat-client.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,7 @@ export class AgentChat<TAgent = unknown> {
672672
},
673673
...(this.triggerConfigDefault?.machine ? { machine: this.triggerConfigDefault.machine } : {}),
674674
...(this.triggerConfigDefault?.queue ? { queue: this.triggerConfigDefault.queue } : {}),
675-
...(this.triggerConfigDefault?.concurrency
675+
...(this.triggerConfigDefault?.concurrency !== undefined
676676
? triggerConcurrencyBody(this.triggerConfigDefault.concurrency)
677677
: {}),
678678
...(this.triggerConfigDefault?.concurrencyKey !== undefined

‎packages/trigger-sdk/src/v3/chat-server.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ async function openHandoverSession(opts: {
545545
},
546546
...(opts.triggerConfig?.machine ? { machine: opts.triggerConfig.machine } : {}),
547547
...(opts.triggerConfig?.queue ? { queue: opts.triggerConfig.queue } : {}),
548-
...(opts.triggerConfig?.concurrency
548+
...(opts.triggerConfig?.concurrency !== undefined
549549
? triggerConcurrencyBody(opts.triggerConfig.concurrency)
550550
: {}),
551551
...(opts.triggerConfig?.concurrencyKey !== undefined

‎packages/trigger-sdk/src/v3/concurrency-shared.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
export function triggerConcurrencyBody(concurrency: string | string[] | undefined): {
1212
concurrency?: string[];
1313
} {
14-
if (!concurrency) {
14+
if (concurrency === undefined) {
1515
return {};
1616
}
1717
const limits = Array.isArray(concurrency) ? concurrency : [concurrency];

‎packages/trigger-sdk/src/v3/createStartSessionAction.test.ts‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,27 @@ describe("chat.createStartSessionAction — runtime", () => {
211211
expect(lastStartBody).toBeUndefined();
212212
});
213213

214+
it("rejects an empty-string concurrency instead of silently dropping it", async () => {
215+
installStartFixture();
216+
217+
const emptyDefault = chat.createStartSessionAction("fake-chat", {
218+
triggerConfig: { concurrency: "" as unknown as string[] },
219+
});
220+
await expect(emptyDefault({ chatId: "chat-empty-limit" })).rejects.toThrow(
221+
/non-empty strings/
222+
);
223+
224+
const emptyPerCall = chat.createStartSessionAction("fake-chat");
225+
await expect(
226+
emptyPerCall({
227+
chatId: "chat-empty-limit-2",
228+
triggerConfig: { concurrency: "" as unknown as string[] },
229+
})
230+
).rejects.toThrow(/non-empty strings/);
231+
232+
expect(lastStartBody).toBeUndefined();
233+
});
234+
214235
it("server-mints override tokens for additional API keys", async () => {
215236
const requests: Array<{ url: string; body: unknown }> = [];
216237
const start = chat.createStartSessionAction("fake-chat", {

0 commit comments

Comments
 (0)