{"record":{"id":"d9c6554a8ac4d3b8","repo":"pbakaus/impeccable","slug":"impeccable-failed-to-fetch-pending-count","errorCode":null,"errorMessage":"[impeccable] failed to fetch pending count:","messagePattern":"\\[impeccable\\] failed to fetch pending count:","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"skill/scripts/live-browser.js","lineNumber":4131,"sourceCode":"    if (previousCount <= 0) playPendingIntroAnimation();\n  }\n\n  function maybeShowFirstSaveToast() {\n    if (!firstSaveOfSession) return;\n    firstSaveOfSession = false;\n    showToast('Saved. Click \"Apply copy edits\" to write changes.', 4500);\n  }\n\n  async function fetchPendingCount() {\n    try {\n      const res = await fetch(\n        'http://localhost:' + PORT + '/manual-edit-stash?token=' + encodeURIComponent(TOKEN) + '&pageUrl=' + encodeURIComponent(location.pathname),\n      );\n      if (!res.ok) return;\n      const data = await res.json();\n      updatePendingCounter(data.count || 0);\n    } catch (err) {\n      console.warn('[impeccable] failed to fetch pending count:', err);\n    }\n  }\n\n  async function onPendingPillClick() {\n    const count = parseInt(pendingPillEl?.dataset.count || '0', 10);\n    if (count <= 0 || pendingApplyInFlight) return;\n    const ok = confirm('Apply ' + count + ' copy edit' + (count === 1 ? '' : 's') + ' to source?');\n    if (!ok) return;\n    let waitForSseCompletion = false;\n    resetManualApplyProgress(count);\n    setPendingApplyLoading(true, count);\n    try {\n      const res = await fetch(\n        'http://localhost:' + PORT + '/manual-edit-commit?token=' + encodeURIComponent(TOKEN) + '&pageUrl=' + encodeURIComponent(location.pathname) + '&async=1',\n        { method: 'POST', keepalive: true },\n      );\n      if (!res.ok) {\n        const errBody = await res.json().catch(() => ({}));","sourceCodeStart":4113,"sourceCodeEnd":4149,"githubUrl":"https://github.com/pbakaus/impeccable/blob/f2c7051853848826aac2f4646581d62a732155ad/skill/scripts/live-browser.js#L4113-L4149","documentation":"The in-page live script failed to fetch the pending manual-edit count from the local live server (/manual-edit-stash). The fetch or JSON parse threw and the failure is only warned; the pending pill counter is simply not updated.","triggerScenarios":"The browser page calls http://localhost:<PORT>/manual-edit-stash?token=...&pageUrl=...; network error, non-OK response falling through, or res.json() throwing leads to the catch at skill/scripts/live-browser.js:4109.","commonSituations":"Live dev server was restarted or stopped while the page stayed open; wrong/changed TOKEN after a server restart; page URL path changed; localhost port conflict.","solutions":["Confirm the live server on the given PORT is running; restart the live session and reload the page.","Check that the token matches the current server session (reload the page to get a fresh TOKEN).","Open the URL manually in devtools network tab to see the actual status/response.","Ignore if transient: the counter refreshes on the next successful poll."],"exampleFix":"// before\nconst res = await fetch(url); const data = await res.json();\n// after (surface status before parsing)\nconst res = await fetch(url);\nif (!res.ok) { console.warn('[impeccable] pending count HTTP', res.status); return; }\nconst data = await res.json();","handlingStrategy":"retry","validationCode":"async function serverUp(port) {\n  try { const r = await fetch('http://localhost:' + port + '/healthz'); return r.ok; } catch { return false; }\n}","typeGuard":null,"tryCatchPattern":"try {\n  const res = await fetch(url);\n  if (!res.ok) throw new Error('HTTP ' + res.status);\n  const data = await res.json();\n  updatePendingCounter(data.count || 0);\n} catch (err) {\n  console.warn('[impeccable] failed to fetch pending count:', err);\n}","preventionTips":["Reload live-mode pages after restarting the dev server so token and port stay valid","Poll with backoff instead of hammering a dead server","Check for port conflicts if the server port is fixed"],"tags":["network","fetch","browser","localhost"],"backgroundTag":"connection-refused","analyzedSha":"f2c7051853848826aac2f4646581d62a732155ad","analyzedAt":"2026-09-08T04:51:14.109Z","contentChangedAt":"2026-09-08T04:51:14.109Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}