Skip to content

fix(kiro): EBADF crash fix + dynamic context window + default model#152

Merged
royosherove merged 1 commit into
mainfrom
fix/detached-ebadf-containers
Jun 15, 2026
Merged

fix(kiro): EBADF crash fix + dynamic context window + default model#152
royosherove merged 1 commit into
mainfrom
fix/detached-ebadf-containers

Conversation

@royosherove

@royosherove royosherove commented Jun 15, 2026

Copy link
Copy Markdown
Member

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.

Note: the initial commit on this branch flipped detached to false; that was not the real cause and was reverted on main. detached: true is retained (matches MeshClaw's start_new_session=True, needed for clean process-group kill). The shipped fixes are below (merged to main, released in v0.6.2).

Fixes

1. Remove terminal capability (the real EBADF cause)

clientCapabilities: { terminal: true } in ACP initialize made 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 with error: 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 to clientCapabilities: {}.

2. Default model = claude-sonnet-4.6 (kiro mode)

The roundhouse kiro agent used kiro's auto mode. Now pins claude-sonnet-4.6 via kiro-cli acp --model, configurable through agent.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 via kiro-cli chat --list-models (sonnet-4.6 = 1,000,000), falling back to 200k only when unknown.

Verification

  • 626 unit tests pass
  • Live Slack→kiro round-trip confirmed: no EBADF, startup logs [kiro] spawned agent=roundhouse model=claude-sonnet-4.6 window=1,000,000 tokens, no spurious first-message compaction.

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.
@royosherove royosherove merged commit c027823 into main Jun 15, 2026
1 check passed

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

@royosherove royosherove changed the title fix(kiro): disable detached spawn to prevent EBADF in containers fix(kiro): EBADF crash fix + dynamic context window + default model Jun 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant