{"record":{"id":"2c88026bcfa76912","repo":"BigPizzaV3/CodexPlusPlus","slug":"app-server-thread-id","errorCode":null,"errorMessage":"新建会话失败：app-server 未返回 thread id","messagePattern":"新建会话失败：app-server 未返回 thread id","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"apps/codex-plus-mobile-relay/src/main.rs","lineNumber":1257,"sourceCode":"  return await rpc(\"turn/start\", { threadId, clientUserMessageId: `codex-plus-mobile-${Date.now()}`, input: [{ type: \"text\", text }] });\n}\n$(\"connect\").onclick = connect;\n$(\"filter\").oninput = (event) => { state.filter = event.target.value; renderSessions(); };\n$(\"back\").onclick = () => { detailPane.classList.add(\"hidden\"); sessionsPane.classList.remove(\"hidden\"); };\n$(\"composer\").onsubmit = async (event) => {\n  event.preventDefault();\n  const input = $(\"messageInput\");\n  const text = input.value.trim();\n  if (!text) return;\n  input.value = \"\";\n  let threadId = state.selectedId;\n  let isNew = false;\n  try {\n    if (!threadId) {\n      const result = await rpc(\"thread/start\", state.selectedCwd ? { cwd: state.selectedCwd } : {});\n      const thread = result?.thread || result?.data || result;\n      threadId = thread?.id || result?.threadId || result?.id;\n      if (!threadId) throw new Error(\"新建会话失败：app-server 未返回 thread id\");\n      state.selectedId = threadId;\n      isNew = true;\n    }\n    rememberPendingMessage(threadId, text);\n    appendMessageNode(\"用户\", text, true);\n    setStatus(\"正在思考...\");\n    pollThread(threadId);\n    sendMessage(threadId, text, isNew)\n      .then(() => setStatus(\"已发送，正在同步回复...\"))\n      .catch((error) => {\n        forgetPendingMessage(threadId, text);\n        setStatus(error.message, true);\n      });\n  } catch (error) {\n    forgetPendingMessage(threadId, text);\n    setStatus(error.message, true);\n  }\n};","sourceCodeStart":1239,"sourceCodeEnd":1275,"githubUrl":"https://github.com/BigPizzaV3/CodexPlusPlus/blob/b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6/apps/codex-plus-mobile-relay/src/main.rs#L1239-L1275","documentation":"After sending thread/start, the page defensively unwraps the JSON-RPC result through several shapes (result.thread.id, result.threadId, result.id). If none of them yields a thread id, the new session cannot be tracked, so sendMessage throws this error instead of continuing with an undefined threadId.","triggerScenarios":"rpc(\"thread/start\", ...) resolves but the response lacks id in every expected location: app-server returned an error-shaped result, an older/newer app-server version changed the reply schema, or the reply was an empty object due to a forwarding bug.","commonSituations":"Codex app-server updated with a changed thread/start response schema; relay forwarded a JSON-RPC error object as if it were a result; mismatched relay/app-server versions; cwd rejected silently server-side.","solutions":["Log the full thread/start result and update the unwrap chain to match the current app-server schema.","Update the relay page and app-server to matching versions.","Check whether thread/start actually returned a JSON-RPC error and surface it instead of the generic message.","Retry thread/start once; if it still returns no id, show the raw response to the user for diagnosis."],"exampleFix":"// before\nthreadId = thread?.id || result?.threadId || result?.id;\n// after\nthreadId = thread?.id || result?.threadId || result?.id;\nif (!threadId && result?.error) throw new Error(`新建会话失败：${result.error.message ?? JSON.stringify(result.error)}`);","handlingStrategy":"try-catch","validationCode":"const result = await rpc(\"thread/start\", opts); const threadId = result?.thread?.id || result?.threadId || result?.id; if (!threadId) throw new Error(`thread/start 响应异常：${JSON.stringify(result).slice(0, 200)}`);","typeGuard":"function extractThreadId(result) { const t = result?.thread ?? result?.data ?? result; return (typeof t?.id === \"string\" && t.id) || (typeof result?.threadId === \"string\" && result.threadId) || null; }","tryCatchPattern":"try { const id = extractThreadId(await rpc(\"thread/start\", opts)); if (!id) throw new Error(\"no thread id\"); } catch (e) { setStatus(`新建会话失败：${e.message}`, true); }","preventionTips":["Log the raw thread/start response once when upgrading app-server versions.","Surface result.error from JSON-RPC replies instead of a generic message.","Keep relay page and app-server versions matched."],"tags":["jsonrpc","app-server","schema","response"],"backgroundTag":"unexpected-api-response-shape","analyzedSha":"b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6","analyzedAt":"2026-09-19T23:35:21.129Z","contentChangedAt":"2026-09-19T23:35:21.129Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}