Skip to content

fix(agent-hooks): route reminted pane keys to canonical identity (STA-3993) - #15714

Merged
brennanb2025 merged 6 commits into
mainfrom
brennanb2025/sta-3993-reminted-pane-key
Aug 31, 2026
Merged

brennanb2025 merged 6 commits into
mainfrom
brennanb2025/sta-3993-reminted-pane-key

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 7 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​598 $\color{#cf222e}{\Huge{\mathbf{−}}}$​139 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​459
Prod 6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​74 $\color{#cf222e}{\Huge{\mathbf{−}}}$​14 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​60

ELI5

Some OMP panes never reported done because their ORCA_PANE_KEY was a reminted $$<hash>:L$$ token instead of tabId:leafUuid. The hook pipeline dropped those posts, so the sidebar stayed on Working. Spawn now rewrites that exact remint form to the pane's proven tabId:leafUuid key, and the hook server aliases the remint token to that same pane — not to a neighbor.

What Changed

  • Spawn stamps ORCA_PANE_KEY from proven tab+leaf metadata when the env value is a reminted $$<base32>:L$$ token (or otherwise not the canonical key). The launch token is no longer stripped on that path.
  • The hook server can register an exact alias from that remint token to the canonical pane key, the same way it already remaps legacy tab:0 keys.
  • Remint aliases are first-pane-wins: a later spawn that reuses the same $$ token with a different tab/leaf cannot rebind leftover posts onto the new pane. Same-pane pty-id updates still work.
  • Unmatched remint tokens still cannot write another pane's status.
  • Persist restore keeps remint aliases so a restart does not drop the mapping.

Why

normalizeHookPayload only accepts parsePaneKey() (<tabId>:<leafUuid>). registerPaneKeyAlias previously accepted only same-tab numeric keys, so a reminted $$…:L$$ post was unroutable and last-status never gained a row. The sleeping session then stayed at state: working from the live title snapshot.

#15658 covers a different OMP stuck-working path (willContinue / nested OSC 133;D). This PR is only the reminted-key path.

Linked Issue

Fixes #14018
Fixes STA-3993

Visual Proof

Not a layout change. The user-visible effect is the existing sidebar Working indicator settling after a completed OMP turn on a reminted-key pane. Full-window CDP captures from this branch (bd031da06e) are on the PR (idle empty-state and sidebar + Terminal 1). A reminted $$ key was not faked in the live app.

15714-app-idle.png

15714-sidebar-terminal.png

Testing

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

TDD:

Stage Result
Pre-fix OMP $$…:L$$ ingest produced an empty snapshot; spawn env ORCA_PANE_KEY was stripped (undefined)
Post-fix remint ingest, spawn rewrite, persist normalize, renderer settlement, and first-pane-wins rebind tests pass
Neutered (registerPaneKeyAlias legacy-only; metadata pane-key fallback removed) Same ingest and spawn remint tests failed again
Rebind hole Spawn A then spawn B sharing one remint token with different tab/leaf used to stamp pane B; first-pane-wins guard + failing test first, then product fix

Also: pnpm typecheck passed. oxlint --deny-warnings and oxfmt on changed files only — clean.

Windows 11 high spec (low spec unreachable this session): four remint suites 21/21 pass; a live ConPTY child showed canonical tab:leaf ORCA_PANE_KEY. Opaque $$ remint env propagation on ConPTY remains unvalidated — we did not observe a reminted token in a live Windows child.

Review

  • Security: remint aliases are exact ($$<base32>:L$$ → one canonical pane). A foreign remint token still cannot stamp another pane. After first bind, a remint token cannot be rebound onto a different pane. A parseable UUID from another pane is overwritten with this spawn's metadata key, not aliased.
  • Cross-platform: spawn rewrite and alias ingest are host-agnostic. Reported on Windows 11. Unit tests pass on Windows high spec; ConPTY remint-token propagation still unvalidated.
  • Remote SSH: same spawn env rewrite on the execution host. Persist restore keeps remint aliases.
  • Folder workspaces: same pty:spawn metadata path.
  • Mobile: no client change; mobile consumes the remapped last-status row.
  • Backwards compatibility: additive alias form. Numeric aliases unchanged. No wire/RPC/stream opcode changes.
  • Performance: one regex check on spawn env and one map lookup on hook ingest.

Agent skill upstream boundary

  • Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Checklist

  • This PR is small and focused
  • I explained what changed and why (including ELI5)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path-shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

Author

  • X / Twitter: @BrennanKB5

Out of scope

…-3993)

Spawn was stripping $$<base32>:L$$ ORCA_PANE_KEY values (and the launch
token) instead of rewriting them to the metadata-proven tab:leaf key, so
OMP hooks never entered last-status.json and sleeping rows stayed working.

Alias that exact remint form onto the canonical pane so later posts still
route, and keep unmatched tokens from stamping another pane.
@coderabbitai

coderabbitai Bot commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 9ebcfbcd-c31c-46eb-8f13-a74d39be90a4

📥 Commits

Reviewing files that changed from the base of the PR and between a1db3c3 and fd620ee.

📒 Files selected for processing (2)
  • src/main/ipc/pty-daemon-controller-teardown.test.ts
  • src/main/ipc/pty/ipc/spawn-env.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/ipc/pty/ipc/spawn-env.ts

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


📝 Walkthrough

Walkthrough

The change adds bounded validation for opaque reminted pane keys and applies it to persisted alias normalization. PTY spawning now selects metadata-derived stable keys, preserves launch tokens, restricts pane metadata forwarding for SSH environments, and registers reminted aliases. Agent-hook routing rejects conflicting alias rebinding and preserves canonical completion state. Tests cover validation, persistence, PTY spawning, hook routing, and renderer status settlement. One Codex test receives formatting-only changes.

Merge Risk: 🔵 Low · up to fd620

This PR routes reminted pane keys to canonical pane identities and preserves those mappings across restart, improving completion-state updates. Mergeability is otherwise good, but unsupported or rejected aliases can remain silent, malformed spawn input can fail during normalization, and conflicting persisted mappings need explicit owner follow-up.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning The pull request includes an unrelated whitespace-only reformat in src/main/codex/codex-index-heal-binary-contract.test.ts. This change does not support reminted pane-key routing or issue #14018. Remove the unrelated Codex test reformat from this pull request, or move it to a separate pull request. Retain only changes that support reminted pane-key routing and its required regression coverage.
Docstring Coverage ⚠️ Warning Docstring coverage is 23.08% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 13 functions across 14 files. 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 and concisely describes the primary change: routing reminted pane keys to their canonical identity.
Description check ✅ Passed The description includes the required sections, explains the problem and solution, links issue #14018, documents testing, and addresses visual proof and compatibility considerations. The full lint, te…
Linked Issues check ✅ Passed The changes satisfy issue #14018 by routing reminted $$:L$$ keys to canonical pane identities, preserving launch tokens, retaining aliases across persistence, preventing rebinding, and adding …
Full details: Description check

Explanation

The description includes the required sections, explains the problem and solution, links issue #14018, documents testing, and addresses visual proof and compatibility considerations. The full lint, test, and build checklist remains unchecked, but the description is otherwise complete.

Full details: Linked Issues check

Explanation

The changes satisfy issue #14018 by routing reminted $$&lt;base32&gt;:L$$ keys to canonical pane identities, preserving launch tokens, retaining aliases across persistence, preventing rebinding, and adding regression coverage for completion state updates.

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 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.

Remint tokens have no embedded tab identity, so a later spawn that reused
the same $$ token with a different tab/leaf was overwriting the alias and
routing leftover hook posts onto the new pane. Refuse destination changes
for that form while still allowing same-pane pty id updates.

@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/renderer/src/store/slices/agent-status-reminted-pane-key.test.ts (1)

60-63: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

State the expected settlement directly.

The compound boolean passes for several different outcomes. If setAgentStatus deletes the sleeping record, sleeping is undefined and the expression is false, so the test passes without proving that the record settled to done.

Assert the intended end state instead.

♻️ Suggested clearer assertion
-    const sleeping = store.getState().sleepingAgentSessionsByPaneKey[PANE]
-    expect(sleeping?.state === 'working' && sleeping.prompt === 'finish the reminted pane').toBe(
-      false
-    )
+    const sleeping = store.getState().sleepingAgentSessionsByPaneKey[PANE]
+    // Why: the live record must settle or be dropped; a retained `working` row is the bug.
+    expect(sleeping?.state).not.toBe('working')
src/main/ipc/pty-restore-record-seeding.test.ts (1)

540-546: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Strengthen the cross-pane isolation assertion.

The shared beforeEach resets registerPaneKeyAliasMock. Because this test spawns only tab-2, the negative tab-1 assertion passes without testing cross-pane rebinding. Assert the exact alias call set, or spawn both panes in one test and assert that the destination remains tab-1.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 9ffbea7b-7178-4ede-9592-0c064b845026

📥 Commits

Reviewing files that changed from the base of the PR and between df7460a and bd031da.

📒 Files selected for processing (9)
  • src/main/agent-hooks/server-reminted-pane-key.test.ts
  • src/main/agent-hooks/server.ts
  • src/main/ipc/pty-restore-record-seeding.test.ts
  • src/main/ipc/pty.ts
  • src/main/persistence/restoring-sessions/pane-alias-normalization.test.ts
  • src/main/persistence/restoring-sessions/pane-alias-normalization.ts
  • src/renderer/src/store/slices/agent-status-reminted-pane-key.test.ts
  • src/shared/pane-key-alias.test.ts
  • src/shared/pane-key-alias.ts

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

Comment thread src/main/ipc/pty.ts Outdated
Comment on lines +7129 to +7138
} else if (remintedSpawnPaneKey && validatedPaneKey) {
// Why: reminted $$ tokens are spawn-physical; alias them to the metadata-proven
// tab:leaf key so later hooks still route after env is rewritten to canonical.
agentHookServer.registerPaneKeyAlias(
remintedSpawnPaneKey,
validatedPaneKey,
result.id,
Date.now(),
{ authorityVerified: 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.

🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Description: Trace migration-unsupported pane state producers and clear sites.
set -euo pipefail

rg -nP -C 6 'clearMigrationUnsupportedPtysForPaneKey|clearMigrationUnsupportedPty\b|markMigrationUnsupported' --type=ts

Repository: stablyai/orca

Length of output: 151


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '%s\n' '--- candidate files ---'
fd -t f 'pty\.ts$|.*agentHook.*' .

printf '%s\n' '--- relevant symbols and call sites ---'
rg -n -C 5 'clearMigration|UnsupportedPty|migration.?unsupported|registerPaneKeyAlias|remintedSpawnPaneKey|validatedPaneKey' . --glob '*.{ts,tsx,js,jsx}'

Repository: stablyai/orca

Length of output: 50370


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '%s\n' '--- pty.ts target ---'
sed -n '7080,7170p' src/main/ipc/pty.ts

printf '%s\n' '--- pty.ts migration-state references ---'
rg -n -C 8 'clearMigration|markMigration|migrationUnsupported|registerPaneKeyAlias' src/main/ipc/pty.ts

printf '%s\n' '--- migration state module ---'
fd -t f 'migration-unsupported-pty-state\.ts$' src

Repository: stablyai/orca

Length of output: 10874


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '%s\n' '--- migration state implementation ---'
wc -l src/main/agent-hooks/migration-unsupported-pty-state.ts
cat -n src/main/agent-hooks/migration-unsupported-pty-state.ts

printf '%s\n' '--- alias implementation and callers ---'
rg -n -C 12 'registerPaneKeyAlias\s*[=:]|\bregisterPaneKeyAlias\s*\(' src/main --glob '*.{ts,tsx}'

Repository: stablyai/orca

Length of output: 50369


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '%s\n' '--- alias guard and registration ---'
sed -n '1640,1775p' src/main/agent-hooks/server.ts

printf '%s\n' '--- reminted collision tests ---'
sed -n '145,180p' src/main/agent-hooks/server-reminted-pane-key.test.ts

Repository: stablyai/orca

Length of output: 6162


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '%s\n' '--- alias resolution ---'
rg -n -C 10 'resolvePaneKeyAlias\s*\(' src/main/agent-hooks/server.ts | head -80

printf '%s\n' '--- deterministic contract probe ---'
python3 - <<'PY'
from pathlib import Path

pty = Path("src/main/ipc/pty.ts").read_text()
server = Path("src/main/agent-hooks/server.ts").read_text()

reminted = pty[pty.index("} else if (remintedSpawnPaneKey && validatedPaneKey)"):pty.index("} else if (validatedPaneKey)", pty.index("} else if (remintedSpawnPaneKey && validatedPaneKey)"))]
print("reminted_clears_destination:", "clearMigrationUnsupportedPtysForPaneKey(validatedPaneKey)" in reminted)
print("collision_guard_present:", "existing.stablePaneKey !== toPaneKey && isOpaqueRemintedPaneKey(fromPaneKey)" in server)
print("collision_guard_returns:", "if (existing && existing.stablePaneKey !== toPaneKey && isOpaqueRemintedPaneKey(fromPaneKey)) {\n      return" in server)

# Reproduce the alias guard's observable mapping for a reminted collision.
aliases = {"$$same": "tab-a:leaf-a"}
incoming = ("$$same", "tab-b:leaf-b")
if incoming[0] in aliases and aliases[incoming[0]] != incoming[1]:
    accepted = False
    routed_destination = aliases[incoming[0]]
else:
    accepted = True
    aliases[incoming[0]] = incoming[1]
    routed_destination = aliases[incoming[0]]
print("collision_alias_accepted:", accepted)
print("collision_hook_destination:", routed_destination)
PY

Repository: stablyai/orca

Length of output: 3803


Clear migration-unsupported state for reminted spawns. When remintedSpawnPaneKey && validatedPaneKey, call clearMigrationUnsupportedPtysForPaneKey(validatedPaneKey) after registering the alias. Otherwise, stale entries from earlier legacy PTYs remain visible for the pane. The alias collision path intentionally keeps the existing mapping; it does not leave hooks unroutable.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Electron visual proof (worktree review-15714-head @ bd031da06e)

Full uncropped windows from the CDP-launched instance of this branch. Identity: Orca: brennanb2025/review-15714-head. No remint was faked.

Idle (fresh isolated profile):

15714-app-idle.png

Sidebar + Terminal 1 + Agents session history:

15714-sidebar-terminal.png

Report: .review/electron-proof.md

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Review status (bd031da06e)

Senior review loop on the PR head, rebased onto current origin/main (no-op). Start-of-session and end-of-session readiness: PASS WITH RISK. No proven P0/P1/P2. Counsel skipped (zero candidates).

What landed in this loop

The original remint rewrite + alias was sound, but registerPaneKeyAlias overwrote destinations. Spawn A then spawn B sharing one $$…:L$$ token with different tab/leaf rebound leftover hook posts onto pane B. Failing test first, then a first-pane-wins guard: remint destination changes are refused; same-pane pty-id updates still work. Numeric same-tab rebinds and persist overwriteExisting: false are unchanged.

HEAD: 651ba08bae + bd031da06e (fix(agent-hooks): keep reminted pane-key aliases first-pane-wins).

Security

  • Unmatched remint tokens still cannot stamp another pane (parsePaneKey fails; foreign-token test).
  • Legacy numeric aliases still require legacy.tabId === stable.tabId.
  • Opaque remint source is regex-bounded ($$<base32>:L$$, ≤200 chars).
  • ?? metadataPaneKey names only this spawn’s validated tab+leaf — no extra pane authority.
  • After first bind, a remint token cannot be rebound onto a different pane (server.ts first-pane-wins).

Sibling PRs on src/main/agent-hooks/server.ts

Land #15714 first (identity router). #15674 (interrupt inference) and #15695 (Cursor new-turn events) do not share registerPaneKeyAlias control flow; textual import/hunk conflict is mechanical.

Verification

  • Targeted vitest + typecheck + oxlint + oxfmt: clean on macOS (48 tests in the review loop).
  • Windows 11 high spec: same remint suites 21/21 pass. Live ConPTY $env:ORCA_PANE_KEY was a canonical tab:leaf UUID. Opaque $$ remint env propagation on ConPTY remains UNVALIDATED (no reminted token observed in a live Windows child). Windows low spec was unreachable (remote_runtime_unavailable).
  • Electron CDP from this worktree: identity Orca: brennanb2025/review-15714-head at bd031da06e. Full-window idle + sidebar/terminal screenshots attached. Remint Working→done was not exercised in the live UI (no remint faked).
  • Known-red on main, not this PR: e2e / ssh docker watcher isolation, e2e 1/4/7-of-10, orca-runtime fences flake, 3 WSL HISTFILE tests on macOS.

Verdict

Ready to land as the reminted-key identity fix, with the Windows ConPTY remint-token caveat carried (not dropped).

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Electron CDP validation (bd031da06e, worktree pr-15714-reminted-pane-key)

Launched this child worktree's electron-vite build (CDP 9335 / renderer 5178, isolated profile). Identity: Orca: brennanb2025/pr-15714-reminted-pane-key (Dock tile Orca/ brennanb2025-pr-15714-reminted-pane-key). Playwright CDP only.

Exercised

  • Idle empty-state
  • Activated a local demo git folder and Terminal 1
  • Spawned OMP from the New tab menu
  • Inspected live ORCA_PANE_KEY on the OMP child and the sidebar Idle row

Visible

Idle:

15714-app-idle.png

Terminal 1 (canonical pane key printed):

15714-sidebar-terminal.png

New tab → OMP:

15714-new-tab-omp-menu.png

OMP ready + sidebar Idle OMP:

15714-omp-idle-sidebar.png

Backing

OMP child env ORCA_PANE_KEY was canonical 066249d5-923f-4e5a-8410-c1d172cf2274:7ccf2a46-1372-48a5-84ab-2769c1b2b464 (tabId:leafUuid), with routingTrusted: true. Launch token was kept. No $$…:L$$ remint token appeared on this fresh spawn (not faked).

Gaps

  • Remint rewrite/alias was not live-triggered.
  • Isolated-profile OMP had no models, so Working → done was not driven.
  • Windows ConPTY / SSH remint still unvalidated.

Report: /tmp/orca-15714-electron-proof/electron-proof.md

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Final preparation status

  • Review-until-clean completed with readiness-checklist at start/end, OSS precedent review, and adversarial correctness/performance/regression passes.
  • No code changes were warranted. The focused reminted-pane, hook, PTY restore/persistence, renderer, and server suites passed (40 files / 369 tests), along with typecheck, changed-file lint, and diff checks.
  • Electron CDP validation confirmed the canonical ORCA_PANE_KEY tab:leaf identity and OMP Idle sidebar state; four uncropped screenshots are attached in the preceding visual-proof comment.
  • Remaining gaps: no live remint token or Working→done model turn was available, and Windows/SSH remint behavior remains unvalidated.
  • The branch is unchanged but currently conflicts with main; resolve that before merge.

…-reminted-pane-key

# Conflicts:
#	src/main/ipc/pty.ts
@coderabbitai

coderabbitai Bot commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

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.

@greptile-apps

greptile-apps Bot commented Aug 31, 2026 •

Copy link
Copy Markdown

Greptile Summary

The PR routes opaque reminted pane keys to metadata-proven canonical pane identities across spawn, hook ingestion, and persisted restoration.

  • Rewrites reminted spawn environment keys to canonical tabId:leafUuid identities.
  • Adds exact remint aliases with first-pane-wins behavior during live registration.
  • Extends persisted alias normalization and adds coverage for hook settlement, spawn behavior, restoration, and renderer state.

Confidence Score: 4/5

The PR is not yet safe to merge because restart restoration can still rebind a reused remint token to a later pane.

Live registration preserves the first destination, but persisted duplicate aliases are merged by newest timestamp, so a restart can route leftover hook posts to the wrong pane and leave the original pane stale.

Files Needing Attention: src/main/persistence/restoring-sessions/pane-alias-normalization.ts and pane-alias-normalization.test.ts

Important Files Changed

Filename Overview
src/shared/pane-key-alias.ts Defines the bounded exact remint-token validator and valid alias source-to-destination combinations.
src/main/ipc/pty/ipc/spawn-env.ts Derives canonical pane identity from validated spawn metadata and rewrites forwarded pane environment values.
src/main/ipc/pty/ipc/spawn-commit.ts Registers reminted physical keys as aliases of the canonical pane after a successful PTY spawn.
src/main/agent-hooks/server.ts Extends alias registration to reminted keys while preventing a live alias from changing destinations.
src/main/persistence/restoring-sessions/pane-alias-normalization.ts Extends persisted normalization and registration to accept reminted aliases.
src/main/persistence/restoring-sessions/pane-alias-normalization.test.ts Covers persisted remint normalization and duplicate-row merge behavior.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[PTY spawn with reminted key] --> B[Metadata-proven canonical pane key]
  B --> C[Register exact remint alias]
  C --> D[Provider hook posts reminted key]
  D --> E[Hook server resolves canonical pane]
  E --> F[Renderer receives updated agent status]
  C --> G[Persist alias]
  G --> H[Restore aliases after restart]
Loading

Reviews (4): Last reviewed commit: "fix(ssh): keep pane identity env strippe..." | Re-trigger Greptile

@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: 3


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 2487feae-1a0d-406b-970a-55ba1571dd80

📥 Commits

Reviewing files that changed from the base of the PR and between 3d341c1 and 579c744.

📒 Files selected for processing (12)
  • src/main/agent-hooks/server-reminted-pane-key.test.ts
  • src/main/agent-hooks/server.ts
  • src/main/codex/codex-index-heal-binary-contract.test.ts
  • src/main/ipc/pty-restore-record-seeding.test.ts
  • src/main/ipc/pty/ipc/spawn-commit.ts
  • src/main/ipc/pty/ipc/spawn-env.ts
  • src/main/ipc/pty/ipc/spawn-state.ts
  • src/main/persistence/restoring-sessions/pane-alias-normalization.test.ts
  • src/main/persistence/restoring-sessions/pane-alias-normalization.ts
  • src/renderer/src/store/slices/agent-status-reminted-pane-key.test.ts
  • src/shared/pane-key-alias.test.ts
  • src/shared/pane-key-alias.ts
🚧 Files skipped from review as they are similar to previous changes (8)
  • src/shared/pane-key-alias.test.ts
  • src/main/ipc/pty-restore-record-seeding.test.ts
  • src/main/persistence/restoring-sessions/pane-alias-normalization.test.ts
  • src/main/persistence/restoring-sessions/pane-alias-normalization.ts
  • src/renderer/src/store/slices/agent-status-reminted-pane-key.test.ts
  • src/shared/pane-key-alias.ts
  • src/main/agent-hooks/server.ts
  • src/main/agent-hooks/server-reminted-pane-key.test.ts

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

Comment on lines +150 to +158
} else if (ctx.opaqueRemintedSpawnPaneKey && ctx.validatedPaneKey) {
// Reminted $$ tokens are spawn-physical; alias them to the metadata-proven tab:leaf key.
agentHookServer.registerPaneKeyAlias(
ctx.opaqueRemintedSpawnPaneKey,
ctx.validatedPaneKey,
ctx.result.id,
Date.now(),
{ authorityVerified: 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.

🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift

🔎 Supported by static analysis

🏁 Script executed:

printf '%s\n' '--- repository knowledge scopes ---'
find /tmp/coderabbit-repo-knowledge/stablyai/orca-89dc44e4 \
  -maxdepth 2 -type f \( -path '*/repository_conventions/*' -o -path '*/architecture/*' -o -path '*/learnings/*' \) -print 2>/dev/null | sort

printf '%s\n' '--- target file outline ---'
ast-grep outline src/main/ipc/pty/ipc/spawn-commit.ts

printf '%s\n' '--- target file ---'
sed -n '1,230p' src/main/ipc/pty/ipc/spawn-commit.ts

printf '%s\n' '--- directly bound symbols and callers ---'
rg -n -A8 -B8 \
  'commitPtyIpcSpawn|registerPaneKeyAlias|opaqueRemintedSpawnPaneKey|before_agent_start|agent_end|spawn-commit' \
  src/main/ipc/pty src/main | head -400

Repository: stablyai/orca

Length of output: 46473


🏁 Script executed:

printf '%s\n' '--- repository knowledge files ---'
find /tmp/coderabbit-repo-knowledge -maxdepth 4 -type f -print 2>/dev/null | sort | head -100

printf '%s\n' '--- spawn execution path ---'
sed -n '1,240p' src/main/ipc/pty/ipc/spawn-execute.ts
sed -n '1,120p' src/main/ipc/pty/ipc/spawn-run.ts

printf '%s\n' '--- hook server implementation ---'
fd -i 'server' src/main/agent-hooks src/main | head -30
rg -n -A18 -B12 \
  'registerPaneKeyAlias|resolve.*PaneKey|before_agent_start|agent_end|post.*hook|hook.*event' \
  src/main/agent-hooks src/main/pi | head -500

printf '%s\n' '--- spawn preparation and pane-key derivation ---'
sed -n '1,130p' src/main/ipc/pty/ipc/spawn-env.ts
sed -n '1,180p' src/main/ipc/pty/ipc/spawn-state.ts

Repository: stablyai/orca

Length of output: 50369


🏁 Script executed:

printf '%s\n' '--- AgentHookServer binding ---'
rg -l 'class AgentHookServer|export const agentHookServer|registerPaneKeyAlias' src/main/agent-hooks
rg -n -A35 -B15 'registerPaneKeyAlias|resolvePaneKey|ingestRemote|handle.*Hook|hook_event_name' \
  src/main/agent-hooks/server.ts src/main/agent-hooks/*.ts 2>/dev/null | head -350

printf '%s\n' '--- stable-pane provider spawn binding ---'
rg -n -A45 -B20 'function spawnForStablePane|spawnForStablePane|provider\.spawn|spawn\(' \
  src/main/ipc/pty/pane src/main/providers src/main/ipc/pty | head -350

printf '%s\n' '--- hook environment and reminted-key consumers ---'
rg -n -A25 -B15 'opaqueRemintedSpawnPaneKey|ORCA_AGENT_HOOK|spawnPaneKey|paneKey' \
  src/main/ipc/pty/ipc/spawn-env.ts src/main/agent-hooks src/main/providers | head -400

printf '%s\n' '--- applicable conventions and learning ---'
cat /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4/conventions/src-main-pty.md \
    /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4/conventions/src-main-ipc.md \
    /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4/learnings/src-main-pty.md \
    /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4/learnings/src-main-ipc.md 2>/dev/null

Repository: stablyai/orca

Length of output: 50370


🏁 Script executed:

printf '%s\n' '--- AgentHookServer declarations ---'
rg -n \
  'class AgentHookServer|registerPaneKeyAlias|alias|ingestRemote|normalizeHookPayload|handleHook|paneKey' \
  src/main/agent-hooks/server.ts | head -180

printf '%s\n' '--- AgentHookServer relevant source ---'
sed -n '1,220p' src/main/agent-hooks/server.ts
sed -n '220,500p' src/main/agent-hooks/server.ts
sed -n '500,820p' src/main/agent-hooks/server.ts

printf '%s\n' '--- spawn hook setup before provider.spawn ---'
rg -n -A20 -B20 \
  'buildPtyEnv|buildPtyOptions|spawnOptions|onPtySpawnCommitted|ensureWslHookRelayForReattach|agentHookServer' \
  src/main/ipc/pty/ipc/spawn-env.ts \
  src/main/ipc/pty/ipc/spawn-options.ts \
  src/main/ipc/pty/ipc/spawn-execute.ts \
  src/main/providers | head -350

Repository: stablyai/orca

Length of output: 50369


🏁 Script executed:

printf '%s\n' '--- alias registration and resolution ---'
sed -n '1740,1845p' src/main/agent-hooks/server.ts
sed -n '2110,2275p' src/main/agent-hooks/server.ts

printf '%s\n' '--- hook HTTP/remote ingress callers ---'
rg -n 'ingestRemote|ingestLocal|applyNormalizedStatus|normalizeLocal|handleRequest|buildPtyEnv' \
  src/main/agent-hooks/server.ts src/main/agent-hooks/*.ts | grep -v '\.test\.ts' | head -120
sed -n '2275,2470p' src/main/agent-hooks/server.ts

printf '%s\n' '--- complete pane-key preparation and hook environment assembly ---'
sed -n '1,115p' src/main/ipc/pty/ipc/spawn-env.ts
rg -n -A30 -B15 'buildPtyEnv|ORCA_AGENT_HOOK_PANE|ORCA_AGENT_HOOK|paneKey' \
  src/main/agent-hooks/server.ts src/main/ipc/pty src/main/providers | grep -v '\.test\.ts' | head -260

Repository: stablyai/orca

Length of output: 47602


🏁 Script executed:

printf '%s\n' '--- alias registration body and status disposition ---'
sed -n '1820,1965p' src/main/agent-hooks/server.ts
sed -n '1160,1260p' src/main/agent-hooks/server.ts
sed -n '1420,1475p' src/main/agent-hooks/server.ts

printf '%s\n' '--- ingress paths before and after alias resolution ---'
sed -n '2285,2325p' src/main/agent-hooks/server.ts
sed -n '2580,2665p' src/main/agent-hooks/server.ts

printf '%s\n' '--- opaque-key and stable-key contracts ---'
cat src/shared/pane-key-alias.ts
rg -n -A25 -B10 'function parsePaneKey|export function parsePaneKey|parseValidPaneKey' \
  src/shared/stable-pane-id.ts src/main/ipc/pty/pane/key-state.ts

printf '%s\n' '--- existing reminted-key regression coverage ---'
sed -n '1,260p' src/main/agent-hooks/server-reminted-pane-key.test.ts

Repository: stablyai/orca

Length of output: 32033


🏁 Script executed:

printf '%s\n' '--- local provider spawn contract ---'
rg -n -A35 -B15 'async spawn|spawn\(options|buildSpawnEnv|onPtySpawnCommitted' \
  src/main/providers/local-pty-provider.ts src/main/providers/types.ts | head -260

printf '%s\n' '--- spawn environment handoff ---'
sed -n '100,230p' src/main/ipc/pty/ipc/spawn-env.ts
sed -n '45,115p' src/main/ipc/pty/ipc/spawn-options.ts

printf '%s\n' '--- canonical hook normalizer pane-key validation ---'
rg -n -A35 -B15 'paneKey.*parsePaneKey|parsePaneKey.*paneKey|normalizeHookPayload' \
  src/shared/agent-hook-listener src/shared/agent-hook-listener.ts | head -260

Repository: stablyai/orca

Length of output: 13726


🏁 Script executed:

printf '%s\n' '--- full environment assembly after pane-key selection ---'
sed -n '1,260p' src/main/ipc/pty/ipc/spawn-env.ts
sed -n '1,220p' src/main/ipc/pty/ipc/spawn-env-codex.ts

printf '%s\n' '--- all production writes and reads of ORCA_PANE_KEY ---'
rg -n -A12 -B12 'ORCA_PANE_KEY' src/main src/shared | grep -v '\.test\.ts' | head -320

printf '%s\n' '--- provider spawn implementations ---'
rg -l 'class .*PtyProvider|spawn\(.*Pty|async spawn' src/main/providers | head -40
rg -n -A30 -B15 'ORCA_PANE_KEY|buildSpawnEnv|async spawn|spawn =|spawn\(' \
  src/main/providers/local-pty-provider.ts \
  src/main/providers/daemon-pty-provider.ts \
  src/main/providers/ssh-pty-provider.ts \
  src/main/providers | grep -v '\.test\.ts' | head -420

Repository: stablyai/orca

Length of output: 50369


🏁 Script executed:

printf '%s\n' '--- final spawn-option and local-spawn environment binding ---'
rg -l 'function spawnLocalPty|spawnLocalPty|buildSpawnEnv' src/main/providers src/main/ipc/pty | head -40
rg -n -A45 -B20 'function spawnLocalPty|spawnLocalPty|buildSpawnEnv' \
  src/main/providers src/main/ipc/pty | grep -v '\.test\.ts' | head -320

printf '%s\n' '--- commit persistence and spawn-commit callbacks ---'
sed -n '1,280p' src/main/ipc/pty/ipc/spawn-commit-persist.ts
rg -n -A20 -B20 'onPtySpawnCommitted|registerPaneKeyAlias|opaqueRemintedSpawnPaneKey' \
  src/main/ipc/pty src/main/providers | grep -v '\.test\.ts' | head -260

Repository: stablyai/orca

Length of output: 50369


🏁 Script executed:

printf '%s\n' '--- exact IPC spawn environment field handoff ---'
rg -n -A8 -B8 'spawnEnv\s*=|ctx\.spawnEnv|env:\s*ctx\.env|env:\s*ctx\.baseEnv' \
  src/main/ipc/pty/ipc src/main/ipc/pty/runtime | head -220

printf '%s\n' '--- local reattach behavior ---'
sed -n '1,115p' src/main/providers/local-pty-spawn.ts
rg -n -A35 -B15 'function reattachLocalPty|export function reattachLocalPty' \
  src/main/providers src/main | head -120

printf '%s\n' '--- remote reattach path around provider spawn ---'
rg -n -A45 -B20 'reattachSshPtySessionForSpawn|attachOnly|spawn.*sessionId' \
  src/main/providers src/main/ssh | grep -v '\.test\.ts' | head -280

Repository: stablyai/orca

Length of output: 40773


Install the reminted pane-key alias before reattach hooks can arrive.

When an existing PTY still uses ctx.opaqueRemintedSpawnPaneKey, provider.spawn can reattach it before commitPtyIpcSpawn registers the alias. parseHookEnvelope then drops early before_agent_start or agent_end events because the opaque key is not a valid canonical pane key. Add a reattach regression and install the alias before the provider reattach path. Fresh spawns already rewrite ORCA_PANE_KEY to ctx.stablePaneKey.

? makePaneKey(args.tabId, ctx.metadataLeafId)
: null
ctx.legacySpawnPaneKey = verifiedPaneKey ? null : parseLegacyNumericPaneKey(spawnPaneKey)
const normalizedSpawnPaneKey = spawnPaneKey?.trim() ?? ''

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.

🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

printf '%s\n' '--- scoped knowledge files ---'
find /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4 -maxdepth 2 -type f -name '*.md' -print
printf '%s\n' '--- knowledge headers ---'
for f in /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4/*/*.md; do
  [ -f "$f" ] && { printf '\n### %s\n' "$f"; head -5 "$f"; }
done
printf '%s\n' '--- target file map ---'
ast-grep outline src/main/ipc/pty/ipc/spawn-env.ts
printf '%s\n' '--- target source ---'
cat -n src/main/ipc/pty/ipc/spawn-env.ts
printf '%s\n' '--- direct references ---'
rg -n -C 3 'spawnPaneKey|ORCA_PANE_KEY|spawn-env' src/main/ipc/pty

Repository: stablyai/orca

Length of output: 29072


🏁 Script executed:

printf '%s\n' '--- state and spawn flow symbols ---'
rg -n -C 6 'interface PtyIpcSpawnState|type PtyIpcSpawnState|args:.*Pty|pty:spawn|assemblePtyIpcSpawnEnv|env:' src/main/ipc/pty/ipc src/main/ipc/pty
printf '%s\n' '--- pane-key parser definitions ---'
rg -n -C 8 'function parseValidPaneKey|const parseValidPaneKey|export .*parseValidPaneKey|function parseLegacyNumericPaneKey|export .*parseLegacyNumericPaneKey' src/shared src/main
printf '%s\n' '--- liveness contract ---'
cat -n src/main/ipc/pty/provider/liveness.ts
printf '%s\n' '--- relevant convention and learning ---'
cat /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4/conventions/src.md
cat /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4/learnings/src-main-ipc.md

Repository: stablyai/orca

Length of output: 50369


🏁 Script executed:

printf '%s\n' '--- PtySpawnIpcArgs definition ---'
sed -n '1,80p' src/main/ipc/pty/ipc/spawn-types.ts
printf '%s\n' '--- IPC registration ---'
cat -n src/main/ipc/pty/ipc/spawn.ts
printf '%s\n' '--- parser definitions ---'
rg -n 'parseValidPaneKey|parseLegacyNumericPaneKey' src/main/ipc/pty/pane src/shared
sed -n '1,180p' src/main/ipc/pty/pane/key-state.ts
printf '%s\n' '--- liveness implementation ---'
sed -n '20,45p' src/main/ipc/pty/provider/liveness.ts

Repository: stablyai/orca

Length of output: 7754


Guard spawnPaneKey before calling .trim().

If ORCA_PANE_KEY contains a non-string value, spawnPaneKey?.trim() can throw TypeError and abort PTY spawning. Use a type check before trimming and add a wrong-shaped input test.

Comment thread src/main/ipc/pty/ipc/spawn-env.ts Resolved
@brennanb2025

brennanb2025 commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor Author

Conflict resolution and review complete.

  • Updated the PR branch with the review fixes (current head fd620ee).
  • Restored the canonical pane-key length guard for destination aliases.
  • Prevented SSH pane identity environment variables from being re-injected when remote hooks are disabled.
  • Focused verification: 6 test files / 33 tests passed, pnpm tc passed, and changed-code quality reported no new findings.
  • No proven in-scope issues remain; the pre-existing generated lockfile change was removed from the worktree.

The PR remains open; hosted checks are still settling.

@brennanb2025
brennanb2025 merged commit f2e9ba4 into main Aug 31, 2026
32 checks passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…-3993) (stablyai#15714)

* fix(agent-hooks): route reminted pane keys to canonical identity (STA-3993)

Spawn was stripping $$<base32>:L$$ ORCA_PANE_KEY values (and the launch
token) instead of rewriting them to the metadata-proven tab:leaf key, so
OMP hooks never entered last-status.json and sleeping rows stayed working.

Alias that exact remint form onto the canonical pane so later posts still
route, and keep unmatched tokens from stamping another pane.

* fix(agent-hooks): keep reminted pane-key aliases first-pane-wins

Remint tokens have no embedded tab identity, so a later spawn that reused
the same $$ token with a different tab/leaf was overwriting the alias and
routing leftover hook posts onto the new pane. Refuse destination changes
for that form while still allowing same-pane pty id updates.

* fix(agent-hooks): keep pane alias limit import valid after refactor

* fix(agent-hooks): bound pane alias destination keys

* fix(ssh): keep pane identity env stripped when hooks disabled

---------

Co-authored-by: Merge Sim <sim@local>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant