Skip to content

fix: show insights after long-running generation - #1346

Merged
lfnovo merged 4 commits into
lfnovo:mainfrom
justadityaraj:fix/1264-insight-polling
Oct 1, 2026
Merged

lfnovo merged 4 commits into
lfnovo:mainfrom
justadityaraj:fix/1264-insight-polling

Conversation

@justadityaraj

@justadityaraj justadityaraj commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

Context

Insight generation can legitimately take longer than four minutes with local models and large sources. The source detail UI stopped checking the command after 120 attempts, so a completed insight remained hidden until the user navigated away and returned.

Fixes #1264

Changes

  • Keep checking insight commands while their status remains non-terminal; stop on worker terminal states or three consecutive status-request failures.
  • Pass an AbortSignal through status requests, cancel on unmount or replacement, and re-check cancellation after the terminal refetch.
  • Perform a final insight refetch for terminal success or failure, update source query data, and surface terminal failures with a toast.
  • Cover polling beyond the previous limit, terminal/error stops, sanitized status-error logging, unmount races, and backend error display with API and component tests.

User impact

Long-running insights now appear in the open Insights tab as soon as generation completes. Leaving the source stops its browser-side polling, and failed jobs no longer end silently.

Verification

  • npm test — 27 test files passed, 164 tests passed.
  • npm run lint — 0 errors; 7 existing warnings in unchanged files.
  • npm run build — production build, TypeScript check, and static page generation passed.
  • Browser reproduction at 1440×1000 with identical mocked responses — the base build stopped after 120 pending checks and continued to show the empty state; this branch completed check 121, refetched, and rendered the insight without navigation.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)

How Has This Been Tested?

  • Tested locally with development setup
  • Added new unit tests
  • Existing frontend tests pass
  • Manual browser testing performed

Design Alignment

  • Simplicity Over Features
  • Async-First for Performance

The existing polling path remains in place; this removes its arbitrary duration limit and gives it lifecycle cancellation.

Checklist

Code Quality

  • My code follows TypeScript best practices
  • I have performed a self-review of the complete diff
  • I have commented the lifecycle behavior where appropriate
  • My changes generate no new warnings or errors

Testing

  • I have added tests that prove the fix is effective
  • New and existing unit tests pass locally
  • I ran frontend linting
  • I ran TypeScript checking through the production build

Documentation, Database, and Breaking Changes

  • No documentation update is needed
  • No database change or migration is needed
  • No API contract or breaking change is introduced

Screenshots

Before: polling stops after 120 checks After: the completed insight appears on check 121
The Insights tab remains empty after the old polling limit The completed Paper Analysis insight appears without navigation

Pre-Submission Verification

Review in cubic

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 3 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread frontend/src/lib/api/insights.ts Resolved
Comment thread frontend/src/lib/api/insights.test.ts Resolved

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 4 files (changes from recent commits).

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread frontend/src/lib/api/insights.ts Resolved
Comment thread frontend/src/lib/api/insights.ts Resolved

@lfnovo lfnovo left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified: polling now runs until a terminal status, is cancelled on unmount or replacement via AbortSignal, stops after three consecutive status errors, refetches the source on completion and surfaces failures in a toast. waitForCommand has a single caller, so the return-type change is contained. Thanks @justadityaraj — this unblocks long local-model insights (#1264).

@lfnovo
lfnovo enabled auto-merge (squash) October 1, 2026 01:46
@lfnovo
lfnovo merged commit 4e390a7 into lfnovo:main Oct 1, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Insights tab stops polling after 4 minutes and never shows the finished insight

2 participants