fix: extend ACP session creation timeout (#1949)
This commit is contained in:
@@ -354,7 +354,7 @@ func (s *Server) handleWSNewSession(ctx context.Context, msg *ws.Message) *ws.Me
|
||||
return resp
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithTimeout(ctx, 30*time.Second)
|
||||
ctx, cancel := context.WithTimeout(ctx, constants.SessionNewTimeout)
|
||||
defer cancel()
|
||||
|
||||
adapter := s.procMgr.GetAdapter()
|
||||
|
||||
@@ -245,6 +245,25 @@ func TestHandleWSNewSession_NoAdapter(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestHandleWSNewSession_UsesExtendedDeadline(t *testing.T) {
|
||||
s := newTestServer(t)
|
||||
capture := &newSessionDeadlineCaptureAdapter{}
|
||||
s.procMgr.SetAdapterForTest(capture)
|
||||
|
||||
msg, err := ws.NewRequest("req-1", "agent.session.new", NewSessionRequest{})
|
||||
if err != nil {
|
||||
t.Fatalf("NewRequest: %v", err)
|
||||
}
|
||||
resp := s.handleWSNewSession(context.Background(), msg)
|
||||
if resp.Type != ws.MessageTypeResponse {
|
||||
t.Fatalf("response type = %q, want %q", resp.Type, ws.MessageTypeResponse)
|
||||
}
|
||||
const want = 2 * time.Minute
|
||||
if capture.remaining < want-time.Second || capture.remaining > want {
|
||||
t.Fatalf("session/new deadline = %v from now, want about %v", capture.remaining, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHandleWSLoadSession_NoAdapter(t *testing.T) {
|
||||
s := newTestServer(t)
|
||||
ctx := context.Background()
|
||||
@@ -382,6 +401,20 @@ type mcpCaptureAdapter struct {
|
||||
loadSessionServers []types.McpServer
|
||||
}
|
||||
|
||||
type newSessionDeadlineCaptureAdapter struct {
|
||||
promptErrorAdapter
|
||||
remaining time.Duration
|
||||
}
|
||||
|
||||
func (a *newSessionDeadlineCaptureAdapter) NewSession(ctx context.Context, _ []types.McpServer) (string, error) {
|
||||
deadline, ok := ctx.Deadline()
|
||||
if !ok {
|
||||
return "", errors.New("session/new context has no deadline")
|
||||
}
|
||||
a.remaining = time.Until(deadline)
|
||||
return "session-1", nil
|
||||
}
|
||||
|
||||
func (a *mcpCaptureAdapter) NewSession(_ context.Context, servers []types.McpServer) (string, error) {
|
||||
a.newSessionServers = append([]types.McpServer(nil), servers...)
|
||||
return "new-session", nil
|
||||
|
||||
@@ -19,6 +19,10 @@ const (
|
||||
// including cleanup scripts and worktree removal.
|
||||
TaskDeleteTimeout = 2 * time.Minute
|
||||
|
||||
// SessionNewTimeout is the maximum time for ACP session/new. Session creation
|
||||
// can initialize providers, plugins, and MCP servers before the agent responds.
|
||||
SessionNewTimeout = 2 * time.Minute
|
||||
|
||||
// SessionLoadTimeout is the maximum time for ACP session/load (resume).
|
||||
// Session loading may involve deserializing large conversation histories.
|
||||
SessionLoadTimeout = 2 * time.Minute
|
||||
|
||||
Reference in New Issue
Block a user