Skip to content

⚡ Bolt: Avoid redundant API and DB calls for terminal sessions - #77

Open
parvezk wants to merge 1 commit into
mainfrom
bolt-optimize-polling-9496501079347556303
Open

⚡ Bolt: Avoid redundant API and DB calls for terminal sessions#77
parvezk wants to merge 1 commit into
mainfrom
bolt-optimize-polling-9496501079347556303

Conversation

@parvezk

@parvezk parvezk commented Jul 29, 2026

Copy link
Copy Markdown
Owner

💡 What:

  • Updated src/commands/status.ts to skip fetching live status if the session is already marked completed or failed.
  • Updated web/app/api/sessions/route.ts and web/app/api/sessions/[id]/route.ts to conditionally skip writing back to the DB (patchSession) if a terminal status hasn't changed.
  • Replaced a useEffect with a conditional render phase update (setPrevSessionId) in web/components/session-drawer.tsx to fix a React warning and avoid a wasted commit phase.

🎯 Why:
PolyAgent sessions have terminal states (completed or failed). Continually polling the API and/or writing unchanged terminal states back to the Supabase database is a waste of network bandwidth and DB connection time.

📊 Impact:

  • Significant reduction in database writes (UPDATE queries) on the /api/sessions polling interval for users with lots of finished sessions.
  • Reduced external API (vendor) load from the CLI status command.
  • Avoids an unnecessary React re-render when switching sessions in the drawer.

🔬 Measurement:

  • Monitored CLI and Web behavior.
  • Tests passed.
  • pnpm lint in the web directory now passes cleanly without the set-state-in-effect error.

PR created automatically by Jules for task 9496501079347556303 started by @parvezk

- Skips external API calls in the CLI for terminal states (`completed` or `failed`).
- Skips redundant `patchSession` database writes in the web API for sessions that are already in an unchanged terminal state.
- Fixed a cascading re-render React warning in `session-drawer.tsx` by using a render-phase state update instead of `useEffect`.

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
@vercel

vercel Bot commented Jul 29, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
polyagent Ready Ready Preview, Comment Jul 29, 2026 8:34am

@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@cursor

cursor Bot commented Jul 29, 2026

Copy link
Copy Markdown

Bugbot is not enabled for your account, so this pull request was not reviewed.

Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a8cd7a1a96

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/commands/status.ts
store.upsert({ ...s, status: live.status, lastPolled: updatedAt });
} catch {
// keep last-known status
if (status !== "completed" && status !== "failed") {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Keep polling sessions that follow-ups can restart

When a user sends a follow-up after a session has been recorded as completed, followupCommand accepts it without changing the stored status, and adapters such as Cursor and Jules send the message to the same agent/session ID. This guard then prevents every subsequent status and status --watch call from querying the vendor, so resumed work remains permanently displayed as completed; either continue polling these sessions or reset their stored status after a successful follow-up.

Useful? React with 👍 / 👎.

const isUnchangedTerminal = isTerminal && s.status === newStatus;

if (!isUnchangedTerminal) {
await patchSession(s.id, { status: newStatus, last_polled: newLastUpdate });

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Assign live status before awaiting persistence

When the Supabase update rejects after the vendor lookup succeeds, such as during a transient network failure, this await throws before status and lastUpdate receive the successfully fetched values, so the response reports stale database state while potentially including the new summary. The previous ordering preserved the live response even when persistence failed, and the same regression exists in the detail route; assign the live fields before awaiting patchSession, or catch persistence failures separately.

Useful? React with 👍 / 👎.

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.

1 participant