ACP: make --reset-session asynchronous and track pending resets; add PowerShell wrapper for scheduled tasks#11001
ACP: make --reset-session asynchronous and track pending resets; add PowerShell wrapper for scheduled tasks#11001TimLai666 wants to merge 26 commits intoopenclaw:mainfrom
Conversation
- Add pendingReset property to AcpSession type to track async reset promises - Add setPendingReset method to AcpSessionStore interface - Create startResetIfNeeded function that returns reset promise without blocking - Update newSession and loadSession to start reset asynchronously - Update prompt method to wait for pending reset before sending first message - Add comprehensive tests for async reset behavior - All existing tests pass Co-authored-by: TimLai666 <[email protected]>
- Update docs/cli/acp.md to explain async reset behavior - Add changelog entry describing the fix and its benefits Co-authored-by: TimLai666 <[email protected]>
- Remove /IT flag that causes interactive session - Create PowerShell wrapper script with -WindowStyle Hidden - Update schtasks to use PowerShell execution for hidden background mode - Modify uninstallScheduledTask to clean up both .cmd and .ps1 files - All existing tests pass Co-authored-by: TimLai666 <[email protected]>
- Use setPendingReset to clear pending reset for consistent state management - Simplify promise void conversion in startResetIfNeeded Co-authored-by: TimLai666 <[email protected]>
- Export quotePowerShellArg and buildPowerShellWrapper for testing - Add 13 new tests covering PowerShell argument escaping and script generation - Test all script components: description, working directory, environment vars - Verify -WindowStyle Hidden flag is correctly applied - All 30 tests pass Co-authored-by: TimLai666 <[email protected]>
- Update AcpSessionStore interface to accept null for resetPromise parameter Co-authored-by: TimLai666 <[email protected]>
- Remove unused $process variable from PowerShell wrapper - Change ExecutionPolicy from Bypass to RemoteSigned for better security - Properly escape PowerShell script path using quoteCmdArg - Add comments explaining security and escaping choices - Update tests to match new output (remove -PassThru check) Co-authored-by: TimLai666 <[email protected]>
- Use path.join and path.basename instead of string replace for reliability - Ensure .ps1 extension properly replaces .cmd regardless of case - Clarify comments about CMD script backward compatibility - Apply same robust path handling in both install and uninstall functions Co-authored-by: TimLai666 <[email protected]>
- Clarify CMD script purpose: manual troubleshooting/fallback - Make error handling consistent: silent failure for both CMD and PS1 - Add informative message when no scripts found to remove - Document that scheduled task uses PowerShell, CMD is for manual use Co-authored-by: TimLai666 <[email protected]>
| await fs.writeFile(ps1ScriptPath, ps1Script, "utf8"); | ||
|
|
||
| // Keep CMD script for backward compatibility and manual troubleshooting | ||
| // The CMD script can be manually invoked if PowerShell execution fails |
There was a problem hiding this comment.
Invalid PowerShell flags
The scheduled task command is built as powershell.exe -ExecutionPolicy RemoteSigned -WindowStyle Hidden -File .... -WindowStyle is not a consistently supported/recognized switch for powershell.exe across Windows/PowerShell variants, so this can cause the task launch to fail. Hiding is already handled inside the generated .ps1 via Start-Process -WindowStyle Hidden, so dropping -WindowStyle Hidden from the powershell.exe ... invocation avoids a hard failure mode.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/daemon/schtasks.ts
Line: 331:334
Comment:
**Invalid PowerShell flags**
The scheduled task command is built as `powershell.exe -ExecutionPolicy RemoteSigned -WindowStyle Hidden -File ...`. `-WindowStyle` is not a consistently supported/recognized switch for `powershell.exe` across Windows/PowerShell variants, so this can cause the task launch to fail. Hiding is already handled inside the generated `.ps1` via `Start-Process -WindowStyle Hidden`, so dropping `-WindowStyle Hidden` from the `powershell.exe ...` invocation avoids a hard failure mode.
How can I resolve this? If you propose a fix, please make it concise.
Additional Comments (1)
Consider catching/logging reset errors and always clearing Prompt To Fix With AIThis is a comment left during a code review.
Path: src/acp/translator.ts
Line: 226:230
Comment:
**Reset failure breaks prompts**
`prompt()` awaits `session.pendingReset` directly; if `sessions.reset` rejects (gateway error, transient network, etc.), this throws and blocks the first prompt even though the handshake already succeeded. Because `pendingReset` is only cleared after a successful await, a rejection leaves it set and every later prompt will keep failing.
Consider catching/logging reset errors and always clearing `pendingReset` (e.g. `await pendingReset.catch(...); setPendingReset(..., null)`), so reset failure doesn’t hard-fail prompting.
How can I resolve this? If you propose a fix, please make it concise. |
|
Heads up: the lint failure ( git fetch origin main && git rebase origin/main && git push --force-with-lease |
|
Update: the lint failure has been resolved by #11093 (merged), which excluded git fetch origin main && git rebase origin/main && git push --force-with-lease |
- Remove /IT flag that causes interactive session - Create PowerShell wrapper script with -WindowStyle Hidden - Update schtasks to use PowerShell execution for hidden background mode - Modify uninstallScheduledTask to clean up both .cmd and .ps1 files - All existing tests pass Co-authored-by: TimLai666 <[email protected]>
- Export quotePowerShellArg and buildPowerShellWrapper for testing - Add 13 new tests covering PowerShell argument escaping and script generation - Test all script components: description, working directory, environment vars - Verify -WindowStyle Hidden flag is correctly applied - All 30 tests pass Co-authored-by: TimLai666 <[email protected]>
- Remove unused $process variable from PowerShell wrapper - Change ExecutionPolicy from Bypass to RemoteSigned for better security - Properly escape PowerShell script path using quoteCmdArg - Add comments explaining security and escaping choices - Update tests to match new output (remove -PassThru check) Co-authored-by: TimLai666 <[email protected]>
- Use path.join and path.basename instead of string replace for reliability - Ensure .ps1 extension properly replaces .cmd regardless of case - Clarify comments about CMD script backward compatibility - Apply same robust path handling in both install and uninstall functions Co-authored-by: TimLai666 <[email protected]>
- Clarify CMD script purpose: manual troubleshooting/fallback - Make error handling consistent: silent failure for both CMD and PS1 - Add informative message when no scripts found to remove - Document that scheduled task uses PowerShell, CMD is for manual use Co-authored-by: TimLai666 <[email protected]>
- Add pendingReset property to AcpSession type to track async reset promises - Add setPendingReset method to AcpSessionStore interface - Create startResetIfNeeded function that returns reset promise without blocking - Update newSession and loadSession to start reset asynchronously - Update prompt method to wait for pending reset before sending first message - Add comprehensive tests for async reset behavior - All existing tests pass Co-authored-by: TimLai666 <[email protected]>
- Update docs/cli/acp.md to explain async reset behavior - Add changelog entry describing the fix and its benefits Co-authored-by: TimLai666 <[email protected]>
- Use setPendingReset to clear pending reset for consistent state management - Simplify promise void conversion in startResetIfNeeded Co-authored-by: TimLai666 <[email protected]>
- Update AcpSessionStore interface to accept null for resetPromise parameter Co-authored-by: TimLai666 <[email protected]>
bfc1ccb to
f92900f
Compare
|
This pull request has been automatically marked as stale due to inactivity. |
|
This pull request has been automatically marked as stale due to inactivity. |
|
Closing due to inactivity. |
This is the fix for issue #10693 and #10933.
Optimize ACP --reset-session to be asynchronous to minimize latency for clients like Zed.
Greptile Overview
Greptile Summary
--reset-sessionnon-blocking by starting the gateway reset in the background and deferring the await until the firstprompt().pendingResettracking to the in-memory ACP session store/types so prompt sending can wait for completion..ps1wrapper (hiddenStart-Process) and point the task at PowerShell instead of the.cmddirectly.Confidence Score: 3/5
(2/5) Greptile learns from your feedback when you react with thumbs up/down!