Repository navigation
fix(agent-hooks): restore Cursor launch tokens and new-turn restart (STA-3487) - #15695
brennanb2025 wants to merge 3 commits into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (4)
Included review availability: Your plan provides up to 10 included reviews per hour; 6 remain after this review. 📝 WalkthroughWalkthroughThe change adds launch authority handling for queued agent commands. It generates or preserves launch tokens, records launch metadata, and injects Merge Risk: 🔵 Low · up to Queued agent startup may fail in renderer environments that do not provide crypto.randomUUID, preventing the agent from launching. The PR is otherwise mergeable, but this bounded runtime-compatibility risk needs explicit owner awareness or follow-up. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 5f2afc67-24a8-4cec-9532-b27135a9e55d
📒 Files selected for processing (7)
src/main/agent-hooks/server-cursor-pane-authority.test.tssrc/main/agent-hooks/server.tssrc/renderer/src/lib/resume-sleeping-agent-session.test.tssrc/renderer/src/store/slices/terminal-startup-command-retention.test.tssrc/renderer/src/store/slices/terminals.tssrc/shared/queued-agent-launch-authority.test.tssrc/shared/queued-agent-launch-authority.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 0 remain after this review.
| function mintLaunchToken(): string { | ||
| return globalThis.crypto.randomUUID() |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -eu
printf '%s\n' '--- candidate files ---'
git ls-files | rg '(^|/)(queued-agent-launch-authority|.*browser.*uuid|.*uuid).*\.tsx?$|queued-agent-launch-authority'
printf '%s\n' '--- target outline ---'
if command -v ast-grep >/dev/null 2>&1; then
ast-grep outline src/shared/queued-agent-launch-authority.ts
fi
printf '%s\n' '--- target source ---'
nl -ba src/shared/queued-agent-launch-authority.ts | sed -n '1,180p'
printf '%s\n' '--- createBrowserUuid references ---'
rg -n -C 5 'createBrowserUuid|randomUUID|getRandomValues|pendingStartupByTabId|mintLaunchToken' src test tests 2>/dev/null || trueRepository: stablyai/orca
Length of output: 50370
🏁 Script executed:
#!/bin/bash
set -eu
printf '%s\n' '--- exact target ---'
nl -ba src/shared/queued-agent-launch-authority.ts | sed -n '1,140p'
printf '%s\n' '--- browser uuid files ---'
git ls-files | rg '(^|/)(browser-uuid|.*uuid.*)\.(ts|tsx|js|jsx)$'
printf '%s\n' '--- browser uuid implementation ---'
while IFS= read -r f; do
case "$f" in
*browser-uuid*) nl -ba "$f" | sed -n '1,160p' ;;
esac
done < <(git ls-files | rg '(^|/)(browser-uuid|.*uuid.*)\.(ts|tsx|js|jsx)$')
printf '%s\n' '--- queued launch references ---'
rg -n -C 4 --glob '*.ts' --glob '*.tsx' \
'queued-agent-launch-authority|pendingStartupByTabId|mintLaunchToken|normalize.*Startup|launchToken' \
src/shared src/renderer src/main | head -n 1200Repository: stablyai/orca
Length of output: 429
🏁 Script executed:
#!/bin/bash
set -eu
printf '%s\n' '--- exact target ---'
awk '{printf "%6d %s\n", NR, $0}' src/shared/queued-agent-launch-authority.ts | sed -n '1,140p'
printf '%s\n' '--- browser uuid implementation ---'
awk '{printf "%6d %s\n", NR, $0}' src/renderer/src/lib/browser-uuid.ts | sed -n '1,160p'
printf '%s\n' '--- browser uuid tests ---'
awk '{printf "%6d %s\n", NR, $0}' src/renderer/src/lib/browser-uuid.test.ts | sed -n '1,220p'
printf '%s\n' '--- queued launch references ---'
rg -n -C 4 --glob '*.ts' --glob '*.tsx' \
'queued-agent-launch-authority|pendingStartupByTabId|mintLaunchToken|normalize.*Startup|launchToken' \
src/shared src/renderer src/main | sed -n '1,1200p'Repository: stablyai/orca
Length of output: 50370
🏁 Script executed:
#!/bin/bash
set -eu
printf '%s\n' '--- helper imports and calls ---'
rg -n -C 8 --glob '*.ts' --glob '*.tsx' \
'attachQueuedAgentLaunchAuthority|queued-agent-launch-authority' \
src
printf '%s\n' '--- pending startup definitions and writes ---'
rg -n -C 6 --glob '*.ts' --glob '*.tsx' \
'pendingStartupByTabId|setPendingStartup|pendingStartup' \
src/renderer/src/store src/renderer/src/runtime src/renderer/src/hooks src/shared \
| rg -v 'test|snapshot|fixture' | sed -n '1,1600p'
printf '%s\n' '--- browser/build context for the shared module ---'
rg -n -C 5 --glob 'package.json' --glob '*.config.*' --glob '*.ts' --glob '*.tsx' \
'src/shared|renderer|web|browser|queued-agent-launch-authority' \
package.json src/renderer vite.config.* electron.vite.config.* tsconfig*.json 2>/dev/null \
| sed -n '1,1200p'Repository: stablyai/orca
Length of output: 50370
🌐 Web query:
MDN Crypto.randomUUID secure context getRandomValues available insecure contexts
💡 Result:
The Crypto.randomUUID method requires a secure context (HTTPS) to function [1][2]. In contrast, the getRandomValues method is the only member of the Crypto interface that remains available and usable in insecure contexts [3][4][5]. Key points regarding these APIs: 1. Security Requirement: While the crypto property itself is available on the window or worker object in insecure contexts [6][4], most of its methods—including randomUUID—are restricted to secure contexts [1][6][2]. 2. Localhost Exception: Browsers treat localhost as a secure origin, which allows crypto.randomUUID to function even when using HTTP on localhost [7]. However, for other insecure origins, this method will be undefined or unavailable [7]. 3. Recommended Usage: Developers are generally advised to use the Web Crypto API only in secure contexts to ensure appropriate security posture [6][4]. If a cryptographically secure random value is needed in an insecure context, getRandomValues is the supported option [3][5], though it should not be used for key generation, which also requires a secure context [3][2][5].
Citations:
- 1: https://developer.mozilla.org/en-US/docs/Web/API/Crypto/randomUUID
- 2: https://w3c.github.io/webcrypto/
- 3: https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues
- 4: https://developer.mozilla.org/en-US/docs/Web/API/WorkerGlobalScope/crypto
- 5: https://github.com/mdn/content/blob/main/files/en-us/web/api/crypto/getrandomvalues/index.md
- 6: https://developer.mozilla.org/en-US/docs/Web/API/Window/crypto
- 7: https://stackoverflow.com/questions/77980939/typeerror-crypto-randomuuid-is-not-a-function
🏁 Script executed:
#!/bin/bash
set -eu
node - <<'JS'
function mintLaunchTokenDirect(cryptoApi) {
return cryptoApi.randomUUID()
}
function mintLaunchTokenWithGetRandomValues(cryptoApi) {
if (typeof cryptoApi?.randomUUID === 'function') {
return cryptoApi.randomUUID()
}
if (typeof cryptoApi?.getRandomValues !== 'function') {
throw new Error('cryptographically secure UUID source unavailable')
}
const bytes = new Uint8Array(16)
cryptoApi.getRandomValues(bytes)
bytes[6] = (bytes[6] & 0x0f) | 0x40
bytes[8] = (bytes[8] & 0x3f) | 0x80
return Array.from(bytes, (byte) => byte.toString(16).padStart(2, '0')).join('')
}
const cryptoWithoutRandomUUID = {
getRandomValues(bytes) {
for (let i = 0; i < bytes.length; i += 1) bytes[i] = i
return bytes
}
}
let directThrew = false
try {
mintLaunchTokenDirect(cryptoWithoutRandomUUID)
} catch (error) {
directThrew = error instanceof TypeError
}
const fallbackToken = mintLaunchTokenWithGetRandomValues(cryptoWithoutRandomUUID)
console.log(JSON.stringify({ directThrew, fallbackToken }))
JSRepository: stablyai/orca
Length of output: 223
Use a cryptographically secure UUID fallback for launch tokens.
randomUUID() is unavailable on non-secure web origins, so this call can throw before pendingStartupByTabId is written. Use getRandomValues or an injected token factory. Do not use createBrowserUuid unchanged because its final fallback uses Math.random. Add a regression test with randomUUID unavailable.
…STA-3487) Bare cursor-agent queued startups never minted ORCA_AGENT_LAUNCH_TOKEN, and retired panes only restarted on Claude UserPromptSubmit/SessionStart, so a Cursor beforeSubmitPrompt after authority retire could not settle stop to done.
STA-3487 stamps ORCA_AGENT_LAUNCH_TOKEN onto a recognized TUI-agent startup, so resume's env is no longer only the captured agentEnv. Keeps the captured-vs-changed intent and the exact key set, and pins the token to the queued launchToken.
…lper Stop queueTabStartupCommand from minting a launchConfig-only token that never reached ORCA_AGENT_LAUNCH_TOKEN. Pin resume overwriting a captured token, sibling isolation, and non-bare/unrecognized commands staying tokenless.
efe0454 to
18b4e27
Compare
Review statusRebased onto current What this PR doesBare Review fix pushed
Pinned extra tests:
The resume captured-vs-changed test was not loosened: Intentionally not doneDid not lift the retired-pane gate to the full Checks
Visual proofHook-server ingest has no new chrome. These are uncropped full-window shots of the terminal surface in the review build, plus a queued startup that returned to idle. Remaining gaps (not blockers)
Landable from this review. |
|
Closing: its issue #12686 is closed. |


ELI5
Some Cursor panes kept showing Working after the agent finished. Two things stacked: a Cursor pane started as a plain
cursor-agentcommand never got a launch token, and when launch authority was later retired, Orca only treated Claude'sUserPromptSubmit/SessionStartas a new turn. Cursor'sbeforeSubmitPromptwas ignored, so a completedstopnever landed. This stamps a launch token on bare Cursor launches and lets Cursor's own new-turn events reopen a retired pane. A completed stop still cannot stamp a sibling pane.What Changed
cursor-agent,codex, …) now getlaunchConfig+ORCA_AGENT_LAUNCH_TOKEN. Plain shell commands and non-bare invocations likecodex execstay tokenless.beforeSubmitPrompt/sessionStart(in addition to ClaudeUserPromptSubmit/SessionStart).stopstill settles; a retired Cursor pane restarts onbeforeSubmitPrompt(local HTTP and SSHingestRemote) thenstopreachesdone; a retired sibling cannot stamp another pane; queuedcursor-agentcarries the token.Why
Paired Windows observation: same hook sequence (
beforeSubmitPrompt→stop completed→afterAgentResponse), one panedonewith a persisted authority commitment, the other stuckworkingwithORCA_AGENT_LAUNCH_TOKENabsent and no commitment.Tokenless HTTP ingest already accepted
stop(so loosening the authority check would not have been the right fix). The missing token is minted only whenlaunchConfigexists; default-tab / command-only Cursor starts queue{ command: 'cursor-agent' }and never got one. Independently,retirePaneAuthority(command-finished / restored receipt) deletes the row and fences the pane; Claude can restart on the next prompt, Cursor could not.Related in-flight work: #15658 still owns nested-shell OSC
133;Dfalsely retiring launch authority while an agent is in the foreground. This PR does not duplicate that guard. It restores the lost token on the command-only launch path and makes Cursor's new-turn event reopen a retired pane the same way Claude already does.Linked Issue
Fixes #12686
Fixes STA-3487
Visual Proof
N/A — hook-server ingest and queued-startup env stamping. No new chrome. The user-visible effect is the existing Cursor Working indicator settling to idle after a completed
stop.Testing
TDD:
stopalready passed. Retired-pane Cursor restart failed (expected []vs done). Queuedcursor-agenthad nolaunchToken(expected 'cursor', receivedundefined).server-cursor-pane-authority.test.ts4/4,server-closed-tab-suppression.test.ts20/20,queued-agent-launch-authority.test.ts4/4,terminal-startup-command-retention.test.ts6/6,launch-agent-in-new-tab.test.ts27/27cursor-agenttoken test failed againAlso:
pnpm typecheckpassed.oxlint --deny-warningsandoxfmton changed files only — clean.Windows host unreachable this session — Windows env propagation into Cursor panes is unvalidated.
Review
stopwithout a new-turn event stays suppressed. Plain shell startups remain tokenless so a typed agent cannot inherit a sibling token.ingestRemotenow forwardssourceinto disposition; covered by the remote restart test. Folder workspaces use the samequeueTabStartupCommandpath.Agent skill upstream boundary
docs/reference/agent-skill-sharing-upstream-boundary.mdand copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)Author
Out of scope
133;Dretiring launch authority while the agent is still in the foreground. Complementary, not overlapping the Cursor new-turn / command-only token hole.launchAgentLeafId.