{"record":{"id":"1dd7de61523ad6cf","repo":"wavetermdev/waveterm","slug":"creating-new-chat-w","errorCode":null,"errorMessage":"creating new chat: %w","messagePattern":"creating new chat: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/wsh/cmd/wshcmd-ai.go","lineNumber":179,"sourceCode":"\t}\n\n\ttabId := os.Getenv(\"WAVETERM_TABID\")\n\tif tabId == \"\" {\n\t\treturn fmt.Errorf(\"WAVETERM_TABID environment variable not set\")\n\t}\n\n\troute := wshutil.MakeTabRouteId(tabId)\n\n\tif aiNewBlockFlag {\n\t\tnewChatData := wshrpc.CommandWaveAIAddContextData{\n\t\t\tNewChat: true,\n\t\t}\n\t\terr := wshclient.WaveAIAddContextCommand(RpcClient, newChatData, &wshrpc.RpcOpts{\n\t\t\tRoute:   route,\n\t\t\tTimeout: rpcTimeout,\n\t\t})\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"creating new chat: %w\", err)\n\t\t}\n\t}\n\n\tfor _, file := range allFiles {\n\t\tcontextData := wshrpc.CommandWaveAIAddContextData{\n\t\t\tFiles: []wshrpc.AIAttachedFile{file},\n\t\t}\n\t\terr := wshclient.WaveAIAddContextCommand(RpcClient, contextData, &wshrpc.RpcOpts{\n\t\t\tRoute:   route,\n\t\t\tTimeout: rpcTimeout,\n\t\t})\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"adding file %s: %w\", file.Name, err)\n\t\t}\n\t}\n\n\tif aiMessageFlag != \"\" || aiSubmitFlag {\n\t\tfinalContextData := wshrpc.CommandWaveAIAddContextData{","sourceCodeStart":161,"sourceCodeEnd":197,"githubUrl":"https://github.com/wavetermdev/waveterm/blob/a4447c1563b2df285ab89e76c82f91e1a1a49c1e/cmd/wsh/cmd/wshcmd-ai.go#L161-L197","documentation":"When `wsh ai` is invoked with --new (aiNewBlockFlag), it sends a WaveAIAddContextCommand RPC to create a new AI chat block before adding context. If that RPC fails (route unreachable, server error, timeout), aiRun wraps the cause with \"creating new chat: %w\".","triggerScenarios":"Running `wsh ai --new ...` where the WaveAIAddContextCommand RPC fails: the target tab route no longer exists (tab closed), the Wave app is not running/hung, or the RPC exceeded the rpcTimeout.","commonSituations":"The tab identified by WAVETERM_TABID was closed between session start and command execution; Wave terminal was restarted so the route id is stale; network/connection to the wsh server dropped; slow machine caused RPC timeout.","solutions":["Confirm Wave Terminal is running and the tab referenced by WAVETERM_TABID still exists.","Re-run the command from a fresh Wave terminal block to get a current WAVETERM_TABID.","Inspect the wrapped cause (%w) in the message for the root RPC failure (timeout, no connection, etc.) and address it.","Retry the command — transient IPC/busy states usually resolve on a second attempt."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"err := wshclient.WaveAIAddContextCommand(RpcClient, data, opts)\nif err != nil {\n    if errors.Is(err, context.DeadlineExceeded) { /* retry with longer timeout */ }\n    return fmt.Errorf(\"creating new chat: %w\", err)\n}","preventionTips":["Confirm Wave is running and the tab route is current before --new.","Refresh WAVETERM_TABID by running from a live block.","Retry once on transient RPC failures."],"tags":["rpc","wsh","ai"],"backgroundTag":"rpc-call-failed","analyzedSha":"a4447c1563b2df285ab89e76c82f91e1a1a49c1e","analyzedAt":"2026-09-01T15:26:23.972Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}