{"record":{"id":"825233c42d867aa8","repo":"pbakaus/impeccable","slug":"reply-failed-unauthorized","errorCode":null,"errorMessage":"Reply failed: Unauthorized\n","messagePattern":"Reply failed: Unauthorized\n","errorType":"console","errorClass":null,"httpStatus":401,"severity":"error","filePath":"crates/live/src/live_poll.rs","lineNumber":731,"sourceCode":"            Ok(Some(r)) => r,\n            Ok(None) => return 0,\n            Err(msg) => {\n                io.err(&format!(\"{}\\n\", msg));\n                return 1;\n            }\n        };\n        return match post_reply(&base, &token, &reply) {\n            Ok(()) => 0,\n            Err(PollError::ConnRefused) => {\n                io.err(&format!(\n                    \"Live server not running. Start one with: {}\\n\",\n                    script_cmd(&env, &cwd, \"live\")\n                ));\n                1\n            }\n            Err(PollError::Auth) => {\n                // JS: a 401 on the reply POST is a non-ok response -> \"Reply failed: <body.error>\"\n                io.err(\"Reply failed: Unauthorized\\n\");\n                1\n            }\n            Err(PollError::AckTimeout(m)) | Err(PollError::Other(m)) => {\n                io.err(&format!(\"Reply failed: {}\\n\", m));\n                1\n            }\n        };\n    }\n\n    let stream_mode = argv.iter().any(|a| a == \"--stream\");\n    let types_arg = argv\n        .iter()\n        .find(|a| a.starts_with(\"--types=\"))\n        .map(|a| a[\"--types=\".len()..].to_string());\n    let types = normalize_poll_types(types_arg.as_deref());\n    let ack_timeout_ms = arg_value_int(&argv, \"--ack-timeout=\", 600_000);\n\n    if stream_mode {","sourceCodeStart":713,"sourceCodeEnd":749,"githubUrl":"https://github.com/pbakaus/impeccable/blob/2bc2879276c1f321a53c4ca99d3371e411329b52/crates/live/src/live_poll.rs#L713-L749","documentation":"A 401 response on the reply POST is mapped to this hardcoded message. The live server rejected the authentication token that live-poll sent, so the reply was not accepted. Matching the JS implementation, the command prints `Reply failed: Unauthorized` and exits 1.","triggerScenarios":"`impeccable live-poll --reply` where `post_reply` returns `PollError::Auth` — the token read from the server info file does not match what the live server expects (401 from the endpoint).","commonSituations":"The live server was restarted and generated a new token while an old info file was reused; two live sessions in the same workspace and polling the wrong one; manually editing or copying session files between directories.","solutions":["Stop and restart the live server so the info file's token matches the running process, then retry the reply.","Delete the stale server info file and start a fresh `live` session.","Ensure only one live server session exists for the workspace so poll reads the correct token."],"exampleFix":"// before\n$ impeccable live-poll --reply --reply-text hi\nReply failed: Unauthorized\n// after\n$ <self_cmd> live-server stop\n$ ./scripts/impeccable live &\n$ impeccable live-poll --reply --reply-text hi","handlingStrategy":"fallback","validationCode":"// shell: if the info file predates the running server process, restart to refresh the token\npid=$(jq -r .pid .impeccable/live-server.json 2>/dev/null)\nkill -0 \"$pid\" 2>/dev/null || { <self_cmd> live-server stop; ./scripts/impeccable live; }","typeGuard":null,"tryCatchPattern":"// on Unauthorized, restart the server and re-read the token before retrying\ntry {\n  postReply(text);\n} catch (e) {\n  if (/Unauthorized/.test(String(e.stderr))) {\n    execSync('<self_cmd> live-server stop && ./scripts/impeccable live');\n    postReply(text); // retry with fresh token from the new info file\n  } else throw e;\n}","preventionTips":["Never copy or hand-edit the server info file; always derive the token from a live session.","Ensure only one live server runs per workspace.","Restart the server whenever its process is recycled so tokens stay in sync."],"tags":["auth","http","live-server"],"backgroundTag":"authentication-required","analyzedSha":"2bc2879276c1f321a53c4ca99d3371e411329b52","analyzedAt":"2026-09-08T04:51:14.109Z","contentChangedAt":"2026-09-08T04:51:14.109Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}