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

Offen
#659 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Anfängerfreundlichkeit
52/100
Issue-Typ
Bug
Klarheit
Größtenteils klar
Aktivitätsstatus
Aktiv
Tech-Stack
node.js, typescript
Bereich
cli

Rechercherichtung

Beginne mit dem interaktiven TUI-Dispatch für die Ereignishandler run_end und onRunEnd und reproduziere dann das Problem mit dem bereitgestellten mod unter Verwendung von fetch und cmd.exec. Vergleiche das Verhalten der interaktiven TUI mit der headless-Ausführung von -p; abgeschlossen ist die Aufgabe, wenn Promises nach dem Turn zuverlässig aufgelöst oder abgelehnt werden und Subprozesse zurückkehren, ohne dass ein Hilfsprozess erforderlich ist.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

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.

Vorherrschende Sprache
Keine Sprachdaten
Sterne
4k
Forks
350
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus CommandCodeAI/command-code

Alle Issues in CommandCodeAI/command-code

Ähnliche Issues

Weitere Issues zu CLI

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.