Skip to content

Commit faf7888

Browse files
committed
fix(webapp): reject create on closed sessions with 409
When the upsert path returns a previously-closed row, return 409 before ensureRunForSession fires. Otherwise we'd trigger a fresh run on a closed session that can't receive .in input (append handler rejects writes to closed sessions), wasting compute on a run that exits the moment it tries to read. close is one-way; callers must use a different externalId to start a new session.
1 parent cf67175 commit faf7888

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

apps/webapp/app/routes/api.v1.sessions.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,19 @@ const { action } = createActionApiRoute(
164164
});
165165
}
166166

167+
// Reject create on a closed session. The upsert path will return
168+
// an already-closed row when the caller reuses an externalId, and
169+
// without this guard `ensureRunForSession` would trigger a fresh
170+
// run that can't receive `.in` input (the append handler 409s on
171+
// closed sessions). Force the caller to use a different externalId
172+
// — `close` is one-way.
173+
if (session.closedAt) {
174+
return json(
175+
{ error: "Session is closed; use a different externalId to create a new session" },
176+
{ status: 409 }
177+
);
178+
}
179+
167180
// Session is task-bound — every session has a live run by
168181
// construction. `ensureRunForSession` is idempotent: on the
169182
// cached path it sees `currentRunId` is alive and returns it

0 commit comments

Comments
 (0)