Commit 9644a00
fix: auto-resolve question tool in non-interactive contexts (#937)
* fix: auto-resolve question tool in non-interactive contexts
`Question.ask()` awaits an Effect Deferred that only resolves on a
TUI click. When `altimate-code run` is invoked as a subprocess
(Claude Code's Bash tool, CI, plugin host) and a skill that uses
`question` fires, nobody can ever click — the deferred awaits
forever and the parent eventually TaskStops the subprocess. The
symptom is indistinguishable from a hang: 0% CPU, no log activity,
no error.
In non-interactive contexts (no TTY, or explicit env-var opt-in),
auto-resolve `question` with a conservative-by-default policy and
flag the auto-answer in the tool result so the calling LLM can
adapt instead of treating it as a real user choice.
Resolution policy (env-var controlled):
- Detect non-interactive: `!process.stdin.isTTY`. Overrides:
ALTIMATE_FORCE_INTERACTIVE=1 — keep the original interactive
Deferred path even when isTTY is false.
ALTIMATE_NON_INTERACTIVE=1 — force non-interactive even when
isTTY is true (useful for tests + CI assertions).
- Default in non-TTY (ALTIMATE_AUTO_ANSWER=last): pick the option
whose label/description contains a safe keyword (skip, cancel,
no, abort, profile only, decline, deny, stop); fall back to the
last option (UX convention: safer/cancel typically sits at end).
- ALTIMATE_AUTO_ANSWER=first / =skip / =<exact label>: explicit
overrides for callers who want a specific behavior.
Tool result prefix reflects mode — "Running in non-interactive
mode (no TTY). Auto-answered with safe defaults: ..." vs the
original "User has answered your questions: ..." — so the agent
knows the choice was not a real user answer.
Tests: 6 new bun:test cases covering safe-keyword selection,
last-option fallback, each ALTIMATE_AUTO_ANSWER mode, and the
prefix wording. Existing 2 legacy tests gated with
ALTIMATE_FORCE_INTERACTIVE=1 so they preserve their original
intent under non-TTY CI.
Closes #936
* fix(question): return Unanswered in non-interactive mode
The earlier non-interactive policy in this branch scanned option label
text for "safe" keywords (skip/cancel/no/abort/...) and fell back to
the last option. That tried to recover semantics the LLM already knew
at construction time, and false-positived on substrings — "no"
matched inside "Snowflake", "Annotate", "Knowledge", "Honor".
The fix: don't guess. Return Unanswered for every question when no TTY
is present and let the agent decide. The agent has full context — it
knows what action it was about to take and why it asked. It can pick
a safe path from that context or report that user input is required.
Pretending a decision was made that wasn't is the worse failure mode.
Changes:
- Drop SAFE_KEYWORDS and the label-text scan entirely.
- Default non-interactive behavior returns [] (renders as "Unanswered"
via the existing format()).
- Cache isNonInteractive() once at execute() entry so the result
prefix can't disagree with the path that produced the answer.
- Non-interactive prefix tells the agent how to proceed AND names the
escape hatch (ALTIMATE_AUTO_ANSWER=first|last|<label>) so it can
surface it to the user when reporting back.
- Keep =first / =last / =<exact label> as explicit user opt-ins for
callers who genuinely want a default. Drop =skip — it's the new
default.
Addresses cubic-dev-ai review feedback on #937 by removing the
heuristic that needed the word-boundary fix in the first place.
Tests: 9 pass / 0 fail in packages/opencode/test/tool/question.test.ts.
Refs #936
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* fix(question): address PR #937 consensus review findings
Five fixes flowing from the multi-model consensus review on the prior
revision. Touches the `run` entrypoint, the bash tool, the question tool,
and its tests.
- `run.ts:447`: `process.stdin.isTTY` was still dereferenced without a
guard. The prior commit closed null-safety in `question.ts` only;
this closes the same risk in the `run` entrypoint. Addresses the
dev-punia-altimate review comment in full.
- `run.ts` handler: gate the `ALTIMATE_NON_INTERACTIVE=1` assignment on
`!args.attach`. In attach mode the agent runs on the remote server,
so the local env var is a no-op and only pollutes the local process
env for other tools that may consult it.
- `bash.ts`: strip `ALTIMATE_NON_INTERACTIVE` from `mergedEnv` before
`spawn`. Without this, child processes spawned by the bash tool
(e.g. nested `altimate-code serve`) would inherit the flag from the
parent `run` process and silently disable their own HTTP question-
reply path — the exact regression the prior commit is fixing for
other surfaces.
- `question.test.ts`: regression tests for
`ALTIMATE_FORCE_INTERACTIVE=1` precedence over `NON_INTERACTIVE=1`
and for `ALTIMATE_NON_INTERACTIVE=0` honored as explicit opt-out.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* fix(question): close stdin stall + test isolation gap from PR #937 review
Two small fixes flagged by coderabbit + cubic on the prior commit
(d2a8516).
- `run.ts:459`: the `!process.stdin?.isTTY` null-safety guard turned a
crash (undefined stdin) into a stall (we still entered the branch
and awaited `Bun.stdin.text()` on a stream that would never EOF).
Use `process.stdin && !process.stdin.isTTY` so undefined stdin
skips the read entirely — the only sensible behavior in an embedded
runtime where there is no stdin to read from.
- `question.test.ts`: the `tool.question non-interactive auto-answer`
describe block sets `ALTIMATE_NON_INTERACTIVE=1` in beforeEach but
didn't clear `ALTIMATE_FORCE_INTERACTIVE`. A parent-shell export
could silently flip the suite to the interactive path and lose
non-interactive coverage. Delete in both hooks.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Haider <haider@altimate.ai>
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 37072bc commit 9644a00
4 files changed
Lines changed: 381 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
368 | 368 | | |
369 | 369 | | |
370 | 370 | | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
371 | 395 | | |
372 | 396 | | |
373 | 397 | | |
| |||
430 | 454 | | |
431 | 455 | | |
432 | 456 | | |
433 | | - | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
434 | 465 | | |
435 | 466 | | |
436 | 467 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
168 | 168 | | |
169 | 169 | | |
170 | 170 | | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
171 | 180 | | |
172 | 181 | | |
173 | 182 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
6 | 60 | | |
7 | 61 | | |
8 | 62 | | |
9 | 63 | | |
10 | 64 | | |
11 | 65 | | |
12 | | - | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
17 | 82 | | |
18 | 83 | | |
19 | 84 | | |
| |||
22 | 87 | | |
23 | 88 | | |
24 | 89 | | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
25 | 98 | | |
26 | 99 | | |
27 | | - | |
| 100 | + | |
28 | 101 | | |
29 | 102 | | |
30 | 103 | | |
| |||
0 commit comments