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.

Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ import { buildFastAgentCodeModeServerNames } from './fast-agent-tool-policy';
*/
const INTEGRATION_TOOL_APPROVAL_POLL_MS = 1_500;
const SESSION_PRESENCE_LOOKUP_TIMEOUT_MS = 2_000;
/**
* An open session page renews its presence every 10 seconds, and a page that
* just opened can briefly drop it. The owner counts as away only when a
* second lookup, a full renewal later, still finds nobody.
*/
const SESSION_PRESENCE_RECHECK_MS = 11_000;

async function isFastAgentLaunchedTask(
sessionId: string,
Expand Down Expand Up @@ -427,6 +433,14 @@ export function createFastAgentToolApprovalBridge(input: {

const ownerIsPresent = async (): Promise<boolean> => {
if (isFastAgentApprovalChatSurface(input.surface)) return true;
if (await lookUpOwnerPresence()) return true;
await new Promise((resolve) => {
const timer = setTimeout(resolve, SESSION_PRESENCE_RECHECK_MS);
timer.unref?.();
});
return lookUpOwnerPresence();
};
const lookUpOwnerPresence = async (): Promise<boolean> => {
let timeout: ReturnType<typeof setTimeout> | undefined;
try {
return await Promise.race([
Expand Down

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

18 changes: 18 additions & 0 deletions packages/sdk/src/server/lib/task-tool-approvals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ async function publishTaskToolApproval(input: {
}

const SESSION_PRESENCE_LOOKUP_TIMEOUT_MS = 2_000;
/**
* An open session page renews its presence every 10 seconds, and a page that
* just opened can briefly drop it. The owner counts as away only when a
* second lookup, a full renewal later, still finds nobody.
*/
const SESSION_PRESENCE_RECHECK_MS = 11_000;

async function isTaskSessionOwnerPresent(input: {
sessionId: string;
Expand All @@ -122,6 +128,18 @@ async function isTaskSessionOwnerPresent(input: {
) {
return true;
}
if (await lookUpTaskSessionOwnerPresence(input)) return true;
await new Promise((resolve) => {
const timer = setTimeout(resolve, SESSION_PRESENCE_RECHECK_MS);
timer.unref?.();
});
return lookUpTaskSessionOwnerPresence(input);
}

async function lookUpTaskSessionOwnerPresence(input: {
sessionId: string;
userId: string;
}): Promise<boolean> {
let timeout: ReturnType<typeof setTimeout> | undefined;
try {
return await Promise.race([
Expand Down
Loading