Skip to content

--print / -p non-interactive mode: TTY hang + 400 developer role rejected by third-party APIs #883

Description

@naaika50

Bug: --print / -p non-interactive mode hangs with TTY and fails with third-party APIs

Summary

The --print (-p) non-interactive flag has two critical bugs that make it unusable:

  1. Hangs forever when stdin is a TTY (normal terminal) — never exits
  2. 400 error with third-party APIs — sends role: "developer" which most OpenAI-compatible APIs reject

Environment

Kimchi version 0.1.72
OS Windows 11
Shell PowerShell / Git Bash
Install method kimchi update (binary)
Config Multi-model with 7 modelRoles configured

Reproduction: Bug #1 — TTY Hang

# This hangs FOREVER (no exit, no output beyond config warnings):
kimchi -p --no-session "Say hello"

# Expected: process prompt, print response, exit
# Actual: hangs indefinitely, must Ctrl+C

Workaround (forces non-TTY):

kimchi -p --no-session "Say hello" < /dev/null 2>&1
# This EXITS, revealing the underlying API error

Root cause: When stdin is a TTY, kimchi initializes the full interactive TUI even in -p mode. The --mode rpc output shows it gets stuck at:

{"method":"setStatus","statusKey":"permissions-mode","statusText":"default"}
{"method":"setStatus","statusKey":"active-tags","statusText":"phase: explore"}

After this — no further output. Agent is waiting for user interaction that never comes.

Flags tested that DON'T fix it:

  • --yolo → still hangs
  • --auto → still hangs
  • --plan → still hangs
  • --no-session → still hangs
  • --mode json → still hangs
  • --mode rpc → shows init messages then hangs

Reproduction: Bug #2400 developer Role Error

# Non-TTY mode reveals the underlying API error:
kimchi -p --no-session "Say hello" < /dev/null 2>&1

# Output:
# Error: 400 developer is not one of ['system', 'assistant', 'user', 'tool', 'function']
# EXIT: 1

Session log evidence (~/.config/kimchi/harness/sessions/.../...jsonl):

"errorMessage":"400 developer is not one of ['system', 'assistant', 'user', 'tool', 'function']"

This error repeats across ALL retries (3 retries × multiple turns) before the exploration guard triggers.

Root cause: Kimchi's harness sends system-level messages with role: "developer" (OpenAI's newer role for o1/gpt-4o+ models). However, most third-party OpenAI-compatible APIs only accept ['system', 'assistant', 'user', 'tool', 'function'] and reject developer.

Providers tested — ALL failed with developer role:

Provider Model Error
freetokenfaucet2 qwen3.7-plus 400 developer is not one of [...]
aiand zai-org/glm-5.2 403 Forbidden (or 400)
aiand2 deepseek-v4-pro 403 Forbidden
hcnsec DeepSeek-V4-Flash Timeout
opnegateway tencent/hy3:free Error
bynara1 tencent-hy3 Error
cccctoken gpt-5.5 Error

What DOES Work

Only kimchi-dev provider succeeds:

kimchi -p --provider kimchi-dev --model deepseek-v4-flash --no-session "Say hello" < /dev/null

# Output: "Hello! How can I help you today?"
# EXIT: 0

Confirmed working models on kimchi-dev: deepseek-v4-flash, minimax-m3, kimi-k2.7


Current Multi-Model Config (failing)

{
  "modelRoles": {
    "orchestrator": "freetokenfaucet2/qwen3.7-plus",
    "planner":     "opnegateway/tencent/hy3:free",
    "builder":     "aiand2/zai-org/glm-5.2",
    "reviewer":    "aiand/zai-org/glm-5.2",
    "explorer":    "aiand2/deepseek-ai/deepseek-v4-pro",
    "researcher":  "bynara1/tencent-hy3",
    "compactor":   "aiand/zai-org/glm-5.2"
  }
}

All 7 roles use third-party APIs → all fail with 400 developer error.


Expected Behavior

  1. -p should NOT initialize TUI when stdin is a TTY — it should run in true non-interactive/headless mode and exit after processing
  2. -p should work with third-party APIs — either use role: "system" instead of role: "developer", or auto-detect and fall back

Suggested Fixes

Fix 1: TTY detection in -p mode
When -p flag is set, force non-interactive/headless code path regardless of TTY detection.

Fix 2: developersystem role fallback
Either change the harness to use role: "system" by default (all APIs support this), or detect the 400 developer error and retry with role: "system".

Fix 3: Better error surface in non-interactive mode
When -p mode encounters an API error after all retries, print the error to stderr and exit with non-zero code, rather than entering the interactive retry/session loop.


Note on developer role

The developer role is an OpenAI-specific feature for newer models (o1, gpt-4o, etc.). Most open-source model APIs and third-party proxies use pydantic validation that strictly checks for ['system', 'assistant', 'user', 'tool', 'function']. Using role: "system" would be universally compatible while still functioning identically on OpenAI's API (which accepts both).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs-triageNewly opened, not yet reviewed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions