Bug: async work (fetch / cmd.exec) inside mod event handlers is dropped or never resolves in the interactive TUI

オープン
#659 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
52/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
node.js, typescript
領域
cli

調査の方向性

run_end および onRunEnd イベントハンドラーのインタラクティブ TUI dispatch から始め、提供された mod で fetch と cmd.exec を使って問題を再現します。インタラクティブ TUI の動作と headless な -p 実行を比較します。完了の条件は、ターン後の promise が確実に resolve または reject され、ヘルパープロセスを必要とせずにサブプロセスが戻ることです。

索引モデルが issue の本文から書いたものです。

説明

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
  • onRunEnd is documented as "awaited before the run_end event" — the hook itself runs, but its async body doesn't complete.
  • cmd.exec inside onRunEnd/run_end shows the same behavior (starts, never returns).
  • This is why the docs' "must-complete work" claim for onRunEnd doesn'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.

主要言語
言語のデータがありません
スター
4k
フォーク
350
PR マージ指標
30日以内にマージされた PR はありません

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

CommandCodeAI/command-code のほかの issue

CommandCodeAI/command-code の issue をすべて見る

似ている issue

CLI の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。