mirror of
https://github.com/cexll/myclaude.git
synced 2025-12-24 13:47:58 +08:00
* Improve backend termination after message and extend timeout
* fix: prevent premature backend termination and revert timeout
Critical fixes for executor.go termination logic:
1. Add onComplete callback to prevent premature termination
- Parser now distinguishes between "any message" (onMessage) and
"terminal event" (onComplete)
- Codex: triggers onComplete on thread.completed
- Claude: triggers onComplete on type:"result"
- Gemini: triggers onComplete on type:"result" + terminal status
2. Fix executor to wait for completion events
- Replace messageSeen termination trigger with completeSeen
- Only start postMessageTerminateDelay after terminal event
- Prevents killing backend before final answer in multi-message scenarios
3. Fix terminated flag synchronization
- Only set terminated=true if terminateCommandFn actually succeeds
- Prevents "marked as terminated but not actually terminated" state
4. Simplify timer cleanup logic
- Unified non-blocking drain on messageTimer.C
- Remove dependency on messageTimerCh nil state
5. Revert defaultTimeout from 24h to 2h
- 24h (86400s) → 2h (7200s) to avoid operational risks
- 12× timeout increase could cause resource exhaustion
- Users needing longer tasks can use CODEX_TIMEOUT env var
All tests pass. Resolves early termination bug from code review.
Co-authored-by: Codeagent (Codex)
Generated with SWE-Agent.ai
Co-Authored-By: SWE-Agent.ai <noreply@swe-agent.ai>
---------
Co-authored-by: SWE-Agent.ai <noreply@swe-agent.ai>
32 lines
1.0 KiB
Go
32 lines
1.0 KiB
Go
package main
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestParseJSONStream_SkipsOverlongLineAndContinues(t *testing.T) {
|
|
// Exceed the 10MB bufio.Scanner limit in parseJSONStreamInternal.
|
|
tooLong := strings.Repeat("a", 11*1024*1024)
|
|
|
|
input := strings.Join([]string{
|
|
`{"type":"item.completed","item":{"type":"other_type","text":"` + tooLong + `"}}`,
|
|
`{"type":"thread.started","thread_id":"t-1"}`,
|
|
`{"type":"item.completed","item":{"type":"agent_message","text":"ok"}}`,
|
|
}, "\n")
|
|
|
|
var warns []string
|
|
warnFn := func(msg string) { warns = append(warns, msg) }
|
|
|
|
gotMessage, gotThreadID := parseJSONStreamInternal(strings.NewReader(input), warnFn, nil, nil, nil)
|
|
if gotMessage != "ok" {
|
|
t.Fatalf("message=%q, want %q (warns=%v)", gotMessage, "ok", warns)
|
|
}
|
|
if gotThreadID != "t-1" {
|
|
t.Fatalf("threadID=%q, want %q (warns=%v)", gotThreadID, "t-1", warns)
|
|
}
|
|
if len(warns) == 0 || !strings.Contains(warns[0], "Skipped overlong JSON line") {
|
|
t.Fatalf("expected warning about overlong JSON line, got %v", warns)
|
|
}
|
|
}
|