Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ export const FAST_AGENT_MODEL_ROLE = 'orchestration' as const;
// responses, short enough that a crashed turn self-heals the session status.
// Streaming touch points re-extend it so long turns keep the lease fresh.
export const FAST_RESPONDING_LEASE_MS = 15 * 60 * 1000;
// Assistant-message persists also extend the lease, but a turn can spend
// longer than the lease inside tool calls or a streaming stretch without
// persisting one; the time-based renewal keeps the lease fresh for exactly
// as long as the turn is actually executing.
export const FAST_RESPONDING_LEASE_RENEW_MS = FAST_RESPONDING_LEASE_MS / 3;
export const FAST_AGENT_GITHUB_MCP_PATH = '/api/mcp-routing/github';
export const FAST_AGENT_TASKS_API_PATH = '/api/mcp/tasks';
export const FAST_AGENT_ENVIRONMENTS_API_PATH = '/api/mcp/environments';
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import {
advanceSessionNotifiedCursor,
advanceSessionReadCursor,
getSessionForFastConversation,
gt,
isNotNull,
isNull,
lt,
or,
Expand Down Expand Up @@ -207,6 +209,33 @@ export async function markFastAgentInferenceRetryNoticeInterruption(
return stamped.length > 0;
}

/**
* Extend the responding lease with the fence in the statement itself: only a
* lease that is still live is extended, so a stale renewal from an owner that
* lost the conversation mid-write can never resurrect a lease a settlement
* or successor already cleared. No read precedes the write, which removes
* the check-then-write window entirely. Returns whether a lease was renewed.
*/
export async function renewFastSessionRespondingLease(
fastConversationId: string,
): Promise<boolean> {
const renewed = await db
.update(sessions)
.set({
respondingUntil: new Date(Date.now() + FAST_RESPONDING_LEASE_MS),
updatedAt: new Date(),
})
.where(
and(
eq(sessions.fastConversationId, fastConversationId),
isNotNull(sessions.respondingUntil),
gt(sessions.respondingUntil, new Date()),
),
)
.returning({ id: sessions.id });
return renewed.length > 0;
}

export async function reconcileExpiredFastAgentInferenceRetryNotices(
limit = 100,
): Promise<number> {
Expand Down
Loading
Loading