fix(server): close pages by refreshed target id#981
fix(server): close pages by refreshed target id#981Nikhil (shadowfax92) wants to merge 2 commits into
Conversation
❌ Tests failed — 1/1231 failed
Failed tests
|
Greptile SummaryThis PR fixes tab-close failures that occur when a page's CDP
Confidence Score: 4/5Safe to merge; the retry path correctly handles target changes and the session cleanup covers both target IDs. The core retry logic and session cleanup are sound and well-tested. The only rough edge is the tabId check inside the retry guard: when tabId changes but targetId stays the same, a redundant retry fires with the same targetId that already failed, and the original error is replaced by the new one. This scenario is practically unreachable in real browser behavior, so the change is safe to ship. packages/browseros-agent/apps/server/src/browser/browser.ts — specifically the retry guard condition in closePage. Important Files Changed
Sequence DiagramsequenceDiagram
participant Caller
participant closePage
participant resolvePageInfo
participant listPages
participant CDP as cdp.Browser
participant refreshPageInfo
Caller->>closePage: closePage(pageId)
closePage->>resolvePageInfo: resolvePageInfo(pageId)
resolvePageInfo->>resolvePageInfo: pages.get(pageId)?
alt not cached
resolvePageInfo->>listPages: listPages()
listPages-->>resolvePageInfo: updated cache
end
resolvePageInfo-->>closePage: info (or undefined → throw)
closePage->>CDP: "closeTab({ targetId: info.targetId })"
alt success
CDP-->>closePage: ok
closePage->>closePage: detach console, delete page, delete sessions
else error (target changed)
CDP-->>closePage: error
closePage->>refreshPageInfo: refreshPageInfo(pageId)
refreshPageInfo->>CDP: "getTabInfo({ tabId: info.tabId })"
CDP-->>refreshPageInfo: tab with new targetId
refreshPageInfo-->>closePage: refreshed (new targetId)
alt no change or page gone
closePage->>Caller: rethrow error
else targetId changed
closePage->>CDP: "closeTab({ targetId: refreshed.targetId })"
CDP-->>closePage: ok
closePage->>closePage: detach console, delete page, delete both sessions
end
end
closePage-->>Caller: void
Prompt To Fix All With AIFix the following 1 code review issue. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 1
packages/browseros-agent/apps/server/src/browser/browser.ts:616-621
The retry guard checks both `targetId` AND `tabId` to decide whether to retry. This means if only `tabId` changes (while `targetId` stays the same) the method retries `closeTab` with the *same* `targetId` that just failed, then surfaces the error from the second attempt rather than the original one. Since `closeTab` is called by `targetId`, only a changed `targetId` can make the retry meaningful. The `tabId` condition should be dropped.
```suggestion
if (!refreshed || refreshed.targetId === info.targetId) {
throw error
}
```
Reviews (1): Last reviewed commit: "fix: clear close page retry sessions" | Re-trigger Greptile |
| if ( | ||
| !refreshed || | ||
| (refreshed.targetId === info.targetId && refreshed.tabId === info.tabId) | ||
| ) { | ||
| throw error | ||
| } |
There was a problem hiding this comment.
The retry guard checks both
targetId AND tabId to decide whether to retry. This means if only tabId changes (while targetId stays the same) the method retries closeTab with the same targetId that just failed, then surfaces the error from the second attempt rather than the original one. Since closeTab is called by targetId, only a changed targetId can make the retry meaningful. The tabId condition should be dropped.
| if ( | |
| !refreshed || | |
| (refreshed.targetId === info.targetId && refreshed.tabId === info.tabId) | |
| ) { | |
| throw error | |
| } | |
| if (!refreshed || refreshed.targetId === info.targetId) { | |
| throw error | |
| } |
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/browseros-agent/apps/server/src/browser/browser.ts
Line: 616-621
Comment:
The retry guard checks both `targetId` AND `tabId` to decide whether to retry. This means if only `tabId` changes (while `targetId` stays the same) the method retries `closeTab` with the *same* `targetId` that just failed, then surfaces the error from the second attempt rather than the original one. Since `closeTab` is called by `targetId`, only a changed `targetId` can make the retry meaningful. The `tabId` condition should be dropped.
```suggestion
if (!refreshed || refreshed.targetId === info.targetId) {
throw error
}
```
How can I resolve this? If you propose a fix, please make it concise.
Summary
Test plan
Fixes #438