⚡ Bolt: Avoid redundant API and DB calls for terminal sessions - #77
⚡ Bolt: Avoid redundant API and DB calls for terminal sessions#77parvezk wants to merge 1 commit into
Conversation
- 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>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
👋 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 New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
|
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. |
There was a problem hiding this comment.
💡 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".
| store.upsert({ ...s, status: live.status, lastPolled: updatedAt }); | ||
| } catch { | ||
| // keep last-known status | ||
| if (status !== "completed" && status !== "failed") { |
There was a problem hiding this comment.
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 }); |
There was a problem hiding this comment.
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 👍 / 👎.
💡 What:
src/commands/status.tsto skip fetching live status if the session is already markedcompletedorfailed.web/app/api/sessions/route.tsandweb/app/api/sessions/[id]/route.tsto conditionally skip writing back to the DB (patchSession) if a terminal status hasn't changed.useEffectwith a conditional render phase update (setPrevSessionId) inweb/components/session-drawer.tsxto fix a React warning and avoid a wasted commit phase.🎯 Why:
PolyAgent sessions have terminal states (
completedorfailed). 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:
/api/sessionspolling interval for users with lots of finished sessions.statuscommand.🔬 Measurement:
pnpm lintin the web directory now passes cleanly without theset-state-in-effecterror.PR created automatically by Jules for task 9496501079347556303 started by @parvezk