CommandCodeAI / CommandCodeAI/command-code
Bug: async work (fetch / cmd.exec) inside mod event handlers is dropped or never resolves in the interactive TUI
還沒有人認領這個 Issue。
- 主要語言
- 沒有語言資料
- 星號
- 4k
- 分支
- 350
- PR 合併指標
- 30 天內沒有已合併 PR
描述
Bug: async work (fetch / cmd.exec) inside mod event handlers is dropped or never resolves in the interactive TUI
Summary
When a mod runs fetch (or cmd.exec) inside an event handler like run_end or onRunEnd, the promise never resolves in the interactive TUI — even though the same call resolves in ~1s standalone. The mod's async work is silently dropped, so post-turn hooks that do network I/O never complete.
Repro
Minimal mod:
export default function (cmd: any) {
cmd.on('run_end', (event) => {
void fetch('https://api.commandcode.ai/provider/v1/chat/completions', {
method: 'POST',
headers: {'Content-Type': 'application/json', Authorization: 'Bearer ' + require('node:fs').readFileSync(require('node:os').homedir() + '/.commandcode/auth.json', 'utf8') /* parse */},
body: JSON.stringify({model: 'moonshotai/Kimi-K2.7-Code-Highspeed', messages: [{role: 'system', content: 'Reply OK'}], max_tokens: 10}),
signal: AbortSignal.timeout(60_000),
})
.then(r => console.error('RESOLVED', r.status))
.catch(e => console.error('FAILED', e.message));
});
}
Expected: RESOLVED 200 within ~2s of the run ending.
Actual: neither RESOLVED nor FAILED ever logs — the promise never settles. Same with cmd.exec({command: 'curl', ...}) inside onRunEnd: the exec starts (a telltale writes) but never returns.
Evidence (from the suggester mod's debug log)
20:31:39.354 run_end fired, scheduling regenerate
20:31:39.385 fetch: attempt 0 start
20:32:00.078 fetch: attempt 0 status=200 ← resolves 21s later, or never in some runs
Timing is inconsistent: sometimes it resolves after ~20s, sometimes never. In the interactive TUI it's far more likely to never resolve than in headless -p.
What I had to do to work around it
Spawn a standalone helper process (a separate node script) from the mod: the mod writes a request file (sync), spawns the helper with child_process.spawn, and the helper does the fetch in a normal process where it works reliably. This is ugly but necessary — in-module async network I/O is not dependable.
Notes
onRunEndis documented as "awaited before the run_end event" — the hook itself runs, but its async body doesn't complete.cmd.execinsideonRunEnd/run_endshows the same behavior (starts, never returns).- This is why the docs' "must-complete work" claim for
onRunEnddoesn't hold for I/O.
Environment
- Command Code 1.15.0, macOS 26 (arm64)
- Mods loaded from
~/.commandcode/mods/(user scope)
Impact
Any mod that does network I/O or subprocess work in a post-turn hook is unreliable. The workaround (helper process) is a significant complexity tax on mod authors.
貢獻指南
這個儲存庫沒有索引到貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
從 run_end 和 onRunEnd 事件處理常式的互動式 TUI dispatch 開始,然後使用提供的 mod 搭配 fetch 和 cmd.exec 重現該問題。比較互動式 TUI 的行為與 headless -p 執行;完成的標準是 turn 後的 promise 能可靠地 resolve 或 reject,且子程序不需要輔助程序即可返回。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- node.js, typescript
- 領域
- cli
- Issue 類型
- 缺陷
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 活躍度
- 活躍
- 描述清晰度
- 基本清楚
- 新手友好度
- 52/100