Skip to content

fix(test-classifier): --submit prompt dropped a typed answer (type-ahead) - #66

Merged
fg-nava merged 1 commit into
mainfrom
fix-submit-prompt-typeahead
Jun 24, 2026
Merged

fix(test-classifier): --submit prompt dropped a typed answer (type-ahead)#66
fg-nava merged 1 commit into
mainfrom
fix-submit-prompt-typeahead

Conversation

@fg-nava

@fg-nava fg-nava commented Jun 24, 2026

Copy link
Copy Markdown
Collaborator

Symptom

In your live run: a full OBSERVED classification posted the comment to navapbc/ai-chatbot#266 correctly (the #64 fix works ✓), then asked 'Was the classification helpful?', you typed y, and it printed:

--submit: no answer — skipping the metrics row (comment still posted).

The 👍 was lost; no Testing Events row.

Cause — type-ahead buffering

The prompt used a bare read -r answer on fd 0. During the multi-second streamed suite run, any stray newline/keystroke (and the agent's own Bash tool calls touching the TTY) queues in the terminal input buffer. read consumed that buffered line — usually empty, hitting the *) 'no answer' branch — while the y you typed at the prompt was handed back to the shell after the script exited. That's why y echoed but the script never saw it.

Fix

  • Open the controlling terminal once on fd 3 and read from it throughout, so the answer-read and the 👎 reason-read advance the same stream (re-opening /dev/tty per read restarts it and re-grabs the first line — that also fixes a latent bug where the 👎 reason captured n instead of the typed reason).
  • Flush pending type-ahead (read -t 0) before prompting, so only a fresh keypress is read.
  • Re-prompt up to 3× on unrecognized input instead of silently skipping — a stray char shouldn't throw away the row after a full suite run. An explicit empty Enter still skips.

Tested

Single-fd harness across input cases: plain y → 👍; stray char then y → re-prompts and recovers to 👍; n + reason → 👎 with the full reason string (previously n); empty Enter → skip. bash -n clean.

Note: the type-ahead flush can only be fully exercised on a real TTY (a piped file can't replicate terminal buffer timing), so the flush behavior is verified by construction, not by the harness.

Independent of the smolvm PR (#65); branches off main.

…ead)

Symptom: after a long OBSERVED run, answering 'y' at 'Was the classification
helpful?' still printed 'no answer — skipping the metrics row'. The comment
posted but the Testing Events row was dropped.

Cause: the prompt used a bare `read -r answer` on fd 0. During the multi-second
streamed suite run, stray newlines/keystrokes (and the agent's own Bash tool
calls perturbing the TTY) queue in the terminal input buffer. `read` consumed
that buffered line — usually empty → the `*)` 'no answer' branch — while the
'y' typed AT the prompt was handed back to the shell after the script exited
(hence 'y' echoed but never seen).

Fix:
  • open the controlling terminal ONCE on fd 3 and read from it throughout, so
    successive reads (answer, then the 👎 reason) advance the same stream rather
    than re-opening /dev/tty and re-grabbing the first line;
  • flush pending type-ahead (read -t 0) before prompting, so only a fresh
    keypress is read;
  • re-prompt up to 3× on unrecognized input instead of silently skipping — a
    stray char shouldn't discard the row after a full suite run; an explicit
    empty Enter still skips.

Tested the loop logic (single-fd harness): plain y → 👍; stray char then y →
re-prompts and recovers; n + reason → 👎 with the full reason string (previously
captured 'n'); empty Enter → skip.
@fg-nava
fg-nava merged commit 55c1e4b into main Jun 24, 2026
@fg-nava
fg-nava deleted the fix-submit-prompt-typeahead branch June 24, 2026 19:01
fg-nava added a commit that referenced this pull request Jun 24, 2026
…y, not fd 0 (#67)

Follow-up to #66. The helpfulness prompt reads from /dev/tty, but the early
'non-interactive' guard still tested fd 0 ([[ ! -t 0 ]]). During an OBSERVED run
the agent's Bash tool subprocesses (pnpm install, vitest, …) inherit the
dispatcher's fd 0 as their stdin and can leave it non-TTY / consumed-to-EOF by
the time --submit runs. The guard then reports 'non-interactive', returns early,
and the prompt is skipped silently — the comment posts but no 'Was this helpful?'
question appears and no Testing Events row is written. (Observed: a --submit run
ended at 'Comment posted … Awaiting the developer's reaction' with no prompt.)

Fix: gate on the SAME resource the prompt uses — whether /dev/tty can be opened
— instead of fd 0. CI / real non-TTY runs have no controlling terminal so they
still skip correctly. The probe ': <>/dev/tty' is set -e-safe inside the if.
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