Skip to content

fix(daemon): preserve attach output sequence baseline - #19593

Closed
xungua wants to merge 2 commits into
stablyai:mainfrom
xungua:xungua/pr-attach-sequence-20260908
Closed

xungua wants to merge 2 commits into
stablyai:mainfrom
xungua:xungua/pr-attach-sequence-20260908

Conversation

@xungua

@xungua xungua commented Sep 8, 2026 •

Copy link
Copy Markdown

ELI5

Reattached terminal output is counted once.

What Changed

Keep the attach-time sequence baseline and assert baseline plus streamed output equals the current sequence.

Why

Using the post-overlay snapshot sequence counts live output twice and causes false stream gaps.

Linked Issue

Fixes #19595.

Visual Proof

N/A — internal sequence accounting.

Testing

178 tests passed on macOS; reverting the fix fails the regression. Node typecheck, changed-file lint and formatting passed.

Full macOS validation (Node 24, pnpm 12): pnpm lint, pnpm typecheck, pnpm test --maxWorkers=4, and pnpm build all executed. Typecheck and complete desktop/Web/native build passed.

Full suite at 763963d6a4: 76,610 passed / 7 failed / 391 skipped. Final-HEAD serial follow-ups: 23 passed; performance/timeout failures cleared without relaxing assertions or policies.

Still failing: 4 real Claude CLI startup checks (5/10-second initialization deadlines) and 1 English runtime-catalog test. All reproduced on base bba68b1. Full lint fails on the same 7 catalog entries; later extraction/coverage gates passed separately. Full lint/test are not green.

  • Automated regressions added/updated.
  • Manual native Windows/Linux and live SSH QA: not run.

AI Disclosure

OpenAI Codex.

Review

Self-reviewed; Pullfrog reports no new issues. Human review pending.

Agent skill upstream boundary

  • N/A: no upstream agent-skill material copied.

Notes

No new permissions, platform-specific paths/shortcuts, Git commands or wire fields. Folder workspaces and remote ownership considered; full mobile/platform QA remains unrun.

Checklist

  • Small, focused change; problem and rationale explained.
  • Before/after proof attached, or N/A explained.
  • Correctness, security and performance reviewed.
  • Cross-platform, SSH and compatibility impact considered.
  • Full repository lint/typecheck/test/build executed; results above.
  • Full typecheck and build passed.
  • Full lint/test green: baseline failures documented above.

@coderabbitai

coderabbitai Bot commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 4ef90a51-4e0a-412b-9a30-607045455d84

📥 Commits

Reviewing files that changed from the base of the PR and between 91e2072 and 763963d.

📒 Files selected for processing (1)
  • src/main/daemon/daemon-restore-scrollback-depth.test.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 7 remain after this review.


📝 Walkthrough

Walkthrough

The reattach path now returns the original providerSequence from the attach operation. It no longer derives this value from the restored snapshot’s output sequence. Regression tests cover both spawn and attach, including output during history restoration, sequence reconciliation, snapshot recovery, cleanup, and later output progression.

Priority: ➖ Normal — Schedule the daemon reattach sequence fix because it prevents double-counted terminal output and false remote stream gaps across both attach flows.

Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 76396

Reattach now retains the original provider sequence while restoring terminal history, preventing false stream gaps and repeated recovery caused by double-counted output. The affected flows have regression coverage, with no active merge-blocking risk identified.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The changes satisfy issue #19595. They preserve the attach-time provider sequence, prevent double-counting during history restoration, cover both attach and spawn({ attachOnly: true }) flows, and add …
Out of Scope Changes check ✅ Passed All changed files support the linked issue. The implementation preserves sequence accounting, and the tests validate attach and spawn reattach behavior. No unrelated changes are identified.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 3…
Title check ✅ Passed The title clearly and concisely describes the primary change: preserving the attach-time output sequence baseline in the daemon.
Description check ✅ Passed The description includes all required sections, explains the problem and solution, links issue #19595, documents testing and known baseline failures, and identifies unrun platform and SSH validation.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Important

The fix is correct, but it changes behavior an existing test pins — daemon-restore-scrollback-depth.test.ts now fails and will block CI until that assertion is updated to the new baseline semantics.

Reviewed changes

  • Preserve attach baseline over post-drain sequence: the reattach branch in finishSpawn (src/main/daemon/daemon-pty-spawn-result.ts) now emits the original providerSequence (derived from the daemon attach response by providerSequenceFromCreateOrAttach) instead of recomputing it from reattachSnapshot.outputSequence.
  • Regression tests: new daemon-pty-attach-sequence.test.ts covers both spawn({ attachOnly: true }) and attach(), injecting 459 bytes during the durable-history overlay and asserting the next stream sequence stays contiguous.

⚠️ Stale post-drain sequence assertion now fails in daemon-restore-scrollback-depth.test.ts

The existing test uses the post-drain sequence for output produced during warm reattach (src/main/daemon/daemon-restore-scrollback-depth.test.ts:803) asserts expect(reattach.providerSequence?.value).toBe(current?.seq), which encodes the pre-fix behavior this PR removes. Running the daemon suite against this branch fails there: expected 60000 to be 60024. current.seq (60024) is the post-overlay sequence including the 24 injected bytes of FRESH_AFTER_CHECKPOINT\r\n, while providerSequence.value is now correctly the pre-overlay attach baseline (60000). This file is not in the PR diff and was not among the suites listed in the PR body's testing section, so it slipped through local validation; it will fail the full CI suite.

Technical details
# Update the stale reattach-baseline assertion

## Affected sites
- src/main/daemon/daemon-restore-scrollback-depth.test.ts:803 — `expect(reattach.providerSequence?.value).toBe(current?.seq)` pins the removed post-drain baseline.

## Required outcome
- The assertion must reflect the new semantics: `providerSequence.value` is the sequence captured at attach time, before the overlay's injected output is counted. Those injected bytes are streamed live (via `sequenceChars`) rather than folded into the baseline, so the test must assert the pre-overlay baseline (or otherwise prove the injected bytes are accounted exactly once).

## Suggested approach (optional)
- Capture the attach-time baseline (e.g. via a `getBufferSnapshot` taken before the injection, or by subtracting the injected payload length from `current.seq`) and assert `reattach.providerSequence.value` equals that, mirroring the assertion at `daemon-pty-attach-sequence.test.ts:78`.

Pullfrog  | Fix it ➔ | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ No new issues found.

Reviewed changes

  • Updated the warm-reattach restore-depth test to the new baseline semantics: daemon-restore-scrollback-depth.test.ts now captures the attach-time seq as a baseline before the overlay, asserts reattach.providerSequence.value equals that baseline (instead of the removed post-drain seq), and proves the overlay-injected bytes are counted exactly once by tracking streamedChars and checking providerSequence.value + streamedChars === current.seq. This resolves the prior review's stale-assertion finding; the 24-byte FRESH_AFTER_CHECKPOINT\r\n delta the old test pinned is now the live-streamed amount, not part of the baseline.

The fix itself (daemon-pty-spawn-result.ts emitting the attach-time providerSequence instead of reattachSnapshot.outputSequence) and the new daemon-pty-attach-sequence.test.ts were reviewed against the prior commit and are unchanged here. Both targeted suites pass (25 tests).

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

fabolivark added a commit to ab2webco/orca-oss that referenced this pull request Sep 9, 2026
…desbloquear el build de Android (#368)

* fix(terminal): finish a paste in the terminal that started it instead of cancelling on a focus blip

Problem: pasting into a terminal right after switching back to Orca (e.g.
Cmd+Tab to another app to copy, then Cmd+Tab back and immediately Cmd+V)
could show "Paste cancelled: terminal focus changed before paste started."
even though the paste target was correct. When the window regains OS
focus, regular-terminal-focus-ownership.ts's resyncTerminalFocusForWindowFocus
defers reclaiming the xterm helper textarea's DOM focus to the next
animation frame (intentionally, so a click elsewhere during reactivation
isn't yanked back). A Cmd+V fired via the app-menu paste path in that
window can capture document.body as the paste's activeElementAtDispatch
snapshot, before the deferred refocus lands.

Fix: isTerminalPanePasteFocusCurrent already treats a transient body/html
activeElement at paste time as inert and trusts the rest of the check: it
was missing the symmetric case where the *dispatch-time* snapshot itself
was body/html. Only reject as stale when the dispatch snapshot was a real,
different element outside the pane container; a body/html snapshot falls
through to the existing (already correct) final-activeElement checks. A
genuinely stale target (pane closed, focus moved to another real control)
is still rejected exactly as before.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
(cherry picked from commit a7e4893f2255f45dbd921365ebfbb0c6350e2d55)

* fix(runtime): honor caller deadline and abort on local runtime RPC

callRuntimeRpc honored timeoutMs and signal when the target was an
environment and discarded both when the target was local. Nothing
downstream compensated: the preload contract has no deadline on the
local call, and runtime:call dispatches with neither a race nor a
context signal, so ipcRenderer.invoke settles only when the handler
returns.

That made every caller deadline on the local path a no-op. The clearest
case is client-hosted-browser-row-close.ts, which defines a 15s constant
for a call whose target is hardcoded local, so the constant could never
take effect. The user visible symptom is the Automations tab: it mounts
with isLoading true, asks for a 15s deadline, and its finally block can
only run once the promise settles, so a stalled dispatch leaves the page
on its skeleton with no way back.

Bound the local call with the caller's timeoutMs and signal, reusing the
settle once bookkeeping and the error message from the environment path.
No default deadline is added, since long running local RPCs such as
git.fetch and worktree.create pass none on purpose.

(cherry picked from commit 3182aab1d6369eba360bfef8374db15536e18a96)

* fix(sidebar): keep project groups under their execution host

(cherry picked from commit f00a936a4969dbfd366cb3a673b974ca5a2d4b52)

* fix(daemon): conservar la linea base de secuencia al reatachar (upstream #19593)

Port de stablyai/orca#19593. Upstream lo arregla en `daemon-pty-spawn-result.ts`;
nuestro equivalente es `daemon-pty-adapter.ts` (mismo codigo, otra ruta tras la
divergencia). El diff de prod es identico al de upstream.

Al reatachar se tomaba la secuencia del snapshot POST-overlay en vez de la de
attach, asi que la salida recibida durante el overlay se contaba dos veces y el
cliente reportaba huecos de stream que no existian. Es el camino que corre en
cada reconexion contra un runtime remoto.

El test de nuestro arbol afirmaba el comportamiento viejo; se porta su
actualizacion tal cual (+15 -3).

* fix(terminal): make the Orca width provider measure emoji clusters like other terminals

A cursor-position probe (STA-6740) measured Orca advancing one cell for
sequences Windows Terminal and Ghostty advance two for. The cause is that
`OrcaUnicodeProvider` delegated every width decision to xterm's Unicode 11
tables, which measure single code points against a table frozen in 2018, while
the TUIs writing into the pane measure whole grapheme clusters against a
current one. Each cell of disagreement shifts the columns a TUI's next in-place
redraw erases and reprints over.

The provider is already the single width authority every Orca terminal
activates — the live renderer pane, the headless daemon mirror that
snapshot/restore serializes from, the dashboard preview, and the restore-parity
fixture. This teaches that one authority three cluster rules it was missing:

- U+FE0F promotes a valid emoji-variation base from one cell to two;
- a skin-tone modifier joins its base's cluster instead of claiming a second
  wide cell (a `+2` column shift for every glyph after it);
- emoji that default to emoji presentation but postdate Unicode 11 are two
  cells, not one.

Regional indicators are deliberately left alone: xterm has no grapheme
segmentation, so a flag already reaches two cells as 1 + 1.

U+FE0E text presentation is not implemented — it would have to narrow an
already-placed cluster, and xterm's printer only ever advances the cursor for a
joined code point.

Closes STA-6740.

(cherry picked from commit e949f3d422fd22f7e5406f96b09a2b4aed6ff35b)

* fix(terminal): scope the skin-tone rule to modifier bases, and gate the tables against staleness

Review findings on the width-authority change.

The skin-tone rule gated only on the preceding cell being two wide, never on it
being something a modifier can attach to. A modifier after a CJK ideograph
joined it: `中🏽` measured two cells where it measured four before. The rule now
also requires the preceding code point to be an emoji modifier base, which is
the standard's own definition of what a modifier may modify — tighter than
Extended_Pictographic and, for anything that is not a well-formed modifier
sequence, it restores exactly the measurement this provider had before.

The frozen tables could go stale the same way xterm's Unicode 11 table did, so
the derivation is now committed as a test: it re-derives all three tables from
the runtime's Unicode data and xterm's Unicode 11 provider and compares, and
reads nothing from the committed ranges to build that expectation. "No missing
entries" runs always — an older runtime cannot fail it spuriously — and exact
equality runs on the Unicode version the tables were generated against. The
module header now records why the tables are frozen at all: this width is a
cross-host contract and Electron, Node and the mobile JSC embed different ICU
versions, so deriving at runtime would make two Orca processes disagree about
one buffer.

Also: reuse the width the base provider already resolved instead of asking for
it twice on the hot path, and fix two comments that described the ZWJ case as a
control and claimed the reported symptom as established.

Refs STA-6740, STA-7066.

(cherry picked from commit a0d66b58eeb27b2a8356e1306a104dae69d5bb01)

* fix(terminal): typecheck the derivation gate, and catch a spurious range on any Unicode version

Two review findings on the staleness gate.

The unused `name` parameter in the lookup arm failed `tsc --noEmit` with TS6133
on all three projects, which would have reddened the CI typecheck job.

The gate also had a hole in one direction. Exact equality only runs when the
runner's embedded Unicode version matches the version the tables were generated
against, so a bogus entry inserted in sorted position went unnoticed anywhere
those versions differ — and they do differ, unpredictably, since the Node the
job installs carries whatever ICU that patch release shipped. A new arm closes
it without reintroducing that dependency: a committed code point the runtime
does not derive is a wrong entry, unless the runtime has never assigned that
code point at all, which is exactly how a table generated against a newer
Unicode looks from an older one. Both directions now run everywhere; exact
equality stays as the strictest form where the versions do line up.

Refs STA-6740.

(cherry picked from commit 6cb08ec2c1650652692945441c7f9486fe08fd61)

* fix(mobile): subir el versionCode de Android, que Play ya tenia usado

El build de Android fallo con `Google Api Error: Invalid request - Version code
21 has already been used.` El valor esta hardcodeado en `mobile/app.json:78`,
asi que CADA re-dispatch choca hasta que alguien lo sube a mano. iOS tiene
`bump_patch_version` en su workflow; Android no tiene equivalente para el
versionCode.

Esto sube 21 -> 22 para desbloquear el build. El arreglo de fondo —derivarlo o
auto-incrementarlo en el workflow— queda pendiente, porque hoy cada release
movil necesita este commit manual y es facil olvidarlo.

---------

Co-authored-by: Tan Vir <[email protected]>
Co-authored-by: Claude Fable 5.1 <[email protected]>
Co-authored-by: Alisson Linneker <[email protected]>
Co-authored-by: shuning <[email protected]>
Co-authored-by: Merge Sim <sim@local>
@xungua xungua closed this Oct 15, 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.

[Bug]: Daemon reattach double-counts output received during history restoration

1 participant