The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
refactor(desktop): drop the serial-task layer from the MCP log poller
teknium18ac2c147a502
diff --git a/apps/desktop/src/app/skills/mcp-tab.tsx b/apps/desktop/src/app/skills/mcp-tab.tsxindex 263770a5193..020d3e8e2a3 100644--- a/apps/desktop/src/app/skills/mcp-tab.tsx+++ b/apps/desktop/src/app/skills/mcp-tab.tsx@@ -31,7 +31,7 @@ import {testMcpServer} from '@/hermes'import { type Translations, useI18n } from '@/i18n'-import { createSerialTask, startCompletionPoll } from '@/lib/completion-poll'+import { startCompletionPoll } from '@/lib/completion-poll'import { compactNumber } from '@/lib/format'import { brandFor } from '@/lib/mcp-brands'import { estimateServerTokens, serverUsageCount } from '@/lib/mcp-cost'@@ -1726,31 +1726,26 @@ function McpLogs({}) {const [lines, setLines] = useState<null | string[]>(null)// A profile switch reroutes getLogs to the new backend; keying the effect on- // the active profile tears down the old poll (its `cancelled` flag blocks a- // late setLines) so profile A's logs never flash in B.+ // the active profile tears down the old poll (stop suppresses a late+ // publish) so profile A's logs never flash in B.const activeProfile = useStore($activeGatewayProfile)- const readLogs = useMemo(() => createSerialTask(getLogs), [])useEffect(() => {setLines(null)return startCompletionPoll({delayMs: LOG_POLL_MS,- poll: async signal => {+ poll: async () => {const response =source === 'stdio'- ? await readLogs({ file: 'mcp', lines: 500 }, signal)- : await readLogs({ file: 'agent', lines: 300, search: server ?? 'mcp' }, signal)-- if (signal.aborted) {- throw new DOMException('Polling stopped', 'AbortError')- }+ ? await getLogs({ file: 'mcp', lines: 500 })+ : await getLogs({ file: 'agent', lines: 300, search: server ?? 'mcp' })return source === 'stdio' && server ? filterStdioSections(response.lines, server) : response.lines},publish: setLines})- }, [server, source, activeProfile, readLogs])+ }, [server, source, activeProfile])return <LogTail emptyLabel={emptyLabel} lines={lines} />}diff --git a/apps/desktop/src/lib/completion-poll.ts b/apps/desktop/src/lib/completion-poll.tsindex 1822cb04ae5..4a7c647822a 100644--- a/apps/desktop/src/lib/completion-poll.ts+++ b/apps/desktop/src/lib/completion-poll.ts@@ -1,50 +1,33 @@interface CompletionPollOptions<T> {delayMs: number- poll: (signal: AbortSignal) => Promise<T>+ poll: () => Promise<T>publish: (value: T) => void}-/** Serialize a producer across effect lifecycles without publishing stale work. */-export function createSerialTask<Args, Result>(- task: (args: Args) => Promise<Result>-): (args: Args, signal: AbortSignal) => Promise<Result> {- let tail = Promise.resolve()-- return (args, signal) => {- const result = tail.then(() => {- if (signal.aborted) {- throw new DOMException('Task stopped', 'AbortError')- }-- return task(args)- })-- tail = result.then(- () => undefined,- () => undefined- )-- return result- }-}--/** Poll immediately, then wait one full cadence after each request settles. */+/**+ * Poll immediately, then wait one full cadence AFTER each request settles.+ *+ * `setInterval` fires on the wall clock, so a request slower than the cadence+ * overlaps the next one and a stalled backend piles up concurrent requests.+ * Rescheduling from settlement keeps the poll single-flight. The returned stop+ * function drops the pending timer and suppresses a late publish.+ */export function startCompletionPoll<T>({ delayMs, poll, publish }: CompletionPollOptions<T>): () => void {- const controller = new AbortController()+ let stopped = falselet timer: number | undefinedconst run = async () => {try {- const value = await poll(controller.signal)+ const value = await poll()- if (!controller.signal.aborted) {+ if (!stopped) {publish(value)}} catch {// A transient producer failure keeps the previous value visible.}- if (!controller.signal.aborted) {+ if (!stopped) {timer = window.setTimeout(() => void run(), delayMs)}}@@ -52,10 +35,7 @@ export function startCompletionPoll<T>({ delayMs, poll, publish }: CompletionPolvoid run()return () => {- controller.abort()-- if (timer !== undefined) {- window.clearTimeout(timer)- }+ stopped = true+ window.clearTimeout(timer)}}