Skip to content

fix: consolidate agent prompt and mailbox PTY delivery ownership - #16198

Open
Jinwoo-H wants to merge 3 commits into
mainfrom
aug23-triage-sta4495-5122-5150
Open

Jinwoo-H wants to merge 3 commits into
mainfrom
aug23-triage-sta4495-5122-5150

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 13 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1450 $\color{#cf222e}{\Huge{\mathbf{−}}}$​103 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1347
Prod 21 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1465 $\color{#cf222e}{\Huge{\mathbf{−}}}$​399 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1066

Summary

  • centralize prompt, automation, interactive, query, and paste arbitration in the provider-owned PTY input transaction
  • replace fixed-delay prompt submission races with readiness/foreground/lifecycle fencing
  • durably stage mailbox pointer attempts immediately before provider transport writes; classify post-attempt rejection/timeout as operation_unknown and suppress replay
  • fence inactive unknown watermarks so newer mail cannot enter a residual prompt

Validation

  • deterministic readiness oracle: latest origin/main 1/7, candidate 7/7
  • full focused gate: 18 files, 1,393 tests, 1 skipped
  • SSH/daemon/mailbox gate: 13 files, 225 tests
  • node typecheck, oxlint, max-lines ratchet, diff check
  • Electron E2E attempts reached documented seeded-worktree/Codex fixture preconditions before product assertions

No new wire fields or host-receipt claims are introduced. Provider transport publication remains distinct from execution-host receipt.

@Jinwoo-H
Jinwoo-H force-pushed the aug23-triage-sta4495-5122-5150 branch 6 times, most recently from 12bf37b to fc2c6cd Compare August 24, 2026 02:38
@Jinwoo-H
Jinwoo-H force-pushed the aug23-triage-sta4495-5122-5150 branch from fc2c6cd to e2f655e Compare August 24, 2026 02:38
@Jinwoo-H
Jinwoo-H marked this pull request as ready for review August 24, 2026 02:57
@coderabbitai

coderabbitai Bot commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The change adds transaction ownership for PTY input across renderer, automation, and agent prompt writes. It adds generation fencing, bracketed-paste handling, bounded query-reply queues, and lifecycle invalidation. Agent prompt delivery now supports readiness policies and operation_unknown outcomes. Mailbox delivery stages messages durably before provider input and records none, staged, delivered, or unknown states. Runtime, IPC, RPC, database, mailbox, and reliability-gate tests cover these flows.

Merge Risk: 🔵 Low · up to e2f65

The PR centralizes PTY input ownership and prompt/mailbox sequencing, but a flush failure can leave the terminal in bracketed-paste mode, and partially implemented controllers can lose their native transaction behavior. These are bounded edge-case correctness risks requiring explicit owner follow-up before or after merge.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the main changes and validation, but it omits most required template sections, including the linked issue, visual proof, testing checklist, and review checklist. Complete the required template sections, especially the issue link, visual proof or N/A rationale, testing details, AI disclosure, review notes, and checklist items.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: consolidating agent prompt and mailbox PTY delivery ownership.
Docstring Coverage ✅ Passed Docstring check was indeterminate for this PR — some files could not be analyzed in time. Not blocking.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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.

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🧹 Nitpick comments (2)
src/main/runtime/orca-runtime.ts (1)

6219-6236: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Handle controllers that implement only one transaction method.

The condition installs the compatibility owner when either beginInputTransaction or invalidateInputTransactions is missing. If a controller supplies beginInputTransaction but not invalidateInputTransactions, this replaces the controller's own beginInputTransaction and its write with the compatibility owner. The controller's native transaction implementation is then unreachable.

Fill in only the missing method, or require both methods together.

♻️ Proposed fix
-    if (
-      controller &&
-      (!controller.beginInputTransaction || !controller.invalidateInputTransactions)
-    ) {
+    if (controller && !controller.beginInputTransaction) {
       const write = controller.write.bind(controller)
src/main/runtime/orca-runtime.test.ts (1)

977-993: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Reuse acknowledgeAgentPromptSubmit inside makePromptAwareWrite.

Lines 988-990 duplicate the '\r' handling already defined by acknowledgeAgentPromptSubmit at Line 175. Call that helper to keep one definition of the submit acknowledgement.

♻️ Proposed refactor
 function makePromptAwareWrite(runtime: OrcaRuntimeService) {
   return vi.fn((ptyId: string, data: string) => {
     if (data.includes('\x1b[201~')) {
       runtime.onPtyData(ptyId, '\x1b[?25h', Date.now())
     }
-    if (data === '\r') {
-      runtime.onPtyData(ptyId, '\x1b]0;Codex working\x07', Date.now())
-    }
+    acknowledgeAgentPromptSubmit(runtime, ptyId, data)
     return true
   })
 }

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 3c45599e-8803-4f0c-9f25-5083852fc7b2

📥 Commits

Reviewing files that changed from the base of the PR and between 55258f3 and e2f655e.

📒 Files selected for processing (34)
  • config/reliability-gates.jsonc
  • src/main/ipc/pty-write-ipc-validation.test.ts
  • src/main/ipc/pty.ts
  • src/main/pty-input-transaction-lifecycle.ts
  • src/main/pty-input-transaction-state.ts
  • src/main/pty-input-transaction.test.ts
  • src/main/pty-input-transaction.ts
  • src/main/runtime/agent-prompt-delivery-outcome.test.ts
  • src/main/runtime/agent-prompt-delivery-outcome.ts
  • src/main/runtime/agent-prompt-delivery-state-machine.test.ts
  • src/main/runtime/agent-prompt-submission-runtime.test.ts
  • src/main/runtime/agent-prompt-submission-verification.ts
  • src/main/runtime/orca-runtime.test.ts
  • src/main/runtime/orca-runtime.ts
  • src/main/runtime/orchestration-mailbox-notification-consistency.test.ts
  • src/main/runtime/orchestration-mailbox-notification-test-harness.ts
  • src/main/runtime/orchestration-mailbox-transport-settlement.test.ts
  • src/main/runtime/orchestration/db/contract-constants.ts
  • src/main/runtime/orchestration/db/messages/message-inbox.ts
  • src/main/runtime/orchestration/db/schema/create-core-tables-sql.ts
  • src/main/runtime/orchestration/db/schema/migrate.ts
  • src/main/runtime/orchestration/mailbox-pointer-delivery-contract.ts
  • src/main/runtime/orchestration/mailbox-pointer-delivery-validation.ts
  • src/main/runtime/orchestration/mailbox-pointer-delivery.ts
  • src/main/runtime/orchestration/mailbox-pointer-redrive.ts
  • src/main/runtime/orchestration/mailbox-pointer-state.test.ts
  • src/main/runtime/orchestration/mailbox-pointer-state.ts
  • src/main/runtime/orchestration/mailbox-pointer-submit.ts
  • src/main/runtime/orchestration/types.ts
  • src/main/runtime/rpc/errors.test.ts
  • src/main/runtime/rpc/errors.ts
  • src/main/runtime/rpc/methods/orchestration-composed-workers.test.ts
  • src/main/runtime/rpc/methods/orchestration-federation-start-receipt.test.ts
  • src/main/runtime/terminal-send-stale-leaf-liveness.test.ts
💤 Files with no reviewable changes (1)
  • src/main/runtime/orchestration/mailbox-pointer-submit.ts

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

Comment on lines +279 to +295
private interruptOwner(ptyId: string, owner: InputOwner): boolean {
if (
(owner.pasteOpen || owner.pasteMutationPending) &&
!this.writeInput(ptyId, AGENT_PROMPT_BRACKETED_PASTE_END)
) {
return false
}
owner.pasteOpen = false
owner.pasteMutationPending = false
if (!flushQueryReplies(owner, (reply) => this.writeInput(ptyId, reply))) {
return false
}
invalidateOwner(this.ownerByPtyId, ptyId, owner, 'terminal_input_superseded', (token, reason) =>
invalidateTransactionToken(token, reason)
)
return true
}

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.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Clear paste state only after the paste-end write and the flush both succeed.

interruptOwner sets owner.pasteOpen = false and owner.pasteMutationPending = false at lines 286-287, then returns false when flushQueryReplies fails at line 288. The caller then reports a failed write, but the owner remains registered with paste state already cleared. A later interruptOwner call for the same owner skips the bracketed-paste-end write, so the terminal can stay inside an open paste frame.

Restore the previous paste state when the flush fails.

🐛 Proposed fix
     owner.pasteOpen = false
     owner.pasteMutationPending = false
-    if (!flushQueryReplies(owner, (reply) => this.writeInput(ptyId, reply))) {
-      return false
-    }
+    if (!flushQueryReplies(owner, (reply) => this.writeInput(ptyId, reply))) {
+      owner.pasteOpen = pasteWasOpen
+      owner.pasteMutationPending = pasteMutationWasPending
+      return false
+    }

Capture pasteWasOpen and pasteMutationWasPending before the paste-end write.

This branch has not been deployed

No deployments
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.

1 participant