Skip to content

ACP: Make --reset-session non-blocking to fix latency-sensitive client timeouts#1

Merged
TimLai666 merged 5 commits intomainfrom
copilot/optimize-session-reset-process
Feb 7, 2026
Merged

ACP: Make --reset-session non-blocking to fix latency-sensitive client timeouts#1
TimLai666 merged 5 commits intomainfrom
copilot/optimize-session-reset-process

Conversation

Copy link
Copy Markdown

Copilot AI commented Feb 7, 2026

The --reset-session flag blocks the ACP initialization handshake while performing sessions.reset, causing connection failures in clients with tight startup timeouts (e.g., Zed editor).

Changes

Defer reset to after handshake

  • newSession() and loadSession() now start reset asynchronously and return immediately
  • Reset promise tracked in AcpSession.pendingReset via new setPendingReset() method
  • prompt() awaits pending reset before sending first message

New session-mapper API

  • startResetIfNeeded() returns Promise<void> | null without blocking
  • resetSessionIfNeeded() preserved for backward compatibility

Example

// Before: blocks handshake
await resetSessionIfNeeded({ meta, sessionKey, gateway, opts });
const session = this.sessionStore.createSession({ sessionId, sessionKey, cwd });

// After: non-blocking
const resetPromise = startResetIfNeeded({ meta, sessionKey, gateway, opts });
const session = this.sessionStore.createSession({ sessionId, sessionKey, cwd });
if (resetPromise) {
  this.sessionStore.setPendingReset(sessionId, resetPromise);
}

Reset completes before first prompt preserving correctness while eliminating handshake delay.

Original prompt

Problem Description

The --reset-session flag in the openclaw acp command causes a significant delay in the startup process. This leads to connection failures in clients like the Zed editor's ACP bridge integration, which are sensitive to startup latency.

Key Observations

  • Using the --reset-session flag causes a failure with the error: Internal error: { "details": "gateway not connected" }.
  • Removing the flag resolves the issue.
  • The delay introduced by --reset-session exceeds the timeout limits of latency-sensitive clients like Zed.

Root Cause

The --reset-session flag triggers session cleanup and re-initialization, adding extra delay during the handshake process between the client and server.

Proposed Solution

Optimize the session reset process to minimize latency. Several approaches can be considered:

  1. Async Initialization: Perform session re-initialization asynchronously, allowing the handshake process to proceed without waiting for cleanup to complete.
  2. Priority Management: Enhance timeout configurations or enable a handshake bypass mechanism temporarily during session reset.
  3. Conditional Behavior: Implement an adaptive behavior for --reset-session to detect latency-sensitive sessions and reduce delays automatically.

Next Steps

  1. Investigate the code path for --reset-session flag in openclaw acp.
  2. Evaluate the possibility of async initialization or timeout adjustment.
  3. Test changes to ensure compatibility with latency-sensitive clients like Zed.
  4. Validate against the existing test suite to ensure no regressions.

This pull request was created from Copilot chat.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 4 commits February 7, 2026 07:37
- 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]>
Copilot AI changed the title [WIP] Optimize session reset to reduce startup delay ACP: Make --reset-session non-blocking to fix latency-sensitive client timeouts Feb 7, 2026
Copilot AI requested a review from TimLai666 February 7, 2026 07:44
Copy link
Copy Markdown
Owner

@TimLai666 TimLai666 left a comment

Choose a reason for hiding this comment

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

@copilot 簡述一下改了什麼 是大改還是小改

Copy link
Copy Markdown
Author

Copilot AI commented Feb 7, 2026

@copilot 簡述一下改了什麼 是大改還是小改

這是小改,只修改了 ACP 的 session 初始化流程。

核心變更(約 144 行代碼):

  • --reset-session 從同步改成非同步執行
  • 新增 pendingReset 屬性追蹤重置進度
  • 在發送第一個 prompt 前等待重置完成

影響範圍

  • 只修改了 6 個核心檔案(src/acp/*
  • 不影響其他模組
  • 向後兼容,沒有 breaking changes

效果

  • ACP 握手不再被 session reset 阻塞
  • 解決了 Zed editor 等延遲敏感客戶端的連線逾時問題
  • 所有現有測試都通過

主要就是調整了執行順序,讓 handshake 先完成,reset 在背景執行,第一個 prompt 前才等待 reset 完成。

@TimLai666 TimLai666 marked this pull request as ready for review February 7, 2026 08:01
@TimLai666 TimLai666 merged commit 49d1e7a into main Feb 7, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants