Skip to content

fix(cua): make session.stop() idempotent on repeated call#156

Merged
masnwilliams merged 1 commit intohypeship/unified-cua-templatefrom
hypeship/fix-session-stop-idempotent
May 5, 2026
Merged

fix(cua): make session.stop() idempotent on repeated call#156
masnwilliams merged 1 commit intohypeship/unified-cua-templatefrom
hypeship/fix-session-stop-idempotent

Conversation

@masnwilliams
Copy link
Copy Markdown
Contributor

@masnwilliams masnwilliams commented May 5, 2026

Summary

Stacks on top of the unified CUA template branch. Addresses the new High-Severity Cursor Bugbot finding on PR #143's latest scan: stop() throws on repeated call instead of being a no-op.

Background

PR #155 moved the session-state reset (_sessionId = null, …) into the finally so that a thrown replay-stop or browser-delete error wouldn't leave stale state behind. That fix was correct, but it exposed a latent bug: stop() opens with const info = this.info (TS) / info = self.info (Py), and the info getter delegates to the sessionId property, which raises when _sessionId is null. So once PR #155 reliably cleared _sessionId on the first call, the caller's error-path retry would hit the throwing getter and mask the original exception — exactly the failure mode PR #155 was meant to prevent.

Fix

stop() now:

  1. Short-circuits at the top with a sentinel SessionInfo when no session is active — never touches the throwing getter.
  2. Builds the live-session info from local fields directly so the body never depends on this.info / self.info either.

Symmetric in TS (session.ts) and Python (session.py).

Test plan

  • go build ./...
  • go test ./pkg/create/...
  • Force a replay-stop failure (e.g. delete the replay out-of-band, or pass an invalid replay id) and confirm calling session.stop() twice from the caller's error path no longer raises and the original error surfaces.

Note

Medium Risk
Touches session shutdown/cleanup logic in both Python and TypeScript templates; while small, mistakes could lead to leaked browser sessions or masked errors during teardown.

Overview
KernelBrowserSession.stop() in both pkg/templates/python/cua/session.py and pkg/templates/typescript/cua/session.ts is updated to be idempotent.

It now short-circuits when no active session exists (returning a sentinel SessionInfo without reading info/sessionId), and builds the returned SessionInfo directly from internal fields so teardown can’t fail due to accessing a getter after state has been cleared.

Reviewed by Cursor Bugbot for commit db0bdea. Bugbot is set up for automated code reviews on this repo. Configure here.

After PR #155 reset session state inside the finally, a follow-up stop()
from the caller's error path reliably hit the throwing 'sessionId'
getter via 'this.info' / 'self.info' (info accesses sessionId, which
raises 'Session not started' when _sessionId is null). The exception
masked the original error.

stop() now short-circuits with a snapshot of the cleared state when no
session is active, and builds the live-session info from local fields
without going through the throwing getter.

Applied symmetrically in TS and Python.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@masnwilliams masnwilliams marked this pull request as ready for review May 5, 2026 01:35
@firetiger-agent
Copy link
Copy Markdown

Firetiger deploy monitoring skipped

This PR didn't match the auto-monitor filter configured on your GitHub connection:

Any PR that changes the kernel API. Monitor changes to API endpoints (packages/api/cmd/api/) and Temporal workflows (packages/api/lib/temporal) in the kernel repo

Reason: PR modifies session handling logic (CUA template) with no changes to kernel API endpoints or Temporal workflows, which are the specific monitored paths in packages/api/cmd/api/ and packages/api/lib/temporal.

To monitor this PR anyway, reply with @firetiger monitor this.

@masnwilliams masnwilliams merged commit c684ca7 into hypeship/unified-cua-template May 5, 2026
3 checks passed
@masnwilliams masnwilliams deleted the hypeship/fix-session-stop-idempotent branch May 5, 2026 02:28
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