Skip to content

[Bug]: Agent TUIs render dark in a light macOS pane — OSC 11 reply loses the race to the agent's DA1 sentinel (POSIX counterpart of #10492) #13908

Closed

Description

@rhlsthrm

Summary

On macOS, agent TUIs that probe the pane background with OSC 11 + a DA1 sentinel render dark inside a light Orca pane. This is the POSIX counterpart of the Windows symptom described in #10492 ("an agent's OSC 10/11 startup color probe often goes unanswered, so the agent falls back to its own default and paints a dark TUI inside a light pane") — same user-visible outcome, different host path.

Filing separately from #13892 because that issue reports the plumbing defect and its fish/stdin-leak surface; this is the agent-rendering surface. Close as duplicate if you'd rather track them together — but the reply-ordering fix proposed in #13892 should be regression-tested against a DA1-sentinel prober, not only against stdin leakage, and that test does not fall out of the fish repro.

Environment

  • Orca 1.4.180 (macOS, darwin 27.0.0)
  • macOS system appearance: Light; Orca pane renders light
  • Agent: omp (oh-my-pi) 17.2.14
  • No tmux / Zellij / screen; COLORFGBG unset in the pane shell

Symptom

omp selects its dark theme slot (titanium) in a visibly light pane. Configuring theme.light has no effect, because the light slot is never chosen — the light/dark decision, not the theme content, is what goes wrong.

Why a DA1-sentinel prober is specifically vulnerable

omp does not wait on a timeout for the OSC 11 reply. It emits the query and a DA1 immediately after, and treats DA1's arrival as proof that no color reply is coming. From the shipped 17.2.14 bundle (minified, names as emitted):

#n0(){ this.#_.push({kind:"osc11"}), this.#o0("\x1B]11;?\x07"), this.#o0("\x1B[c") }

The DA1 branch of its reply handler pops that pending osc11 entry and abandons the in-flight query. So for this class of prober, a late OSC 11 reply is not slow — it is a negative answer. An out-of-order reply and no reply at all are indistinguishable.

That makes the ordering inversion measured in #13892 (OSC 11 held 21–200 ms on the echo-safe queue; CPR/DA1 written immediately) sufficient on its own to produce this symptom, with no dropped bytes required.

Evidence and its limits

Verified:

  • omp's probe shape and its DA1-as-barrier handling, read from the installed bundle (quoted above).
  • omp's resulting fallback chain terminates in a hardcoded "dark" on this configuration — OSC 11 unresolved, COLORFGBG unset, and its detectMacOSAppearance fallback gated behind ZELLIJ, so never consulted here.
  • macOS is in Light mode; COLORFGBG is unset in the pane shell.

Not verified: I have not captured a byte-level trace of reply ordering inside my own pane, so the attribution to #13892's mechanism is inference from two code paths that fit, not a measured reproduction. Two hypotheses remain live from where I sit:

  1. Orca answers OSC 11, but the reply is deferred behind DA1 per [Bug]: OSC/DSR query replies are reordered behind CPR/DA1 by the POSIX echo-safe write path, stranding them into the next child's stdin #13892 → omp scores it negative.
  2. Orca does not answer OSC 11 on this path at all → same outcome.

Both terminate in the same place. #13892's measurements make (1) the stronger candidate on POSIX, and #6502 (v1.4.103, "answer OSC color queries from active terminal theme") argues against a blanket (2). A maintainer with the PTY-level instrumentation from #13892 can settle it in minutes; I'd rather report the symptom accurately than guess the layer.

Repro

  1. macOS in Light appearance, Orca pane rendering light.
  2. COLORFGBG unset; no multiplexer.
  3. Launch omp 17.2.14 in an Orca terminal pane with distinct light/dark theme slots configured, e.g.:
    theme:
      dark: titanium
      light: latte-glass
  4. Observe: the dark slot renders.

Expected: light slot, matching the pane.

Note on scope

There is an omp-side bug here too — its macOS appearance fallback is gated on ZELLIJ, so it hard-defaults to dark instead of asking the OS when the terminal can't be interrogated. That is independently fixable and not Orca's to fix, and I intend to report it upstream. It does, however, mean Orca panes are currently the layer that decides this outcome for omp users on macOS.

Related: #13892 (suspected mechanism), #10492 (same symptom, Windows/ConPTY), #6502 (color-query replies from active theme), #10913 (no mode 2031 on appearance change, so a live Light↔Dark flip won't reach a running agent either).

Activity

  1. manuaudio commented on Aug 12, 2026

    @manuaudio
    Contributor

    Your two hypotheses are not alternatives — both are real, on different surfaces, and which one you hit depends on whether the pane was visible when omp probed. That distinction matters here because #13892's FIFO fix repairs one of them and cannot repair the other.

    This is a source read against e172a51649 (origin/main), not a measured reproduction. I have not executed anything; the byte-level timing you declined to guess at is still unmeasured, and the last section is the cheapest way I can see to settle it from your seat.

    Visible pane: hypothesis (1), and it is structural rather than racy

    The reply chain for a visible pane is renderer xterm → window.api.pty.write (pty-transport.ts:582) → LocalPtyProvider.write (local-pty-provider.ts:1080). The split you suspected is that last function, in full:

    write(id: string, data: string): void {
      // Cooked PTYs echo private DSR/OSC replies; CPR/DA remain immediate (#13137, #7329).
      if (extractOnlyCookedEchoSafeQueryReplies(data)) {
        const ingress = startupIngressByPty.get(id)
        if (ingress?.answerLiveQueryReply(data)) return
      }
      ptyProcesses.get(id)?.write(data)
    }

    Checking omp's two replies against that predicate (terminal-query-reply.ts:78-114):

    • \x1b]11;rgb:2828/2c2c/3434\x1b\\ matches COOKED_ECHO_RISK_OSC_PREFIX_RE (:47) → answerLiveQueryReply → PtyStartupIngress.answerLiveQueryReply (pty-startup-ingress.ts:97) → delivery.answer → deferred, since defersWrite() is true for posix-pty (pty-startup-reply-delivery.ts:81-83).
    • \x1b[?1;2c matches neither prefix — the private-DSR prefix ^\x1b\[\?[0-9;]*n requires a final n, and DA1 ends in c. extractOnlyCookedEchoSafeQueryReplies returns null → straight to ptyProcesses.get(id)?.write(data).

    So DA1 overtakes OSC 11 on the live visible-pane path, exactly as your inference predicted. Your #13892 measurements were taken on the startup-ingress path; this is the same delivery object reached through a different door, and the door does not change the branch.

    The part I think is new: the inversion is guaranteed, not probable — which is the mechanism behind the "deterministic, not racy" you observed in #13892 but did not attribute.

    isCoalescibleText (pty-input-write-queue.ts:33-38) refuses to coalesce exactly the payloads that need the echo-safe path:

    // Echo-risk replies stay atomic so host classifiers cannot miss them (#13137).
    return text.length <= TERMINAL_INPUT_COALESCE_MAX_CODE_UNITS && !needsCookedEchoSafeQueryReply(text)

    That guard is what forces OSC 11 to arrive at write() as its own call rather than batched with the DA1 behind it. Had the two ever been coalesced into one payload, extractOnlyCookedEchoSafeQueryReplies would return null on the mixed string (:107-109) and both would have gone out immediately, in order, with no leak and no inversion. The atomicity guard added for #13137 is precisely what makes the split unavoidable rather than occasional. Any fix should expect that: you cannot dodge this by letting them ride together, because the guard exists to stop the classifier missing the OSC reply.

    Hidden or parked pane: hypothesis (2), with its own mechanism

    Hypothesis (2) is not merely the residual possibility you left open — it has a specific, deliberate implementation, on the headless path (orca-runtime.ts:11524 → headless-emulator.ts:125 → terminal-view-attribute-responder.ts):

    /** Last renderer push, or null before the first push. Null means SILENCE
     *  for every view-attribute query — a fabricated default would resurrect
     *  the default-black OSC-11 bug (design invariant 3). */
    getBaseAttributes: () => TerminalViewAttributes | null

    handleSpecialColor (:84-106) only calls reportColor when base is truthy, and then returns true unconditionally — consuming the sequence so the headless core's own handler never fires. getTerminalViewAttributes() really can be null; the call site two lines below the responder install guards on exactly that (orca-runtime.ts:11525-11528). So before the first renderer attribute push, an OSC 11 query on a hidden pane is swallowed and unanswered.

    That invariant is correct against the prober it was written for. It assumes a prober that times out — silence buys a fallback that is at least not wrong-and-confident. omp is the class you documented in this issue: it treats DA1 as proof that no reply is coming, so silence is not "wait longer", it is an immediate negative. Design invariant 3 chose silence over a fabricated default specifically to avoid resurrecting default-black; for a DA1-sentinel prober those two options converge on the same rendered outcome.

    Consequence for the fix in #13892: the answerInOrder FIFO repairs the visible-pane surface, because there a reply exists and only its order is wrong. It cannot repair the headless surface, because there is no reply to order. Your instinct to file separately was right, and it is a stronger reason than the one you gave — this is not only a second regression surface for one fix, it is a surface that fix does not reach.

    The measurement that would refute this

    The attribution above is a code read, and the cheapest thing that kills it is timing, which needs no Orca instrumentation. In an Orca pane, time a lone CPR against a lone OSC 11:

    import os, sys, time, termios, tty, select
    fd = sys.stdin.fileno(); old = termios.tcgetattr(fd)
    def probe(q, label):
        tty.setraw(fd); buf = b''; t0 = time.monotonic()
        try:
            os.write(1, q)
            while time.monotonic() - t0 < 1.0:
                if not select.select([fd], [], [], 1.0 - (time.monotonic() - t0))[0]: break
                buf += os.read(fd, 64)
                if buf.endswith((b'\x1b\\', b'\x07')) or buf.endswith(b'R'): break
        finally:
            termios.tcsetattr(fd, termios.TCSADRAIN, old)
        print(f'{label}: {(time.monotonic()-t0)*1000:7.2f} ms  {buf!r}')
    probe(b'\x1b[6n', 'CPR   ')
    probe(b'\x1b]11;?\x1b\\', 'OSC 11')

    Three outcomes, and they separate cleanly:

    Run it once in a pane that has been visible and focused for a while, and once in a freshly restored pane, and the second run separates the two surfaces rather than just the two hypotheses.

    One further prediction that discriminates if the first outcome holds, offered as unverified: under (1) the OSC 11 bytes are not dropped, they land in the tty ~200 ms late while omp is in raw mode and has already abandoned the pending entry. They then reach omp's key decoder as input. Whether that is observable depends on how omp handles an unrecognized OSC in its input stream, which I have not read — but if a stray sequence or spurious input event is visible at agent startup, that is (1) rather than (2), with no timing harness at all.

  2. added theissue type on Sep 19, 2026
  3. nwparker commented on Sep 19, 2026

    @nwparker
    Contributor

    Audit update (current main, 2026-09-19): the hidden/parked path intentionally consumes OSC 10/11/12 and DSR ?996n without replying until the renderer has pushed terminal attributes. src/main/daemon/terminal-view-attribute-responder.ts:24-27,84-95 documents the invariant: fabricating a default would recreate the historical default-black OSC-11 bug. The regression tests pin this silence in src/main/runtime/terminal-query-responder.test.ts:165-181.

    The visible-path reply-ordering work is represented by #13998, but it cannot fix this pre-attribute hidden-pane case because there is no reply to reorder. OMP's DA1-sentinel probe treats silence as a negative answer, so this is a real compatibility gap, but an Orca-only fallback needs a trustworthy per-pane theme snapshot; guessing a default would create a user-facing dark/light regression. I am keeping this open as a separate, evidence-backed follow-up rather than weakening the existing safety invariant.

  4. nwparker commented on Sep 19, 2026

    @nwparker
    Contributor

    Current main now combines the ordered OSC/CPR reply path with the renderer terminal-attribute bridge. Verification passed: 182 focused daemon/query/PTY tests, including the termenv OSC-then-CPR ordering contract, plus the 95-case terminal-query responder suite and renderer attribute suites. OMP source behavior was also exercised read-only. Closing as fixed; reopen with a current-build trace if reproduced.

  5. nwparker commented on Sep 19, 2026

    @nwparker
    Contributor

    Fixed by query-reply ordering and terminal-attribute bridge.

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

    bugSomething isn't workingos:Windowsos:macosIssues affecting macOS

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions