fix(desktop): await PTY ready in daemon to fix port detection#782
Conversation
Port detection was not working for terminals when terminal persistence (daemon mode) was enabled. The root cause was that createOrAttach returned the response before the PTY finished spawning, so session.pid was null. The null PID was registered with the port manager, and sessions with null PIDs are skipped during port scanning. The fix awaits the PTY ready state before returning, ensuring the PID is available. This also simplifies the initial commands section since the PTY is guaranteed to be ready.
|
Caution Review failedThe pull request is closed. 📝 WalkthroughWalkthroughAwait PTY readiness with a timeout while holding a spawn permit; log on timeout and proceed (PID may be null). Always release the spawn permit in a finally block. Execute initialCommands after readiness handling only if the session is alive; minor comment updates. Changes
Sequence DiagramsequenceDiagram
participant TerminalHost as TerminalHost
participant SpawnPermit as SpawnPermit
participant PTY as PTY
participant Session as Session
TerminalHost->>SpawnPermit: acquire()
TerminalHost->>PTY: await readiness (with timeout)
alt PTY ready
PTY-->>TerminalHost: ready
else timeout
TerminalHost->>TerminalHost: log timeout warning
TerminalHost-->>TerminalHost: continue (PID may be null)
end
TerminalHost->>Session: isAlive?
alt session alive
TerminalHost->>Session: execute initialCommands (write)
end
TerminalHost->>SpawnPermit: release()
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
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 |
🧹 Preview Cleanup CompleteThe following preview resources have been cleaned up:
Thank you for your contribution! 🎉 |
Summary
createOrAttachreturned before the PTY finished spawning, sosession.pidwasnullChanges
session.waitForReady()before returning fromcreateOrAttachto ensure PID is availableTest plan
npm run devorpython -m http.server 8000)Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.