fix(kiro): EBADF crash fix + dynamic context window + default model#152
Conversation
Node.js spawn with detached:true causes 'Bad file descriptor (os error 9)' in containerized environments (e.g. AgentSpaces, Docker). The child process inherits stdio pipes that become invalid when detached from the parent's process group. Setting detached:false fixes the issue. Process cleanup still works via direct proc.kill() — the process group kill (killGroup) is a fallback that's unnecessary when the parent manages the child directly.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c50eab8e4f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| env: { ...process.env, ...env }, | ||
| stdio: ["pipe", "pipe", "pipe"], | ||
| detached: true, // own process group for clean kill | ||
| detached: false, // disabled: detached causes EBADF in containers |
There was a problem hiding this comment.
Preserve a force-kill path after disabling detached
With detached: false, the spawned kiro-cli no longer owns a process group whose id is proc.pid, but shutdownProcess() still falls back to killGroup(), which calls process.kill(-proc.pid, "SIGKILL") and suppresses the resulting failure. In the scenario this fallback is meant for—kiro-cli ignores SIGTERM or leaves descendants running—the 5s grace timer resolves without killing anything, leaking the process while the caller believes shutdown completed.
Useful? React with 👍 / 👎.
Summary
Fixes kiro-cli ACP integration in containerized / daemonized environments (AgentSpaces, Docker) where the agent crashed on every prompt, plus two related kiro-mode improvements.
Fixes
1. Remove
terminalcapability (the real EBADF cause)clientCapabilities: { terminal: true }in ACPinitializemade kiro-cli try to use a PTY file descriptor during tool execution. In a daemon / redirected-stdio context (no controlling TTY) that fd is invalid → kiro-cli exits code 1 witherror: Bad file descriptor (os error 9)on the first prompt. MeshClaw's proven-working ACP client declares no terminal capability for the same reason. Changed toclientCapabilities: {}.2. Default model =
claude-sonnet-4.6(kiro mode)The roundhouse kiro agent used kiro's
automode. Now pinsclaude-sonnet-4.6viakiro-cli acp --model, configurable throughagent.model. (Pi mode controls its model separately — unchanged.)3. Dynamic context window (kiro mode)
The adapter hardcoded a 200k window. kiro reports context usage as a percentage with no window in ACP metadata, so multiplying by 200k produced wrong token counts and tripped percent-based compaction thresholds —
auto's real 1M window meant ~42% base context was read as near-limit, firing flush+compact on message one.resolveWindow()now maps the active/configured model to its real window viakiro-cli chat --list-models(sonnet-4.6 = 1,000,000), falling back to 200k only when unknown.Verification
[kiro] spawned agent=roundhouse model=claude-sonnet-4.6 window=1,000,000 tokens, no spurious first-message compaction.