orca icon indicating copy to clipboard operation
orca copied to clipboard

fix(orchestration): defer push-on-idle injection while user is typing

Open innocarpe opened this issue 4 months ago โ€ข 3 comments

Description

Orchestration push-on-idle still wrote banners into a pane where a human was typing (clobbering the draft) and could auto-submit with synthetic Enter when no active coordinator run was registered (#7391 only guarded the coordinator_handle match).

Focused fix

  • Defer delivery (no PTY write) when the leaf is user-focused โ€” messages stay undelivered for later idle
  • Skip synthetic Enter when there is no active coordinator run, or leaf is user-focused / Cursor / active coordinator
  • Pure helpers + runtime wiring in deliverPendingMessages
  • Out of scope: per-terminal --no-submit flag (#3034)

Preserves

  • Worker auto-submit under an active coordinator run when the pane is not user-focused
  • Cursor no-auto-submit behavior
  • Coordinator-handle no-Enter path

Evidence

  • injection-delivery.test.ts + focused orca-runtime cases (21 matched tests green)

User-regression-tradeoffs

  • Focused human panes no longer get banners mid-keystroke; delivery waits until focus leaves / next eligible idle
  • Without an active coordinator run, injected text is no longer auto-submitted (payload still written when unfocused)

Closes #11242

Made with Orca ๐Ÿ‹

innocarpe avatar Jul 29 '26 04:07 innocarpe

RetriggerView in GreptileConfidence Score: 4/5

[Medium impact] Defers orchestration writes while user is actively typing.

The typing-quiet mechanism successfully prevents clobbering user input, but timer cleanup is missing for retired PTYs

Findings

  1. P1ย Timer leak on PTY retirement โ–ถ

Summary

This PR fixes orchestration push-on-idle injection clobbering user input by deferring banner delivery and auto-submit when the user is actively typing. The implementation introduces a 5-second quiet window after keystrokes, checked before pointer writes and Enter submission.

Key changes:

  • Adds typing-quiet detection logic that defers delivery when window is focused and PTY has input in last 5s
  • Implements retry mechanism with per-mailbox timers to redeliver after quiet window expires
  • Wires timing state through PTY controller and runtime dependencies
  • Skips synthetic Enter when no active coordinator or user is typing

Diagram

sequenceDiagram
    participant User
    participant PTY
    participant Delivery
    participant TypingQuiet
    participant Timer
    participant Submit

    User->>PTY: keystroke
    PTY->>PTY: update lastInputAtByPty
    
    Note over Delivery: Orchestration message arrives
    Delivery->>TypingQuiet: defer(lastInputAt, now, focused)
    TypingQuiet->>TypingQuiet: "remaining = 5000 - (now - lastInputAt)"
    alt "remaining > 0"
        TypingQuiet->>Timer: setTimeout(redrive, remaining)
        TypingQuiet-->>Delivery: true (deferred)
        Note over Delivery: No PTY write
    else "remaining <= 0"
        TypingQuiet-->>Delivery: false (can deliver)
        Delivery->>PTY: write pointer banner
        Delivery->>Submit: schedule Enter after 500ms
        Submit->>TypingQuiet: shouldDefer?
        alt still typing
            TypingQuiet-->>Submit: true
            Submit->>Timer: scheduleTypingQuietRetry
            Note over Submit: Skip Enter, keep unread
        else quiet
            TypingQuiet-->>Submit: false
            Submit->>PTY: write Enter
        end
    end
    
    Timer->>Delivery: redrive after quiet window
    Delivery->>PTY: write pointer banner

Reviews (3) ยท Last reviewed commit: "fix(orchestration): settle failed pointe..." ยท Reviewed by Greptile

greptile-apps avatar Jul 29 '26 04:07 greptile-apps

Review Change Stack

[!IMPORTANT]

Review skipped

We couldn't safely recover the incremental review. No full review was started, and the last reviewed checkpoint was preserved. Retry later, or explicitly request a full review by commenting @coderabbitai full review.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • [ ] Trigger review

[!NOTE]

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

  • Last reviewed commit: 08a8085986b5ad28b1a1697c5e361f9d36b9a690
  • Latest commit, not reviewed: 69b6302f846d9ca2cba1bb7b8286fdd16aae1aa8

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • [ ] โ–ถ๏ธ Resume reviews
  • [ ] ๐Ÿ” Trigger review
Walkthrough

Orchestration mailbox delivery now tracks the latest renderer-accepted PTY input timestamp. Focused PTYs defer pointer writes during a five-second typing-quiet interval. A retry coordinator redrives deferred mailboxes after the interval. Pointer staging now handles PTY writes, delivery-flight finalization, mailbox watermark updates, Cursor redrives, and delayed Enter submission. Runtime wiring supplies PTY input, focus, clock, and write callbacks. Tests cover quiet-period decisions, deferred delivery, unfocused windows, missing input, and immediate delivery.

๐Ÿšฅ Pre-merge checks | โœ… 3 | โŒ 2

โŒ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check โš ๏ธ Warning The description explains the bug, fix, trade-offs, issue, and test evidence but omits most required template sections and visual-proof details. Use the repository template and add the missing ELI5, What Changed, Why, Visual Proof, Testing, checklist, and review sections.
Docstring Coverage โš ๏ธ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
โœ… Passed checks (3 passed)

Check name Status Explanation
Title check โœ… Passed The title clearly describes the primary change: deferring push-on-idle injection while the user is typing.
Linked Issues check โœ… Passed The changes address issue #11242 by deferring delivery during typing, delaying synthetic Enter, and preserving coordinator and Cursor protections.
Out of Scope Changes check โœ… Passed The implementation and tests remain focused on orchestration typing-quiet delivery and synthetic submission behavior described in issue #11242.
  • [ ] Autofix ยท Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

coderabbitai[bot] avatar Jul 29 '26 04:07 coderabbitai[bot]

Sync update (b2d038c6a)

Address review: require session.activeWorktreeId when classifying user-focused leaves so background workers no longer defer push-on-idle forever.

Regression: injection-delivery.test.ts covers background worktree + null active worktree.

  • Commit: b2d038c6a6d7b57b66a1531ea91e5d809e1f6ce0
  • Upstream: https://github.com/stablyai/orca/pull/11279
  • Fork portfolio: https://github.com/innocarpe/orca/pull/125

innocarpe avatar Jul 29 '26 23:07 innocarpe

Sync update (27427a5510)

Rebase onto latest upstream/main: keep message-delivery flights; defer push-on-idle injection while user-focused; synthesize Enter only for unattended workers under active run.

  • Commit: 27427a551011fd2ff590baada8078e10d36d8f0e
  • Upstream: https://github.com/stablyai/orca/pull/11279
  • Fork portfolio: https://github.com/innocarpe/orca/pull/125

innocarpe avatar Aug 06 '26 02:08 innocarpe

[!NOTE] GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

coderabbitai[bot] avatar Aug 06 '26 02:08 coderabbitai[bot]

#14832 is the pointer-era follow-up for the same submit-while-typing failure.

The proposed gate there is this PTY had user input in the last 5s and the Orca window is focused (then retry), rather than deferring only while the focused leaf matches. lastInputAtByPty is already per-terminal, so splits / clicking the editor still keep the draft attached to the PTY that received keys.

Tauri-EPO avatar Aug 16 '26 02:08 Tauri-EPO

[!NOTE] GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

coderabbitai[bot] avatar Aug 16 '26 07:08 coderabbitai[bot]

Follow-up for the pointer-era report on #14832 / #11242.

Rebased onto current main (delivery now lives in OrchestrationMailboxPointerDelivery) and replaced the focused-leaf gate:

  • Defer the pointer write when this PTY had renderer input in the last 5s (lastInputAtByPty via RuntimePtyController.lastUserInputAt) and an Orca window is focused (BrowserWindow.getFocusedWindow()), then retry after the remaining quiet time.
  • Skip the delayed Enter under the same predicate so we do not submit the draft. Pointer writes still do not stamp lastInputAtByPty.
  • Do not use tab.activeLeafId or INTERACTIVE_OUTPUT_WINDOW_MS.

Preserves: idle push still delivers after the quiet window; Cursor still skips Enter; no remote wire change.

Evidence: orchestration-typing-quiet + mailbox pointer typing-quiet + existing mailbox settlement/consistency tests โ€” 29 passed.

innocarpe avatar Aug 16 '26 07:08 innocarpe

[!NOTE] GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

coderabbitai[bot] avatar Aug 16 '26 13:08 coderabbitai[bot]

Follow-up for the 500ms Enter-window edge from #14852, plus CodeRabbit's synchronous writePty throw.

  • Skip Enter if this PTY is still in the 5s typing quiet window, keep delivered_at, and reschedule the run mailbox so later unread is not stranded.
  • A throwing pointer write now settles the flight instead of leaving it current.

Evidence: typing-quiet / stage / mailbox settlement tests โ€” 32 passed.

innocarpe avatar Aug 16 '26 23:08 innocarpe

Sync update (66b31c344)

Rebased onto current main after the PTY controller split. lastUserInputAt is wired through RuntimePtyController from lastInputAtByPty (renderer keystrokes only). An active coordinator Run does not bypass the 5s typing-quiet gate; pointer write and delayed Enter still defer while this PTY is being typed.

  • Commit: 66b31c344d267b4e162b6a01105cf33b01a9facb
  • Upstream: https://github.com/stablyai/orca/pull/11279
  • Fork portfolio: https://github.com/innocarpe/orca/pull/125

innocarpe avatar Aug 26 '26 09:08 innocarpe

Sync update (69b6302f84)

Rebased onto current upstream/main. The mailbox pointer write-failure test now uses the terminal argument. Typing-quiet tests: 11 passed.

  • Commit: 69b6302f846d9ca2cba1bb7b8286fdd16aae1aa8
  • Upstream: https://github.com/stablyai/orca/pull/11279
  • Fork portfolio: https://github.com/innocarpe/orca/pull/125

innocarpe avatar Nov 10 '26 06:11 innocarpe