swe-agent[bot]
220be6eb5c
fix: 修复channel同步竞态条件和死锁问题
...
修复了4个严重的channel同步问题:
1. **parseCh无条件阻塞** (main.go:894-907)
- 问题:cmd.Wait()先返回但parseJSONStreamWithLog永久阻塞时,主流程卡死
- 修复:引入ctxAwareReader和5秒drainTimer机制,Wait完成后立即关闭stdout
2. **context取消失效** (main.go:894-907)
- 问题:waitCh先完成后不再监听ctx.Done(),取消信号被吞掉
- 修复:改为双channel循环持续监听waitCh/parseCh/ctx.Done()/drainTimer
3. **parseJSONStreamWithLog无读超时** (main.go:1056-1094)
- 问题:bufio.Scanner阻塞读取,stdout未主动关闭时永远停在Read
- 修复:ctxAwareReader支持CloseWithReason,Wait/ctx完成时主动关闭
4. **forceKillTimer生命周期过短**
- 问题:waitCh返回后立刻停止timer,但stdout可能仍被写入
- 修复:统一管理timer生命周期,在循环结束后Stop和drain
5. **并发竞态修复**
- main.go:492 runStartupCleanup使用WaitGroup同步
- logger.go:176 Flush加锁防止WaitGroup reuse panic
**测试覆盖**:
- 新增4个核心场景测试(Wait先返回、同时返回、Context超时、Parse阻塞)
- main.go覆盖率从28.6%提升到90.32%
- 154个测试全部通过,-race检测无警告
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com >
2025-12-08 23:35:55 +08:00
swe-agent[bot]
da257b860b
fix: 增强日志清理的安全性和可靠性
...
必须修复的问题:
1. PID重用防护 - 添加进程启动时间检查,对比文件修改时间避免误删活动进程的日志
- Unix: 通过 /proc/<pid>/stat 读取进程启动时间
- Windows: 使用 GetProcessTimes API 获取创建时间
- 7天策略: 无法获取进程启动时间时,超过7天的日志视为孤儿
2. 符号链接攻击防护 - 新增安全检查避免删除恶意符号链接
- 使用 os.Lstat 检测符号链接
- 使用 filepath.EvalSymlinks 解析真实路径
- 确保所有文件在 TempDir 内(防止路径遍历)
强烈建议的改进:
3. 异步启动清理 - 通过 goroutine 运行清理避免阻塞主流程启动
4. NotExist错误语义修正 - 文件已被其他进程删除时计入 Kept 而非 Deleted
- 更准确反映实际清理行为
- 避免并发清理时的统计误导
5. Windows兼容性验证 - 完善Windows平台的进程时间获取
测试覆盖:
- 更新所有测试以适配新的安全检查逻辑
- 添加 stubProcessStartTime 支持PID重用测试
- 修复 setTempDirEnv 解析符号链接避免安全检查失败
- 所有测试通过(codex-wrapper: ok 6.183s)
Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com >
2025-12-08 10:53:52 +08:00
freespace8
33149d9615
feat(cleanup): 添加启动时清理日志的功能和--cleanup标志支持
2025-12-07 12:28:06 +08:00
cexll
3bc8342929
fix codex wrapper async log
2025-12-02 16:54:43 +08:00
cexll
d51a2f12f8
optimize codex-wrapper
2025-12-02 15:49:36 +08:00
dnslin
595fa8da96
fix(logger): 保留日志文件以便程序退出后调试并完善日志输出功能
2025-12-01 17:55:39 +08:00
cexll
246674c388
feat: add async logging to temp file with lifecycle management
...
Implement async logging system that writes to /tmp/codex-wrapper-{pid}.log during execution and auto-deletes on exit.
- Add Logger with buffered channel (cap 100) + single worker goroutine
- Support INFO/DEBUG/ERROR levels
- Graceful shutdown via signal.NotifyContext
- File cleanup on normal/signal exit
- Test coverage: 90.4%
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude <noreply@anthropic.com >
2025-11-29 22:40:19 +08:00