MCPcopy Create free account
hub / github.com/cursor/plugins / pollLoop

Function pollLoop

orchestrate/skills/orchestrate/scripts/core/agent-manager.ts:1864–1925  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1862 const waitStartedAt = Date.now();
1863
1864 const pollLoop = async (): Promise<RunResult> => {
1865 while (!ac.signal.aborted) {
1866 try {
1867 await sleep(WAIT_WATCHDOG_POLL_INTERVAL_MS, undefined, {
1868 signal: ac.signal,
1869 });
1870 } catch {
1871 return Promise.reject(new Error("watchdog aborted"));
1872 }
1873 if (ac.signal.aborted) break;
1874 let probe: Run;
1875 try {
1876 probe = await Agent.getRun(args.runId, {
1877 runtime: "cloud",
1878 apiKey: args.apiKey,
1879 agentId: args.agentId,
1880 });
1881 } catch {
1882 continue;
1883 }
1884 if (probe.status !== "running") {
1885 return probe.wait();
1886 }
1887 const idleMs = Date.now() - args.lastSseActivityAt.value;
1888 if (idleMs >= WAIT_SSE_IDLE_ATTENTION_MS && !idleEpisodeLogged) {
1889 idleEpisodeLogged = true;
1890 args.logAttention(
1891 `${args.taskLabel}: SSE idle ${idleMs}ms, polled status=running; watchdog still waiting`
1892 );
1893 }
1894 if (idleMs >= STUCK_ESCALATION_MS && !sseStuckEpisodeLogged) {
1895 sseStuckEpisodeLogged = true;
1896 args.logAttention(`${args.taskLabel}: SSE idle ${idleMs}ms; stuck`);
1897 }
1898 const toolCallIdleMs =
1899 Date.now() - (args.lastToolCallAt.value ?? waitStartedAt);
1900 if (
1901 toolCallIdleMs >= WAIT_TOOL_CALL_IDLE_ATTENTION_MS &&
1902 !toolCallIdleEpisodeLogged
1903 ) {
1904 toolCallIdleEpisodeLogged = true;
1905 args.logAttention(
1906 formatToolCallIdleWarning({
1907 taskLabel: args.taskLabel,
1908 idleMs: toolCallIdleMs,
1909 lastToolCallAt: args.lastToolCallAt.value,
1910 waitStartedAt,
1911 })
1912 );
1913 }
1914 if (
1915 toolCallIdleMs >= toolCallStuckThresholdMs() &&
1916 !toolCallStuckEpisodeLogged
1917 ) {
1918 toolCallStuckEpisodeLogged = true;
1919 args.logAttention(
1920 `${args.taskLabel}: tool_call idle ${toolCallIdleMs}ms; stuck`
1921 );

Callers 1

waitRunWithWatchdogFunction · 0.85

Calls 4

sleepFunction · 0.85
toolCallStuckThresholdMsFunction · 0.85
logAttentionMethod · 0.80

Tested by

no test coverage detected