fix: remove duplicate hidden window and improve scheduled task prompt#496
Merged
shadowfax92 merged 2 commits intomainfrom Mar 13, 2026
Merged
fix: remove duplicate hidden window and improve scheduled task prompt#496shadowfax92 merged 2 commits intomainfrom
shadowfax92 merged 2 commits intomainfrom
Conversation
Contributor
Author
|
@greptileai review |
Contributor
Greptile SummaryThis PR fixes the scheduled task agent's prompt rules so that the Key changes:
Confidence Score: 4/5
Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[buildSystemPrompt called] --> B{isScheduledTask?}
B -- No --> C[Standard page_context: Rule 1 only]
B -- Yes --> D{scheduledTaskWindowId provided?}
D -- Yes --> E["Rule 2: Always pass windowId: <id>\nfor new_page / new_hidden_page"]
D -- No --> F["Rule 2: Always pass windowId\nfrom Browser Context\nfor new_page / new_hidden_page"]
E --> G["Rule 3: Do NOT close\ndedicated hidden window"]
F --> G
G --> H["Rule 4: Do NOT create\nnew windows"]
H --> I["Rule 5: Complete task\nend-to-end"]
C --> J[Emit page_context block]
I --> J
Prompt To Fix All With AIThis is a comment left during a code review.
Path: apps/server/src/agent/prompt.ts
Line: 176-181
Comment:
**`create_hidden_window` missing from MCP tool reference**
The Window Management section in `getCdpToolReference()` lists `create_window(hidden?)` but omits `create_hidden_window`, which exists as a distinct callable tool (`tools/windows.ts:79`). The newly added Rule 4 in the scheduled task context correctly references it by name ("Do NOT create new windows (via `create_window` or `create_hidden_window`)"), so MCP prompt consumers can follow the prohibition — but they wouldn't discover the tool from the reference itself.
Since the PR's explicit goal is to improve MCP prompt tool coverage (adding `new_hidden_page`), it would be consistent to add `create_hidden_window` here too:
```suggestion
## Window Management
- `list_windows` - Get all browser windows
- `create_window(hidden?)` - Create a new browser window
- `create_hidden_window` - Create a new hidden browser window (not visible to user, take_screenshot not supported)
- `close_window(windowId)` - Close a browser window
- `activate_window(windowId)` - Activate (focus) a browser window
```
How can I resolve this? If you propose a fix, please make it concise.
---
This is a comment left during a code review.
Path: apps/server/src/agent/prompt.ts
Line: 144
Comment:
**`show_page` referenced but not listed in tool reference**
The new `new_hidden_page` entry correctly notes "use `show_page` first", but `show_page` itself is not listed anywhere in `getCdpToolReference()`. MCP prompt consumers won't know the tool name or its signature unless they discover it via tool schemas. Consider adding it to the Page Management section alongside `new_hidden_page`:
```suggestion
- `new_hidden_page(url, windowId?)` - Open a hidden background page. Not visible to user. take_screenshot not supported — use show_page first.
- `show_page(page, windowId?, index?, activate?)` - Restore a hidden page to a visible window. Required before take_screenshot on hidden pages.
```
How can I resolve this? If you propose a fix, please make it concise.Last reviewed commit: 946cd4d |
The agent prompt only told the agent to pass windowId with `new_page` but not `new_hidden_page`, which the agent prefers for background work. The agent also had no instruction against closing or replacing its dedicated hidden window, causing pages to scatter across uncontrolled windows. Expanded the scheduled task prompt rules to: - Cover both `new_page` and `new_hidden_page` windowId requirement - Forbid closing the dedicated hidden window - Forbid creating new windows - Added `new_hidden_page` to tool reference for MCP consumers Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…tend The server's ChatService already creates a hidden window for scheduled tasks (chat-service.ts:99-126), but the frontend (scheduledJobRuns.ts) was also creating a minimized Chrome window that the server immediately overwrote. This caused two windows to be created per scheduled task run, with only one being used. Removed from scheduledJobRuns.ts: - chrome.windows.create() call - 1-second race condition delay hack (FIXME) - chrome.windows.remove() cleanup - windowId/activeTab params to getChatServerResponse() Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
946cd4d to
45efa8d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
scheduledJobRuns.ts) was creating a minimized Chrome window that the server (ChatService) immediately overwrote with its own hidden window. Two windows per scheduled task, only one used.new_pageandnew_hidden_page, added rules forbidding window closure/creationChanges
scheduledJobRuns.ts(-28 lines)chrome.windows.create()— server handles window lifecyclechrome.windows.remove()cleanup in finally blockwindowId/activeTabparams togetChatServerResponse()prompt.ts(+9 lines, -5 lines)new_pageandnew_hidden_pagefor windowId requirementTest plan
windowIdto page creation callslist_windowsduring scheduled task shows exactly 1 hidden window🤖 Generated with Claude Code