fix(app): prevent terminal recovery loops (#25710)

This commit is contained in:
Luke Parker 2026-05-04 23:24:57 +10:00 committed by GitHub
commit a366128a93
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 122 additions and 27 deletions

View file

@ -480,15 +480,21 @@ export const Terminal = (props: TerminalProps) => {
})
const connectToken = async () => {
const result = await client.pty.connectToken(
{ ptyID: id },
{
throwOnError: false,
headers: { "x-opencode-ticket": "1" },
},
)
const result = await client.pty
.connectToken(
{ ptyID: id },
{
throwOnError: false,
headers: { "x-opencode-ticket": "1" },
},
)
.catch((err: unknown) => {
if (err instanceof Error && err.message.includes("Request is not supported")) return
throw err
})
if (!result) return
if (result.response.status === 200 && result.data?.ticket) return result.data.ticket
if ((result.response.status === 404 || result.response.status === 405) && password) return
if (result.response.status === 404 || result.response.status === 405) return
if (result.response.status === 403)
throw new Error("PTY connect ticket rejected by origin or CSRF checks. Check the server CORS config.")
throw new Error(`PTY connect ticket failed with ${result.response.status}`)