Skip to content

fix(skills): payload-cli's PTY driver stalls — chalk colours break its prompt regex - #762

Merged
Ardnived merged 7 commits into
mainfrom
claude/fix-751-pty-ansi-prompts
Sep 12, 2026
Merged

Ardnived merged 7 commits into
mainfrom
claude/fix-751-pty-ansi-prompts

Conversation

@sydevs-bot

@sydevs-bot sydevs-bot commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • interactive.py answers drizzle's rename-vs-create prompt again — it now matches on ANSI-stripped text, while the log keeps the raw, coloured bytes.
  • A prompt the driver cannot parse ends the run with exit 3 and the last 200 characters, instead of hanging until the caller's timeout kills it. It arms on an unanswered question only.
  • The driver gets its first gate: four cases drive it over a real PTY against a fake child, so no database and no schema change are needed.

Changes

  • .claude/skills/payload-cli/interactive.py — strip ANSI (SGR and private-mode) before matching; give up loudly on an unanswered prompt; PAYLOAD_PTY_CWD and PAYLOAD_PTY_STALL_SECONDS overrides.
  • .claude/skills/payload-cli/test_interactive.py — new. Run with python3 .claude/skills/payload-cli/test_interactive.py.
  • .claude/skills/payload-cli/SKILL.md — the fourth bug, exit 3, the overrides, the stall bound's two constraints, and how to run the self-test.

Preview

Preview pending — Railway posts the URL as a commit status once the PR environment deploys. No application code changed, so it exercises nothing new.

Test results

  • Lean gate: ✓ .claude/skills/pr-prep/check.sh — lint, typecheck (src), typecheck (tests), 1671 unit tests in 128 files.
  • Targeted specs: 14 checks passed in test_interactive.py.
  • Build: N/A — no application code changed.

Each case was watched failing against its own defect, reintroduced at the site that caused it: matching on raw text (4 assertions red), the give_up call removed (4 red), the narrow ANSI class restored (4 red), unanswered() back to a bare QUESTION_LINE search (2 red), give_up exiting 4 (1 red), the PAYLOAD_PTY_CWD lookup removed (1 red).

Manual verification

  1. Make any schema change, run the driver as SKILL.md documents it, and confirm grep -c '\[pty\] answered' /tmp/payload-pty.log is greater than zero and a migration file appears. The self-test proves the prompt-matching, but only a real drizzle run proves the prompt text still looks the way this driver expects.

Notes for reviewer

  • The ticket's "this one has to be done attended" warning is stale. chore(claude): let the loop edit docs, rules, skills and guides unattended #667 already granted Edit(.claude/skills/**) / Write(.claude/skills/**), and the files here were written from the shell in any case, so Protected Paths never came up. Worth correcting wherever else that warning is repeated.
  • PAYLOAD_PTY_CWD does not revert alone. An earlier version of this body claimed it did. It sits in 9004694 with the ANSI strip and give_up, and splitting it now means rewriting pushed history, which this branch does not do. It removes the reason the feat(translations): rewrite the Sahaj Atlas schema by widget view, seed all ten locales, and gate availableLocales on them #706 workaround needed a patched copy four directories deep.
  • The stall detector is a heuristic, and can be wrong. It fires when the buffer holds a question line this driver never answered and nothing at all has been written for 240 seconds. Any output restarts the clock, and PAYLOAD_PTY_STALL_SECONDS raises the bound. A false positive costs a re-run with a message saying exactly that; the failure it replaces cost 400 seconds and said nothing.
  • The bound is pinned from both sides. 240 clears the 2m08s config boot src/migrations/AGENTS.md:48-52 measured twice, and stays under the caller's 300s timeout so a genuine hang still ends with a message rather than a bare exit 124.
Detail

Why the old regex failed. On a PTY chalk colours the column and table names, so the bytes are Is \x1b[1m\x1b[34mcommon_chrome\x1b[39m\x1b[22m column in … and \w+ cannot span the escapes. Starting migration and Accept warnings and push schema to database? are uncoloured and kept matching, which is why the phase-boundary reset looked healthy right up to the first real prompt.

The strip takes ? in its parameter class. \x1b[?25l / \x1b[?25h are the cursor hide/show a prompt library wraps a select in, and [0-9;]* could not match them. Left in, the cursor-show lands after the question mark, so QUESTION_LINE's \?[ \t\r]*$ stops matching and an unanswerable prompt hangs again — the exact failure exit 3 exists to replace.

One clock was never the problem; the buffer was. A first draft tracked last_answer beside last_output so an answered prompt's echo could not read as a new one. The echo is output, so it already restarts last_output. But it also lands back in buf and stays there, armed, and the next quiet stretch gave up over a prompt the driver had answered. unanswered() fixes that at the buffer, matching each question line against what seen records.

The hang case needs two assertions, not one. subprocess kills a timed-out child, so returncode != 0 held for the hang as much as for the intended exit 3 — it could not fail, and stayed green while four assertions beside it went red. It now asserts returncode == 3, the code SKILL.md and src/migrations/AGENTS.md tell a caller to read.

Not wired into CI. The file is a skill asset, outside every lane this repo runs. ubuntu-latest does ship python3, so a unit spec could shell out to it — the cost is wall-clock, since the cases wait on real PTY clocks (~35s) against a 17s unit lane. Left open for the reviewer. SKILL.md says to run it after touching the driver.

Closes #751

🤖 Generated with Claude Code

https://claude.ai/code/session_012tsfQ56ZoU9hXgNjppCCkR

`interactive.py` exists so `migrate:create` cannot hang on drizzle's
rename-vs-create prompt. It stopped answering that prompt: the child runs on
a PTY, so chalk colours the column and table names, and `\w+` cannot span the
escapes now sitting inside the match:

    Is \x1b[1m\x1b[34mcommon_chrome\x1b[39m\x1b[22m column in …

`Starting migration` and the data-loss prompt still matched, because chalk
does not colour those — which is why the phase-boundary reset looked healthy
right up to the first real prompt. The driver then waited until the caller's
`timeout` killed it: exit 124, no migration, and nothing in the log saying
why.

Match on an ANSI-stripped copy. The bytes going to `/tmp/payload-pty.log`
stay raw, so the log still shows what the terminal saw.

A question left silent for `PAYLOAD_PTY_STALL_SECONDS` (default 90) now ends
the run with exit 3 and the last 200 characters, rather than letting the
caller's `timeout` decide between the two documented failure modes. Ordinary
work does not trip it: any output restarts the clock, drizzle's re-render of
an answered prompt included.

`PAYLOAD_PTY_CWD` runs the child somewhere other than the repo root this file
sits in, so a patched copy no longer has to live four directories deep.

Refs #751

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01DfBVHWawcqnWmwCaR9DCjC
The driver has now shipped four silent bugs and had no gate at all. Its own
documented check needs a schema change and a database, so nobody ran it.

Three cases drive the real driver over a real PTY against a node child that
prints one prompt: the coloured rename prompt from a real log, an
unparseable question that must end the run, and `PAYLOAD_PTY_CWD`. Each was
watched failing against its own defect reintroduced at the site that caused
it.

The hang case needs the `driver ended on its own` assertion beside the exit
code: a killed process also exits non-zero, so `returncode != 0` passes for
the hang this case exists to catch.

Run it with `python3 .claude/skills/payload-cli/test_interactive.py`. It is
not wired into CI — the file is a skill asset, outside every lane.

Refs #751

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01DfBVHWawcqnWmwCaR9DCjC
The sentence filing this bug is the only thing standing between the next
reader and the same 400-second wait, so the count in the heading is
load-bearing rather than decorative.

Also documents exit 3, the two environment overrides, and the self-test,
none of which the driver had before.

Closes #751

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01DfBVHWawcqnWmwCaR9DCjC
@railway-app

railway-app Bot commented Sep 10, 2026 •

Copy link
Copy Markdown

🚅 Deployed to the SahajCloud-pr-762 environment in sahajcloud

Service Status Web Updated
SahajCloud ✅ Success (View Logs) Web Sep 12, 2026 at 12:11 am UTC
1 service not affected by this PR
  • mailpit

@sydevs-bot

sydevs-bot commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor Author

🤖 no session running

recent dispatches
  • 00:00Z address-review · attempt 1 · session · done
  • 00:00Z address-review · attempt 1 · session
  • 23:52Z adversarial-review · attempt 1 · session · done
  • 23:52Z adversarial-review · attempt 1 · session
  • 21:36Z adversarial-review · attempt 2 · session · done

Written by the sydevs dispatcher. Sessions never edit this comment.

@sydevs-bot sydevs-bot added bot:working Lock: a cloud session is running on this item. Removed when it ends. awaiting and removed bot:working Lock: a cloud session is running on this item. Removed when it ends. labels Sep 10, 2026
@sydevs-bot

Copy link
Copy Markdown
Contributor Author

The session for this item did not finish after 3 attempts. I have stopped retrying. A comment, a verb, or a push from you starts me again.

🤖 sydevs dispatcher

@sydevs-bot sydevs-bot added bot:working Lock: a cloud session is running on this item. Removed when it ends. awaiting and removed awaiting bot:working Lock: a cloud session is running on this item. Removed when it ends. labels Sep 10, 2026
@sydevs-bot

Copy link
Copy Markdown
Contributor Author

The session for this item did not finish after 3 attempts. I have stopped retrying. A comment, a verb, or a push from you starts me again.

🤖 sydevs dispatcher

@sydevs-bot sydevs-bot added bot:working Lock: a cloud session is running on this item. Removed when it ends. awaiting and removed awaiting bot:working Lock: a cloud session is running on this item. Removed when it ends. labels Sep 10, 2026
@sydevs-bot

Copy link
Copy Markdown
Contributor Author

The session for this item did not finish after 3 attempts. I have stopped retrying. A comment, a verb, or a push from you starts me again.

🤖 sydevs dispatcher

@sydevs-bot sydevs-bot added bot:working Lock: a cloud session is running on this item. Removed when it ends. awaiting and removed bot:working Lock: a cloud session is running on this item. Removed when it ends. labels Sep 11, 2026
@sydevs-bot

Copy link
Copy Markdown
Contributor Author

The session for this item did not finish after 3 attempts. I have stopped retrying. A comment, a verb, or a push from you starts me again.

🤖 sydevs dispatcher

@sydevs-bot sydevs-bot added bot:working Lock: a cloud session is running on this item. Removed when it ends. awaiting and removed awaiting bot:working Lock: a cloud session is running on this item. Removed when it ends. labels Sep 11, 2026
@sydevs-bot

Copy link
Copy Markdown
Contributor Author

The session for this item did not finish after 3 attempts. I have stopped retrying. A comment, a verb, or a push from you starts me again.

🤖 sydevs dispatcher

@sydevs-bot sydevs-bot added bot:working Lock: a cloud session is running on this item. Removed when it ends. and removed awaiting labels Sep 11, 2026

@sydevs-bot sydevs-bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

🧐 Adversarial review

Holistic. The three-line ANSI strip is the ticket's ask, and is right. Around it the diff grew to ~3×: 126 of 198 lines are an unrequested, un-run self-test, plus a stall detector and two knobs. I would not merge the detector. Its 90s default is under this repo's measured 2m08s silent boot (src/migrations/AGENTS.md:48-52), and it cannot tell an answered prompt from an unparsed one.

Findings

  • should-fix interactive.py:115 — arms on answered prompts and misreports them.
  • should-fix interactive.py:63 — 90s default is under the documented 128s boot.
  • consider interactive.py:68 — ANSI misses \x1b[?25l, the bug being fixed.
  • consider interactive.py:59 — PAYLOAD_PTY_CWD does not revert alone, per the body.
  • consider test_interactive.py:5 — prose-run, and one assertion cannot fail.

Checked. #751, the PR body, three commits, both .py files whole, payload-cli/SKILL.md, src/migrations/AGENTS.md:38-78 — exit 3 lands in its "Other error" row. Consumers: AGENTS.md:75, migrations/AGENTS.md:47,73,74.

🤖 Written by the sydevs autonomous loop — see what this is


Generated by Claude Code


python3 .claude/skills/payload-cli/test_interactive.py

Nothing in CI runs this. It exists because the driver has now shipped four

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Worth asking what this earns. It is 126 lines against a 59-line fix, and the only thing that runs it is a sentence in SKILL.md — the same prose-only enforcement that let four bugs ship. Could pnpm test:unit shell out to it, or is a Python step not worth it in that lane?

Line 95 also asserts returncode != 0, which the PR body says passed against the reintroduced defect. An assertion that cannot fail is worth deleting — line 94 already carries the case.

🤖 Written by the sydevs autonomous loop — see what this is


Generated by Claude Code

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Assertion adopted in dc7b7f9, as returncode == 3 rather than a deletion — exit 3 is the contract SKILL.md and the migrations guide tell a caller to read. Watched failing with give_up exiting 4. It stayed green today while 4 assertions beside it went red.

On CI: ubuntu-latest ships python3, so a spec could shell out. The cost is wall-clock — the cases wait on real PTY clocks, ~35s, against a 17s unit lane. Your call.

🤖 Written by the sydevs autonomous loop — see what this is


Generated by Claude Code

@sydevs-bot sydevs-bot added bot:working Lock: a cloud session is running on this item. Removed when it ends. and removed bot:working Lock: a cloud session is running on this item. Removed when it ends. labels Sep 12, 2026
The detector could not tell an answered prompt from an unparsed one.
Answering clears `buf`, but drizzle re-renders the prompt afterwards and
that echo lands straight back in it. The echo is output, so it restarts
the silence clock and cannot trip the detector itself — but it stays in
`buf` armed. The next genuinely quiet stretch, the migration write or a
slow boot, then exits 3 saying "saw a prompt I could not parse" about a
prompt the driver did answer.

`unanswered()` matches each question line against what `seen` already
records, so only a question this driver never answered can end the run.

The new case drives the real driver over a PTY: answer a coloured prompt,
echo it back, then go silent past the bound. Watched failing against the
defect reintroduced at its own site — `unanswered(stalled)` back to
`QUESTION_LINE.search(stalled)` — 2 of its 3 assertions red.

Reported in review: #762 (comment)

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_012tsfQ56ZoU9hXgNjppCCkR
The 90s default sat under this repo's own documented silence.
`src/migrations/AGENTS.md` records `db:migrations:create` booting the
Payload config in 2m08s, twice, and that measurement is why the caller's
`timeout` is 300 and not 150. A healthy run that went quiet for 128s
exited 3.

240 clears the measured boot and still ends the run before the caller's
300s bound, so a genuine hang keeps its useful message instead of a bare
exit 124.

Reported in review: #762 (comment)

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_012tsfQ56ZoU9hXgNjppCCkR
`[0-9;]*` cannot take `?`, so `\x1b[?25l` and `\x1b[?25h` survived the
strip — the cursor hide/show a prompt library emits around a select.

That is the same shape as the bug this branch fixes, an escape sitting
inside the text we match on, and it has a concrete cost: the cursor-show
lands after the question mark, so `QUESTION_LINE`'s `\?[ \t\r]*$` stops
matching and an unanswerable prompt hangs again, which is the failure
exit 3 exists to replace.

The existing unparsed-prompt case now ends its question with `\x1b[?25h`.
Watched failing against the narrow class restored: 4 of its 5 assertions
red, the driver hanging until the test's own timeout killed it.

Reported in review: #762 (comment)

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_012tsfQ56ZoU9hXgNjppCCkR
`returncode != 0` could not fail. `subprocess` kills a timed-out child, so
a hang gives a non-zero code too — the PR body already recorded it passing
against the reintroduced defect, and it did so again in this session while
four assertions beside it went red.

Exit 3 is the contract `payload-cli/SKILL.md` and `src/migrations/AGENTS.md`
tell a caller to read, so assert that instead of deleting the line. Watched
failing with `give_up` exiting 4.

Reported in review: #762 (comment)

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_012tsfQ56ZoU9hXgNjppCCkR
@railway-app
railway-app Bot temporarily deployed to sahajcloud / SahajCloud-pr-762 September 12, 2026 00:09 Destroyed
@sydevs-bot

Copy link
Copy Markdown
Contributor Author

Addressed the adversarial review. Pushed dc7b7f9, one commit per thread.

Adopted

Open. That thread also asks whether test:unit should shell out. It can — ubuntu-latest ships python3 — but the cases wait ~35s on real clocks against a 17s lane. Your call.

Detector stays, both findings fixed. 14 checks, each watched failing.

🤖 Written by the sydevs autonomous loop — see what this is


Generated by Claude Code

@sydevs-bot sydevs-bot removed the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Sep 12, 2026
@sydevs-bot
sydevs-bot marked this pull request as ready for review September 12, 2026 00:19
@sydevs-bot
sydevs-bot requested a review from Ardnived September 12, 2026 00:19
@Ardnived
Ardnived merged commit c98c763 into main Sep 12, 2026
49 of 54 checks passed
@Ardnived
Ardnived deleted the claude/fix-751-pty-ansi-prompts branch September 12, 2026 03:33
@sydevs-bot sydevs-bot moved this from Revising to Done in SYDevelopers Technical Roadmap Sep 12, 2026

This branch was successfully deployed

No deployments
sahajcloud / SahajCloud-pr-762 — dc7b7f9d Deployed Sep 12, 2026 by railway-app[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

fix(skills): payload-cli's PTY driver stalls — chalk colours break its prompt regex

3 participants