Skip to content

ACP: make --reset-session asynchronous and track pending resets; add PowerShell wrapper for scheduled tasks#11001

Closed
TimLai666 wants to merge 26 commits intoopenclaw:mainfrom
TimLai666:main
Closed

ACP: make --reset-session asynchronous and track pending resets; add PowerShell wrapper for scheduled tasks#11001
TimLai666 wants to merge 26 commits intoopenclaw:mainfrom
TimLai666:main

Conversation

@TimLai666
Copy link
Copy Markdown

@TimLai666 TimLai666 commented Feb 7, 2026

This is the fix for issue #10693 and #10933.
Optimize ACP --reset-session to be asynchronous to minimize latency for clients like Zed.

  • Implement pendingReset tracking in the session store.
  • Add PowerShell wrapper for hidden execution of scheduled tasks on Windows.
  • Updated documentation, changelog, and unit tests.

Greptile Overview

Greptile Summary

  • Makes ACP --reset-session non-blocking by starting the gateway reset in the background and deferring the await until the first prompt().
  • Adds pendingReset tracking to the in-memory ACP session store/types so prompt sending can wait for completion.
  • Updates docs/changelog and extends unit tests for session reset behavior.
  • Updates Windows scheduled-task installation to generate a .ps1 wrapper (hidden Start-Process) and point the task at PowerShell instead of the .cmd directly.

Confidence Score: 3/5

  • This PR is close to mergeable but has a couple of runtime failure modes that should be fixed first.
  • Main risks are (1) a failed async session reset can permanently break prompting for that session due to an unhandled rejected pendingReset promise, and (2) the Windows scheduled task command includes a PowerShell flag that can cause task launch failures depending on the installed PowerShell/Windows variant.
  • src/acp/translator.ts, src/daemon/schtasks.ts

(2/5) Greptile learns from your feedback when you react with thumbs up/down!

Copilot AI and others added 13 commits February 7, 2026 07:33
- 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]>
@openclaw-barnacle openclaw-barnacle bot added docs Improvements or additions to documentation gateway Gateway runtime labels Feb 7, 2026
@TimLai666 TimLai666 marked this pull request as ready for review February 7, 2026 08:24
Copy link
Copy Markdown
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

2 files reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

Comment on lines +331 to +334
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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Feb 7, 2026

Additional Comments (1)

src/acp/translator.ts
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.

Prompt To Fix With AI
This 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.

@leszekszpunar
Copy link
Copy Markdown
Contributor

Heads up: the lint failure (preserve-caught-error in extensions/memory-lancedb/index.ts) is a pre-existing issue on main, not caused by your changes. The fix is in #11061. Once it lands, rebase on main and re-push to get a clean CI run.

git fetch origin main && git rebase origin/main && git push --force-with-lease

@leszekszpunar
Copy link
Copy Markdown
Contributor

Update: the lint failure has been resolved by #11093 (merged), which excluded extensions/ from oxlint scope. A rebase on main should give you a clean CI run.

git fetch origin main && git rebase origin/main && git push --force-with-lease

Copilot AI and others added 7 commits February 8, 2026 02:08
- 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]>
Copilot AI and others added 2 commits February 8, 2026 02:08
- 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]>
@openclaw-barnacle
Copy link
Copy Markdown

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle bot added the stale Marked as stale due to inactivity label Feb 21, 2026
@openclaw-barnacle openclaw-barnacle bot added size: M and removed stale Marked as stale due to inactivity labels Feb 22, 2026
@openclaw-barnacle
Copy link
Copy Markdown

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle bot added the stale Marked as stale due to inactivity label Mar 8, 2026
@openclaw-barnacle
Copy link
Copy Markdown

Closing due to inactivity.
If you believe this PR should be revived, post in #pr-thunderdome-dangerzone on Discord to talk to a maintainer.
That channel is the escape hatch for high-quality PRs that get auto-closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation gateway Gateway runtime size: M stale Marked as stale due to inactivity

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants