Conversation
|
There was a problem hiding this comment.
5 issues found across 5 files
Confidence score: 2/5
- High merge risk: there are concrete, high-confidence runtime failures in new handlers, including
stagehandbeing dereferenced without being provided inpackages/server-v4/src/routes/v4/browsersession/setViewportSize.tsandsessionStore.endSession(...)being called onundefinedinpackages/server-v4/src/routes/v4/browsersession/close.ts. - Several new routes appear unreachable because they are not registered in the route plugin/
routes.ts(packages/server-v4/src/routes/v4/browsersession/close.ts,packages/server-v4/src/routes/v4/browsersession/setViewportSize.ts,packages/server-v4/src/routes/v4/browsersession/isBrowserbase.ts), so intended API behavior will not be exposed at runtime. - Given the 7-9/10 severities with strong confidence, this is likely to cause immediate endpoint regressions rather than minor polish issues.
- Pay close attention to
packages/server-v4/src/routes/v4/browsersession/routes.ts,packages/server-v4/src/routes/v4/browsersession/close.ts,packages/server-v4/src/routes/v4/browsersession/setViewportSize.ts,packages/server-v4/src/routes/v4/browsersession/isBrowserbase.ts- register all new routes and ensure required handler dependencies (stagehand,sessionStore) are actually passed.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="packages/server-v4/src/routes/v4/browsersession/isBrowserbase.ts">
<violation number="1" location="packages/server-v4/src/routes/v4/browsersession/isBrowserbase.ts:14">
P2: This route is defined but never registered in `browserSessionRoutes`, so the `/v4/browsersession/isBrowserbase` endpoint won’t be reachable. Add it to `packages/server-v4/src/routes/v4/browsersession/routes.ts`.</violation>
</file>
<file name="packages/server-v4/src/routes/v4/browsersession/setViewportSize.ts">
<violation number="1" location="packages/server-v4/src/routes/v4/browsersession/setViewportSize.ts:14">
P1: This route is not imported/registered in the browser session route plugin, so the new endpoint is unreachable.</violation>
<violation number="2" location="packages/server-v4/src/routes/v4/browsersession/setViewportSize.ts:29">
P1: The handler dereferences `stagehand`, but `createBrowserSessionActionHandler` never passes `stagehand`, causing a runtime crash on this endpoint.</violation>
</file>
<file name="packages/server-v4/src/routes/v4/browsersession/close.ts">
<violation number="1" location="packages/server-v4/src/routes/v4/browsersession/close.ts:14">
P0: Dead code: The newly added route files are not imported or registered in the routes.ts file. They are exported but never consumed, making them unreachable at runtime.</violation>
<violation number="2" location="packages/server-v4/src/routes/v4/browsersession/close.ts:30">
P1: `sessionStore` is passed as `undefined` by the shared action handler, so calling `sessionStore.endSession(...)` will crash with a runtime TypeError.</violation>
</file>
Architecture diagram
sequenceDiagram
participant Client
participant Router as Fastify Router (v4)
participant Handler as Shared Action Handler
participant Store as SessionStoreManager
participant SH as Stagehand Instance
participant PW as Playwright / Browser
Note over Client,PW: NEW: Browser Session Management Flow (v4)
Client->>Router: POST /v4/browsersession/[method]
Note right of Client: Includes sessionId & params
Router->>Handler: Execute Route Handler
Handler->>Store: NEW: Get session (sessionId)
alt Session Not Found
Store-->>Handler: null
Handler-->>Client: 404 Action Error Envelope
else Session Active
Store-->>Handler: Stagehand Instance
Handler->>Handler: NEW: Validate params via Zod Schema
alt method == "setViewportSize"
Handler->>SH: context.awaitActivePage()
SH-->>Handler: Page Instance
Handler->>PW: page.setViewportSize(w, h)
PW-->>Handler: void
else method == "close"
Handler->>Store: NEW: endSession(sessionId)
Store->>SH: close()
Store->>Store: Remove from LRU Cache
else method == "isBrowserbase"
Handler->>SH: Access .isBrowserbase property
end
Handler-->>Client: 200 Success (Standard Action Envelope)
end
Note over Store: InMemorySessionStore: Handles TTL,<br/>LRU eviction, and lazy V3 init
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
| createBrowserSessionActionHandler, | ||
| } from "./shared.js"; | ||
|
|
||
| const closeRoute: RouteOptions = { |
There was a problem hiding this comment.
P0: Dead code: The newly added route files are not imported or registered in the routes.ts file. They are exported but never consumed, making them unreachable at runtime.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/server-v4/src/routes/v4/browsersession/close.ts, line 14:
<comment>Dead code: The newly added route files are not imported or registered in the routes.ts file. They are exported but never consumed, making them unreachable at runtime.</comment>
<file context>
@@ -0,0 +1,40 @@
+ createBrowserSessionActionHandler,
+} from "./shared.js";
+
+const closeRoute: RouteOptions = {
+ method: "POST",
+ url: "/browsersession/close",
</file context>
| createBrowserSessionActionHandler, | ||
| } from "./shared.js"; | ||
|
|
||
| const setViewportSizeRoute: RouteOptions = { |
There was a problem hiding this comment.
P1: This route is not imported/registered in the browser session route plugin, so the new endpoint is unreachable.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/server-v4/src/routes/v4/browsersession/setViewportSize.ts, line 14:
<comment>This route is not imported/registered in the browser session route plugin, so the new endpoint is unreachable.</comment>
<file context>
@@ -0,0 +1,48 @@
+ createBrowserSessionActionHandler,
+} from "./shared.js";
+
+const setViewportSizeRoute: RouteOptions = {
+ method: "POST",
+ url: "/browsersession/setViewportSize",
</file context>
| handler: createBrowserSessionActionHandler({ | ||
| method: "setViewportSize", | ||
| actionSchema: BrowserSessionSetViewportSizeActionSchema, | ||
| execute: async ({ stagehand, params }) => { |
There was a problem hiding this comment.
P1: The handler dereferences stagehand, but createBrowserSessionActionHandler never passes stagehand, causing a runtime crash on this endpoint.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/server-v4/src/routes/v4/browsersession/setViewportSize.ts, line 29:
<comment>The handler dereferences `stagehand`, but `createBrowserSessionActionHandler` never passes `stagehand`, causing a runtime crash on this endpoint.</comment>
<file context>
@@ -0,0 +1,48 @@
+ handler: createBrowserSessionActionHandler({
+ method: "setViewportSize",
+ actionSchema: BrowserSessionSetViewportSizeActionSchema,
+ execute: async ({ stagehand, params }) => {
+ const page = await stagehand.context.awaitActivePage();
+ await page.setViewportSize(params.width, params.height, {
</file context>
| method: "close", | ||
| actionSchema: BrowserSessionCloseActionSchema, | ||
| execute: async ({ sessionId, sessionStore }) => { | ||
| await sessionStore.endSession(sessionId); |
There was a problem hiding this comment.
P1: sessionStore is passed as undefined by the shared action handler, so calling sessionStore.endSession(...) will crash with a runtime TypeError.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/server-v4/src/routes/v4/browsersession/close.ts, line 30:
<comment>`sessionStore` is passed as `undefined` by the shared action handler, so calling `sessionStore.endSession(...)` will crash with a runtime TypeError.</comment>
<file context>
@@ -0,0 +1,40 @@
+ method: "close",
+ actionSchema: BrowserSessionCloseActionSchema,
+ execute: async ({ sessionId, sessionStore }) => {
+ await sessionStore.endSession(sessionId);
+ return {
+ result: {
</file context>
| createBrowserSessionActionHandler, | ||
| } from "./shared.js"; | ||
|
|
||
| const isBrowserbaseRoute: RouteOptions = { |
There was a problem hiding this comment.
P2: This route is defined but never registered in browserSessionRoutes, so the /v4/browsersession/isBrowserbase endpoint won’t be reachable. Add it to packages/server-v4/src/routes/v4/browsersession/routes.ts.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/server-v4/src/routes/v4/browsersession/isBrowserbase.ts, line 14:
<comment>This route is defined but never registered in `browserSessionRoutes`, so the `/v4/browsersession/isBrowserbase` endpoint won’t be reachable. Add it to `packages/server-v4/src/routes/v4/browsersession/routes.ts`.</comment>
<file context>
@@ -0,0 +1,39 @@
+ createBrowserSessionActionHandler,
+} from "./shared.js";
+
+const isBrowserbaseRoute: RouteOptions = {
+ method: "POST",
+ url: "/browsersession/isBrowserbase",
</file context>
why
what changed
test plan
Summary by cubic
Adds v4 BrowserSession routes and a pluggable session store with a default in‑memory LRU/TTL cache to improve session lifecycle and performance.
/v4/browsersession/close,/isAdvancedStealth,/isBrowserbase,/setViewportSize.SessionStoreinterface and defaultInMemorySessionStore(lazyV3init, LRU eviction, TTL, periodic cleanup) managed viasessionStoreManager.fastify-zod-openapischemas; errors return the standard action error envelope.Written for commit 9952cf6. Summary will update on new commits. Review in cubic