Skip to content

[PIR #1920] Tower PTYs get TERM=xterm-256color; claude gate accepts the ASCII-fallback > marker - #1928

Merged
amrmelsayed merged 22 commits into
mainfrom
builder/pir-1920
Nov 18, 2026
Merged

amrmelsayed merged 22 commits into
mainfrom
builder/pir-1920

Conversation

@amrmelsayed

@amrmelsayed amrmelsayed commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

PIR Review: Architect mail held with no-composer-marker on Windows

Fixes #1920

Summary

On native Windows, mail to the main architect was held with busy:no-composer-marker after a Tower restart, and the hold never cleared. The cause was the environment, not the gate's logic. node-pty sets TERM from its name option only on POSIX, and architects launch as bare claude, with Tower's env and no TERM. With no Unicode signal in its env on win32, claude draws its figures ASCII fallbacks: the composer marker becomes > followed by U+00A0 instead of ❯, and the claude gate profile only matched ❯/›.

Builders never showed this, because Git Bash sets TERM=xterm-256color before claude starts. The fix has two parts:

  1. Every Tower-launched PTY child now gets TERM=xterm-256color, enforced at the spawn chokepoint. New sessions draw ❯.
  2. The claude profile also accepts the ASCII marker, so sessions already drawn in fallback mode (including the live architects at install time) deliver without a restart.

Files Changed

  • codev/plans/1920-tower-mail-to-the-architect-he.md (+214 / -0)
  • codev/projects/1920-tower-mail-to-the-architect-he/status.yaml (porch state)
  • codev/resources/arch.md (+2 / -0)
  • codev/reviews/1920-tower-mail-to-the-architect-he.md (this file)
  • codev/resources/lessons-learned.md (+2 / -0)
  • codev/state/pir-1920_thread.md (+23 / -0)
  • packages/codev/scripts/spec-1658-conpty-capture.mts (+24 / -5)
  • packages/codev/src/agent-farm/__tests__/fixtures/gate/README.md (+19 / -0)
  • packages/codev/src/agent-farm/__tests__/fixtures/gate/claude-conpty-ghost-idle-ascii.replay.bin.gz (new, binary)
  • packages/codev/src/agent-farm/__tests__/fixtures/gate/conpty/conpty-claude-ascii-draft.capture.jsonl.gz (new, binary)
  • packages/codev/src/agent-farm/__tests__/fixtures/gate/conpty/conpty-claude-ascii-idle.capture.jsonl.gz (new, binary)
  • packages/codev/src/agent-farm/__tests__/fixtures/gate/conpty/conpty-claude-ascii-midturn.capture.jsonl.gz (new, binary)
  • packages/codev/src/agent-farm/__tests__/fixtures/gate/conpty/conpty-claude-ascii-prefix-left.capture.jsonl.gz (new, binary)
  • packages/codev/src/agent-farm/__tests__/helpers/conpty-replay.ts (+6 / -0)
  • packages/codev/src/agent-farm/__tests__/render-gate.test.ts (+76 / -0)
  • packages/codev/src/agent-farm/__tests__/spec-1658-conpty-gate-replay.test.ts (+2 / -1)
  • packages/codev/src/agent-farm/servers/gate-profiles.ts (+25 / -1)
  • packages/codev/src/agent-farm/servers/render-gate.ts (+2 / -1)
  • packages/codev/src/lib/agent-env.ts (+23 / -0)
  • packages/codev/src/terminal/__tests__/pty-terminal-type.test.ts (+72 / -0)
  • packages/codev/src/terminal/__tests__/session-manager-spawn-config.test.ts (+25 / -4)
  • packages/codev/src/terminal/__tests__/session-manager.test.ts (+24 / -1)
  • packages/codev/src/terminal/pty-session.ts (+6 / -3)
  • packages/codev/src/terminal/session-manager.ts (+7 / -4)

Commits

Test Results

  • npm run build: ✓ pass
  • npm test (full packages/codev suite, on native Windows, after rebasing onto Fix #1922: full suite on native Windows no longer stops the live Tower; fix EPERM at its cause #1926): ✓ pass. It passed at porch done (134.4s) and again on the porch approve re-check (129.7s). The first attempt timed out at 300s because several builders were running the full suite at once; it passed once the runs were serialized.
  • New tests:
    • render-gate.test.ts: 10 cases in "claude's ASCII-fallback composer marker (Issue tower: mail to the architect held with no-composer-marker after a Tower restart on Windows #1920)":
      • the derived ghost fixture is clean, and is no-composer-marker under the old pattern;
      • NBSP, space, and bare > idle lines are clean;
      • typed text is user-text;
      • a > … echo above the composer is clean;
      • an ASCII picker is user-text;
      • a parked ghost is clean, while inverse plus non-dim is user-text;
      • >> and >foo are no-composer-marker;
      • codex > stays no-composer-marker.
    • pty-terminal-type.test.ts: the helper, and the non-shellper PtySession.spawn (name and env.TERM).
    • session-manager*.test.ts: TERM at first spawn on win32 and linux, an inherited xterm replaced, and the crash and clean-exit relaunch SPAWN frames.
    • spec-1658-conpty-gate-replay.test.ts: the four new real bare-env claude 2.1.327 captures (idle, draft, prefix-left, midturn) replay with the expected verdicts.
  • Windows workflow (on demand, suites): https://github.com/cluesmith/codev/actions/runs/44242152525
  • Manual verification:
    • Before the fix: a read-only viewer attach captured the held main architect's screen. It showed > + U+00A0, which classifies no-composer-marker under the old profile and clean under the new one.

    • Dev approval: the owner installed this build on their Windows machine and restarted Tower. Mail to main now delivers. The backlog held as no-composer-marker delivered on install:

      The 2026-11-02 cron (dc384851) was superseded by the 00:00Z team-update row and did not deliver.

Architecture Updates

COLD: codev/resources/arch.md, "PTY Environment". TERM is now enforced at the spawn chokepoint by withPtyTerminalType(), at four places:

  • the shellper config;
  • both relaunch SPAWN frames;
  • the non-shellper PtySession.spawn.

The same entry explains why (node-pty sets TERM on POSIX only), and that the claude gate profile accepts the ASCII-fallback marker while codex keeps the strict one. Nothing hot-tier: the mailbox and gate invariant in arch-critical.md is unchanged.

Lessons Learned Updates

COLD: codev/resources/lessons-learned.md, Testing ([From #1920]). A fixture recorder that adds environment that production does not add records a screen that production never shows. Spec 1658's recorder set TERM itself, so every capture drew ❯ and the suite stayed green while real architects drew >. Record with the env the production launch path builds, and put any deviation behind a named switch (--bare-env).

Not routed, but worth knowing: launchers.windows.test.ts (before #1926) stopped the live Tower on port 4100 during a local full-suite run. #1926 added the guard.

Things to Look At During PR Review

  • The ASCII ghost-cursor fixture is derived, not recorded. claude-conpty-ghost-idle-ascii.replay.bin.gz is the real M15 capture with every ❯ replaced by >; no other byte changed. Six idle recordings of claude 2.1.327, with the bare env and the normal env, never drew the inverse software cursor, so the focused state could not be recorded live. It shows that isGhostCursorCell's first-input-cell anchor holds with a one-column ASCII marker. It does not prove claude draws exactly that screen.

  • The marker regex (gate-profiles.ts, CLAUDE_COMPOSER_MARKER): > must be followed by a space, U+00A0, or end of line. Without that lookahead, >>, >foo or a quoted > line would read as a marker. The last-match-wins search plus the region-end rule requirement still bound the composer. A transcript > … echo above the composer is fine: the composer's own marker is the last match.

  • TERM is overwritten, not defaulted. An inherited xterm (mintty) fails claude's win32 Unicode check, and the PTY really is xterm-256color. The change is in shared code; on POSIX node-pty already set the same value from name, so behaviour there is unchanged.

  • No hold became a force-inject. The gate still requires a clean, bounded composer region; only the set of accepted marker glyphs grew.

  • Consultation (single pass): codex APPROVE, claude APPROVE, gemini COMMENT (lane skipped: agy CLI not installed). Claude noted three minors, all applied after the consultation: the NBSP test constant is now the escape \u00a0 (a literal could silently normalise to a space); the CLAUDE_COMPOSER_MARKER doc names its known boundary (no agy-style cursor-row/palette anchor, so a single > item below the composer with a rule beneath it would read as an empty region; never observed); this file list was corrected. Claude also confirmed the chokepoint holds because session.options.env is wrapped at every client.spawn read, not at its writes.

How to Test Locally

  • View diff: VSCode sidebar → right-click builder pir-1920 → View Diff
  • Run dev: VSCode sidebar → Run Dev, or afx dev pir-1920
  • What to verify:
    • On Windows, install the build and restart Tower. afx send architect "…" to an idle architect reports delivered, not held … no-composer-marker.
    • A newly started architect draws ❯ (its env has TERM=xterm-256color).
    • npx vitest run src/agent-farm/__tests__/render-gate.test.ts src/agent-farm/__tests__/spec-1658-conpty-gate-replay.test.ts src/terminal/__tests__/session-manager.test.ts src/terminal/__tests__/session-manager-spawn-config.test.ts src/terminal/__tests__/pty-terminal-type.test.ts (from packages/codev).

Flaky Tests

  • packages/codev/src/__tests__/tower-lifecycle.windows.test.ts, "Phase 4 (b): started from inside a session job, Tower is created through CIM and survives the session teardown, with its shellper". Windows workflow run 44242152525, first attempt: Tower 3432 died with the session job (before teardown: inJob=False jobOpened=True procOpened=True ppid= created= …), and the CIM lookup returned null. The failed job passed on rerun. The same test failed on bugfix-1922's run 44237325105, before this branch's changes, with connect ECONNREFUSED. Left running, not skipped.

node-pty sets TERM from its name option on POSIX only. On Windows an agent
launched straight into ConPTY (the architect's bare claude) got only the TERM
in Tower's inherited env, often none, and claude then drew its ASCII
fallbacks, including a '>' composer marker the render gate did not match.
Applied at the shellper first-spawn config, both relaunch SPAWN frames, and
the non-shellper PtySession.spawn.
…arker

Heals architects already running with the fallback screen (their env cannot
change until claude relaunches). The pointer is followed by U+00A0 in fallback
mode; '>' must be followed by a space or end the row. Codex keeps its pattern.
The recorder injected TERM itself, so no fixture showed the screen production
architects drew. --bare-env records without it; four real captures of claude
2.1.327 (idle, draft, prefix-left, midturn) join the replay suite.
@amrmelsayed
amrmelsayed merged commit d623f6c into main Nov 18, 2026
8 checks passed
amrmelsayed added a commit that referenced this pull request Nov 18, 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.

tower: mail to the architect held with no-composer-marker after a Tower restart on Windows

1 participant