Skip to content

[STG-1802] fix: abort immediately for already-aborted agent signals#1982

Open
shrey150 wants to merge 1 commit intomainfrom
shrey/agent-abort-fast-path
Open

[STG-1802] fix: abort immediately for already-aborted agent signals#1982
shrey150 wants to merge 1 commit intomainfrom
shrey/agent-abort-fast-path

Conversation

@shrey150
Copy link
Copy Markdown
Contributor

@shrey150 shrey150 commented Apr 8, 2026

Summary

  • throw AgentAbortError before agent setup when the supplied signal is already aborted
  • deflake the abort-signal integration test by removing Browserbase init from the immediate-abort case
  • add a changeset and unit coverage for the fast path

Verification

  • pnpm exec prettier --check .changeset/quiet-cameras-knock.md packages/core/lib/v3/v3.ts packages/core/tests/integration/agent-abort-signal.spec.ts packages/core/tests/unit/browserbase-session-accessors.test.ts
  • pnpm --filter @browserbasehq/stagehand typecheck
  • pnpm --filter @browserbasehq/stagehand build:esm
  • pnpm --filter @browserbasehq/stagehand test:core -- packages/core/dist/esm/tests/unit/browserbase-session-accessors.test.js
  • node --import tsx -e "already-aborted signal smoke test"

Linear: https://linear.app/browserbase/issue/STG-1802/abort-immediately-for-already-aborted-agent-signals


Summary by cubic

Abort agents immediately when given an already-aborted signal, throwing AgentAbortError before any setup. Aligns with Linear STG-1802 and removes flakiness in the immediate-abort path for @browserbasehq/stagehand.

  • Bug Fixes
    • Added early abort check in V3 execute path (throwAgentAbortIfAborted), using signal.reason when present.
    • Deflaked tests by skipping Browserbase init for the immediate-abort case and added unit coverage for the fast path.

Written for commit b84f012. Summary will update on new commits. Review in cubic

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 4 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.
Architecture diagram
sequenceDiagram
    participant App as Client Application
    participant V3 as V3 Core (Stagehand)
    participant BB as Browserbase / Session
    participant LLM as LLM Client

    Note over App, LLM: Agent Execution Flow (with AbortSignal)

    App->>V3: agent.execute({ instruction, signal })
    
    V3->>V3: NEW: throwAgentAbortIfAborted(signal)
    
    alt NEW: Signal is already aborted (Fast Path)
        V3-->>App: throw AgentAbortError (reason)
        Note right of V3: Execution stops before initializing resources
    else Signal is active
        V3->>V3: validateExperimentalFeatures()
        
        opt CHANGED: If not initialized (Integration Tests)
            V3->>BB: init() / Session Setup
            BB-->>V3: session ready
        end
        
        V3->>LLM: setup & query handler
        
        loop Agent Loop
            V3->>LLM: Generate next action
            LLM-->>V3: action
            V3->>BB: Perform action on Page
            
            opt Signal aborted during execution
                V3-->>App: throw AgentAbortError
            end
        end
        
        V3-->>App: AgentResult / Stream
    end
Loading

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