Your always-on AI coworkers that move between text, calls, and Slack.
TypeScript
fix: report a Dot turn that hits the time limit as an error (#85)
Charan Rathore71efd82cd883
diff --git a/src/server/dot-agent.ts b/src/server/dot-agent.tsindex 27252ca..0ffca7f 100644--- a/src/server/dot-agent.ts+++ b/src/server/dot-agent.ts@@ -25,6 +25,7 @@ const channelError = () => ({message:'OpenDots could not complete this request. Please check the app and try again.',});+const TURN_TIME_LIMIT_MS = 90_000;export class DotAgent extends AbstractAgent {private inner?: BuiltInAgent;private controller?: AbortController;@@ -56,7 +57,16 @@ export class DotAgent extends AbstractAgent {this.controller = controller;let subscription: { unsubscribe(): void } | undefined;let watcher: ReturnType<typeof setInterval> | undefined;- const timeout = setTimeout(() => this.abortRun(), 90_000);+ let timedOut = false;+ let finished = false;+ const timeout = setTimeout(() => {+ timedOut = true;+ this.abortRun();+ }, TURN_TIME_LIMIT_MS);+ const timeLimitError = () => ({+ type: EventType.RUN_ERROR,+ message: `This turn reached the ${TURN_TIME_LIMIT_MS / 1000} second time limit and was stopped. Try a smaller request.`,+ });try {const dot = this.workspace.dot(this.dotId);if (!dot) throw new Error('Specialist Dot not found.');@@ -323,19 +333,34 @@ export class DotAgent extends AbstractAgent {forwardedProps: {},}).subscribe({- next: (event) =>+ next: (event) => {+ if (+ event.type === EventType.RUN_ERROR ||+ event.type === EventType.RUN_FINISHED+ )+ finished = true;subscriber.next(this.channel && event.type === EventType.RUN_ERROR? channelError(): event,- ),+ );+ },error: (error: unknown) => {if (this.channel) {subscriber.next(channelError());subscriber.complete();+ } else if (timedOut && !finished) {+ subscriber.next(timeLimitError());+ subscriber.complete();} else subscriber.error(error);},- complete: () => subscriber.complete(),+ complete: () => {+ if (timedOut && !finished)+ subscriber.next(+ this.channel ? channelError() : timeLimitError(),+ );+ subscriber.complete();+ },});} catch (error) {subscriber.next(diff --git a/tests/tanstack-agent.test.ts b/tests/tanstack-agent.test.tsindex 055d669..c3c8c73 100644--- a/tests/tanstack-agent.test.ts+++ b/tests/tanstack-agent.test.ts@@ -272,3 +272,35 @@ it('tells the model the current time so scheduled runs do not invent one', asyncvi.useRealTimers();}});++it('reports a turn that hits the time limit as a RUN_ERROR instead of ending silently', async () => {+ vi.useFakeTimers();+ try {+ const f = fixture();+ vi.spyOn(globalThis, 'fetch').mockImplementation(+ (_url, init) =>+ new Promise((_resolve, reject) => {+ init?.signal?.addEventListener(+ 'abort',+ () => reject(init.signal?.reason),+ {+ once: true,+ },+ );+ }),+ );+ const finished = lastValueFrom(f.agent.run(f.input).pipe(toArray()));+ await vi.advanceTimersByTimeAsync(90_001);+ const events = await finished;+ expect(events).toEqual(+ expect.arrayContaining([+ expect.objectContaining({+ type: EventType.RUN_ERROR,+ message: expect.stringMatching(/time limit/i),+ }),+ ]),+ );+ } finally {+ vi.useRealTimers();+ }+});