Skip to content

fix(export): add PDF timeout and hoist currency - #1526

Merged
khaira777 merged 2 commits into
mainfrom
fm/flocafe-export-pdf-timeout-and-currency-hoist
Nov 8, 2026
Merged

khaira777 merged 2 commits into
mainfrom
fm/flocafe-export-pdf-timeout-and-currency-hoist

Conversation

@khaira777

@khaira777 khaira777 commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #1518

Intent

Approve the two surgical export fixes and defer the 366-day increase:

  1. Approve the PDF deadline and failure handling: start with 30 seconds for rendering, excluding time spent in the save dialog. Handle renderer termination and window closure, and always clean up timers, listeners, staging files, and the hidden window. A timeout must destroy the rendering window; merely rejecting Promise.race leaves work running. loadFile() already rejects on load failure, so avoid redundant event handling.
  2. Approve hoisting the currency lookup: in getOrdersWithItemsForBills (main/routes/bills.ts:915), calculate the factor once per invocation outside the bill loop to eliminate repeated per-bill settings reads.

What Changed

  • Enforce a 30-second rendering timeout and abort guards (render-process-gone and closed) in renderHtmlToPdfBuffer, destroying the hidden BrowserWindow on timeout and cleaning up timers, listeners, and staged HTML files in finally.
  • Hoist getCurrencyMinorUnitFactor(getTenantCurrency()) outside the per-bill loop in getOrdersWithItemsForBills so tenant currency settings are read once per batch call instead of once per bill.

Risk Assessment

✅ Low: The changes cleanly add a 30-second rendering deadline (excluding save dialog time) with full window/listener/timer/file cleanup on failure or timeout in renderHtmlToPdfBuffer, and hoist the store currency lookup out of the per-bill loop in getOrdersWithItemsForBills, with thorough behavioral unit test coverage.

Testing

Executed targeted test suites (tests/printer-ipc.test.ts, tests/daily-invoices-export.test.ts, and tests/reports-export.test.ts including its real Electron printToPDF child run) and drove all 6 scenarios live in a real Electron runtime against an isolated SQLite database and real Chromium BrowserWindow instances, capturing the generated compiled invoices HTML/PDF and structured verification results in the evidence directory; all checks passed.

  • Live validation: ✅ go - 6 of 6 scenarios driven live against the product
Scenario Result Live Evidence
Exporting HTML to PDF via save-html-as-pdf IPC uses a 30s default rendering deadline that starts only after the save dialog resolves, producing a valid PDF even when the user pauses in the save dialog… ✅ pass live ~/.no-mistakes/evidence/01M6YFKNJNAQ24EK0STXX2TQM7/live-exported-invoices.pdf and ~/.no-mistakes/evidence/01M6YFKNJNAQ24EK0STXX2TQM7/live-verification-results.j…
When offscreen PDF rendering stalls past the rendering deadline, export fails with a timeout error, immediately destroys the hidden BrowserWindow so work cannot continue in the background, deletes the… ✅ pass live ~/.no-mistakes/evidence/01M6YFKNJNAQ24EK0STXX2TQM7/live-verification-results.json (scenario2_renderTimeout) and npx tsx tests/printer-ipc.test.ts
When the offscreen PDF renderer process terminates unexpectedly (render-process-gone), renderHtmlToPdfBuffer rejects immediately with the termination reason and cleans up the hidden BrowserWindow,… ✅ pass live ~/.no-mistakes/evidence/01M6YFKNJNAQ24EK0STXX2TQM7/live-verification-results.json (scenario3_rendererCrash) and npx tsx tests/printer-ipc.test.ts
When the hidden PDF BrowserWindow closes unexpectedly during rendering (closed event), renderHtmlToPdfBuffer rejects immediately and cleans up the staging HTML file, timers, and listeners ✅ pass live ~/.no-mistakes/evidence/01M6YFKNJNAQ24EK0STXX2TQM7/live-verification-results.json (scenario4_windowClosed) and npx tsx tests/printer-ipc.test.ts
When pdfWindow.loadFile() fails to load the document, the rejection propagates directly without registering a redundant did-fail-load listener, and cleans up the hidden BrowserWindow, staging HTML… ✅ pass live ~/.no-mistakes/evidence/01M6YFKNJNAQ24EK0STXX2TQM7/live-verification-results.json (scenario5_loadFileFailure) and npx tsx tests/printer-ipc.test.ts
Projecting a multi-bill batch through getOrdersWithItemsForBills hoists the tenant currency minor-unit factor lookup outside the per-bill loop so SQLite settings is queried once per call rather th… ✅ pass live ~/.no-mistakes/evidence/01M6YFKNJNAQ24EK0STXX2TQM7/live-verification-results.json (scenario6_currencyHoist) plus npx tsx tests/printer-ipc.test.ts and `npx tsx tests/daily-invoic…
Evidence: Live Electron verification results JSON

{ "scenario6_currencyHoist": { "billCount": 6, "projectedOrdersCount": 6, "settingsQueryCount": 2, "settingsQueries": [ "SELECT value FROM settings WHERE key = ?", "SELECT value FROM settings WHERE key = ?" ] }, "scenario1_saveDialogExcluded": { "defaultTimeoutMs": 30000, "configuredRenderTimeoutMs": 2500, "simulatedSaveDialogDelayMs": 3000, "totalElapsedMs": 3864, "saveResult": { "success": true, "path": "~/.no-mistakes/evidence/01M6YFKNJNAQ24EK0STXX2TQM7/live-exported-invoices.pdf" }, "pdfBytes": 259200, "pdfHeader": "%PDF-1.4", "windowDestroyed": true, "stagingFileDeleted": true }, "scenario2_renderTimeout": { "ipcResult": { "success": false, "error": "PDF rendering timed out after 800ms" }, "windowDestroyed": true, "destroyCalledOnTimeout": true, "stagingFileDeleted": true, "outputPdfCreated": false, "userClosedListenersRemaining": 0 }, "scenario3_rendererCrash": { "error": "PDF renderer process terminated unexpectedly (killed)", "windowDestroyed": true, "stagingFileDeleted": true, "userClosedListenersRemaining": 0 }, "scenario4_windowClosed": { "error": "PDF rendering window closed unexpectedly", "windowDestroyed": true, "stagingFileDeleted": true, "userClosedListenersRemaining": 0 }, "scenario5_loadFileFailure": { "error": "ERR_BLOCKED_BY_CLIENT (-20) loading 'file:///var/folders/y_/1ltcxtwj0zd_w1dg9jv4jl580000gn/T/flo-live-verify-weB7KO/non-existent-file-404.html'", "windowDestroyed": true, "stagingFileDeleted": true, "userClosedListenersRemaining": 0, "didFailLoadListenersRegistered": 0 } }

{
  "scenario6_currencyHoist": {
    "billCount": 6,
    "projectedOrdersCount": 6,
    "settingsQueryCount": 2,
    "settingsQueries": [
      "SELECT value FROM settings WHERE key = ?",
      "SELECT value FROM settings WHERE key = ?"
    ]
  },
  "scenario1_saveDialogExcluded": {
    "defaultTimeoutMs": 30000,
    "configuredRenderTimeoutMs": 2500,
    "simulatedSaveDialogDelayMs": 3000,
    "totalElapsedMs": 3864,
    "saveResult": {
      "success": true,
      "path": "~/.no-mistakes/evidence/01M6YFKNJNAQ24EK0STXX2TQM7/live-exported-invoices.pdf"
    },
    "pdfBytes": 259200,
    "pdfHeader": "%PDF-1.4",
    "windowDestroyed": true,
    "stagingFileDeleted": true
  },
  "scenario2_renderTimeout": {
    "ipcResult": {
      "success": false,
      "error": "PDF rendering timed out after 800ms"
    },
    "windowDestroyed": true,
    "destroyCalledOnTimeout": true,
    "stagingFileDeleted": true,
    "outputPdfCreated": false,
    "userClosedListenersRemaining": 0
  },
  "scenario3_rendererCrash": {
    "error": "PDF renderer process terminated unexpectedly (killed)",
    "windowDestroyed": true,
    "stagingFileDeleted": true,
    "userClosedListenersRemaining": 0
  },
  "scenario4_windowClosed": {
    "error": "PDF rendering window closed unexpectedly",
    "windowDestroyed": true,
    "stagingFileDeleted": true,
    "userClosedListenersRemaining": 0
  },
  "scenario5_loadFileFailure": {
    "error": "ERR_BLOCKED_BY_CLIENT (-20) loading 'file:///var/folders/y_/1ltcxtwj0zd_w1dg9jv4jl580000gn/T/flo-live-verify-weB7KO/non-existent-file-404.html'",
    "windowDestroyed": true,
    "stagingFileDeleted": true,
    "userClosedListenersRemaining": 0,
    "didFailLoadListenersRegistered": 0
  }
}
Evidence: Live compiled daily invoices PDF exported via Electron printToPDF
%PDF-1.4
%

... [250998 bytes truncated] ...

 
0000129439 00000 n 
0000132043 00000 n 
0000135481 00000 n 
0000140873 00000 n 
0000144922 00000 n 
0000153402 00000 n 
0000163030 00000 n 
0000000427 00000 n 
0000018665 00000 n 
0000165965 00000 n 
0000172994 00000 n 
0000180497 00000 n 
0000186368 00000 n 
0000189667 00000 n 
0000195775 00000 n 
0000200443 00000 n 
0000203074 00000 n 
0000211540 00000 n 
0000215049 00000 n 
0000220875 00000 n 
0000223330 00000 n 
0000224810 00000 n 
0000227512 00000 n 
0000229926 00000 n 
0000232015 00000 n 
0000234981 00000 n 
0000236944 00000 n 
0000239264 00000 n 
0000241907 00000 n 
0000245084 00000 n 
0000250254 00000 n 
0000006571 00000 n 
0000019206 00000 n 
0000014262 00000 n 
0000019735 00000 n 
0000017161 00000 n 
0000020096 00000 n 
0000020173 00000 n 
0000020292 00000 n 
0000020504 00000 n 
0000020570 00000 n 
0000020972 00000 n 
0000021127 00000 n 
0000021225 00000 n 
0000021608 00000 n 
0000022454 00000 n 
0000022786 00000 n 
0000024885 00000 n 
0000025097 00000 n 
0000025756 00000 n 
0000026343 00000 n 
0000026998 00000 n 
0000027268 00000 n 
0000029341 00000 n 
0000029553 00000 n 
0000029651 00000 n 
0000030264 00000 n 
0000030598 00000 n 
0000031181 00000 n 
0000031793 00000 n 
0000032111 00000 n 
0000032904 00000 n 
0000033216 00000 n 
0000033601 00000 n 
0000033753 00000 n 
0000034082 00000 n 
0000036095 00000 n 
0000036307 00000 n 
0000037324 00000 n 
0000038568 00000 n 
0000038780 00000 n 
0000038847 00000 n 
0000039486 00000 n 
0000039642 00000 n 
0000039783 00000 n 
0000040102 00000 n 
0000041709 00000 n 
0000041922 00000 n 
0000042021 00000 n 
0000042605 00000 n 
0000042924 00000 n 
0000043077 00000 n 
0000043407 00000 n 
0000045290 00000 n 
0000045503 00000 n 
0000046163 00000 n 
0000046819 00000 n 
0000047147 00000 n 
0000047418 00000 n 
0000049497 00000 n 
0000049710 00000 n 
0000049869 00000 n 
0000050775 00000 n 
0000050981 00000 n 
0000051048 00000 n 
0000051235 00000 n 
0000051393 00000 n 
0000051492 00000 n 
0000051666 00000 n 
0000051992 00000 n 
0000053706 00000 n 
0000053912 00000 n 
0000054045 00000 n 
0000054382 00000 n 
0000054626 00000 n 
0000056536 00000 n 
0000056742 00000 n 
0000056809 00000 n 
0000057376 00000 n 
0000057942 00000 n 
0000058315 00000 n 
0000058414 00000 n 
0000058553 00000 n 
0000059067 00000 n 
0000059413 00000 n 
0000059773 00000 n 
0000060560 00000 n 
0000060912 00000 n 
0000063090 00000 n 
0000063296 00000 n 
0000063395 00000 n 
0000063962 00000 n 
0000064276 00000 n 
0000064755 00000 n 
0000065066 00000 n 
0000065779 00000 n 
0000066077 00000 n 
0000066442 00000 n 
0000066593 00000 n 
0000066772 00000 n 
0000067091 00000 n 
0000067255 00000 n 
0000069387 00000 n 
0000069593 00000 n 
0000070224 00000 n 
0000070767 00000 n 
0000071324 00000 n 
0000071926 00000 n 
0000072241 00000 n 
0000072513 00000 n 
0000072708 00000 n 
0000075012 00000 n 
0000075218 00000 n 
0000075714 00000 n 
0000076090 00000 n 
0000076471 00000 n 
0000076570 00000 n 
0000076907 00000 n 
0000077151 00000 n 
0000079140 00000 n 
0000079353 00000 n 
0000079846 00000 n 
0000080002 00000 n 
0000080541 00000 n 
0000081432 00000 n 
0000082396 00000 n 
0000082497 00000 n 
0000082823 00000 n 
0000084228 00000 n 
0000084434 00000 n 
0000084583 00000 n 
0000084934 00000 n 
0000085113 00000 n 
0000086089 00000 n 
0000086295 00000 n 
0000086640 00000 n 
0000088759 00000 n 
0000088965 00000 n 
0000089114 00000 n 
0000089465 00000 n 
0000089616 00000 n 
0000089820 00000 n 
0000090139 00000 n 
0000091067 00000 n 
0000091273 00000 n 
0000091340 00000 n 
0000091527 00000 n 
0000092094 00000 n 
0000092660 00000 n 
0000093033 00000 n 
0000093191 00000 n 
0000093342 00000 n 
0000093966 00000 n 
0000094065 00000 n 
0000094204 00000 n 
0000094378 00000 n 
0000094892 00000 n 
0000095238 00000 n 
0000095598 00000 n 
0000096385 00000 n 
0000098822 00000 n 
0000102345 00000 n 
0000102592 00000 n 
0000102822 00000 n 
0000103311 00000 n 
0000103517 00000 n 
0000103893 00000 n 
0000104274 00000 n 
0000104406 00000 n 
0000106116 00000 n 
0000106329 00000 n 
0000106478 00000 n 
0000106637 00000 n 
0000106943 00000 n 
0000107773 00000 n 
0000107986 00000 n 
0000108053 00000 n 
0000108246 00000 n 
0000108848 00000 n 
0000109487 00000 n 
0000109890 00000 n 
0000110046 00000 n 
0000110145 00000 n 
0000110286 00000 n 
0000110476 00000 n 
0000110860 00000 n 
0000111707 00000 n 
0000114055 00000 n 
0000114268 00000 n 
0000115159 00000 n 
0000115556 00000 n 
0000115966 00000 n 
0000116102 00000 n 
0000117508 00000 n 
0000117721 00000 n 
0000118381 00000 n 
0000118976 00000 n 
0000119564 00000 n 
0000120165 00000 n 
0000120821 00000 n 
0000121149 00000 n 
0000121420 00000 n 
0000121622 00000 n 
0000123951 00000 n 
0000124164 00000 n 
0000124263 00000 n 
0000124877 00000 n 
0000125212 00000 n 
0000125796 00000 n 
0000126409 00000 n 
0000126728 00000 n 
0000127522 00000 n 
0000127835 00000 n 
0000128221 00000 n 
0000128374 00000 n 
0000128556 00000 n 
0000128741 00000 n 
0000129071 00000 n 
0000131148 00000 n 
0000131376 00000 n 
0000131540 00000 n 
0000131839 00000 n 
0000132409 00000 n 
0000132637 00000 n 
0000133411 00000 n 
0000134103 00000 n 
0000134860 00000 n 
0000135161 00000 n 
0000137243 00000 n 
0000137471 00000 n 
0000138208 00000 n 
0000138878 00000 n 
0000139590 00000 n 
0000139967 00000 n 
0000140340 00000 n 
0000140541 00000 n 
0000142432 00000 n 
0000142660 00000 n 
0000142727 00000 n 
0000143187 00000 n 
0000143390 00000 n 
0000143587 00000 n 
0000144595 00000 n 
0000146812 00000 n 
0000152545 00000 n 
0000152792 00000 n 
0000153022 00000 n 
0000153547 00000 n 
0000162156 00000 n 
0000162406 00000 n 
0000162639 00000 n 
0000163178 00000 n 
0000163384 00000 n 
0000163451 00000 n 
0000163638 00000 n 
0000164204 00000 n 
0000164362 00000 n 
0000164461 00000 n 
0000164635 00000 n 
0000165422 00000 n 
0000165761 00000 n 
0000167887 00000 n 
0000168093 00000 n 
0000168245 00000 n 
0000168741 00000 n 
0000169501 00000 n 
0000169881 00000 n 
0000170476 00000 n 
0000171313 00000 n 
0000171689 00000 n 
0000172070 00000 n 
0000172203 00000 n 
0000172302 00000 n 
0000172639 00000 n 
0000174553 00000 n 
0000179622 00000 n 
0000179869 00000 n 
0000180099 00000 n 
0000180642 00000 n 
0000185517 00000 n 
0000185764 00000 n 
0000185994 00000 n 
0000186513 00000 n 
0000186726 00000 n 
0000187365 00000 n 
0000187932 00000 n 
0000188296 00000 n 
0000189143 00000 n 
0000189463 00000 n 
0000191543 00000 n 
0000191756 00000 n 
0000192370 00000 n 
0000192705 00000 n 
0000193289 00000 n 
0000193608 00000 n 
0000194402 00000 n 
0000194715 00000 n 
0000195101 00000 n 
0000195431 00000 n 
0000197390 00000 n 
0000197603 00000 n 
0000198263 00000 n 
0000198864 00000 n 
0000199520 00000 n 
0000199848 00000 n 
0000200119 00000 n 
0000202223 00000 n 
0000202436 00000 n 
0000202776 00000 n 
0000204450 00000 n 
0000210666 00000 n 
0000210916 00000 n 
0000211149 00000 n 
0000211688 00000 n 
0000211894 00000 n 
0000212525 00000 n 
0000213091 00000 n 
0000213648 00000 n 
0000214250 00000 n 
0000214522 00000 n 
0000214717 00000 n 
0000216999 00000 n 
0000217205 00000 n 
0000217304 00000 n 
0000217618 00000 n 
0000218097 00000 n 
0000218664 00000 n 
0000218975 00000 n 
0000219688 00000 n 
0000219986 00000 n 
0000220351 00000 n 
0000220527 00000 n 
0000222490 00000 n 
0000222696 00000 n 
0000222845 00000 n 
0000223024 00000 n 
0000223974 00000 n 
0000224202 00000 n 
0000224307 00000 n 
0000224606 00000 n 
0000225866 00000 n 
0000226094 00000 n 
0000226831 00000 n 
0000227204 00000 n 
0000228642 00000 n 
0000228870 00000 n 
0000229627 00000 n 
0000231254 00000 n 
0000231460 00000 n 
0000231716 00000 n 
0000233739 00000 n 
0000233952 00000 n 
0000234101 00000 n 
0000234471 00000 n 
0000234777 00000 n 
0000235421 00000 n 
0000235634 00000 n 
0000235733 00000 n 
0000236317 00000 n 
0000236630 00000 n 
0000238092 00000 n 
0000238305 00000 n 
0000238965 00000 n 
0000240063 00000 n 
0000240276 00000 n 
0000240343 00000 n 
0000240746 00000 n 
0000241593 00000 n 
0000243763 00000 n 
0000243976 00000 n 
0000244373 00000 n 
0000244783 00000 n 
0000246093 00000 n 
0000249442 00000 n 
0000249689 00000 n 
0000249919 00000 n 
trailer
<</Size 436
/Root 67 0 R
/Info 1 0 R>>
startxref
250399
%%EOF
Evidence: Live compiled daily invoices HTML input document
<!doctype html>
<html lang="en-US">
<head>
<meta charset="utf-8">
<title>Compiled Daily Invoices — 2026-11-08</title>
<style>
  @page { size: A4 portrait; margin: 10mm; }
  * { box-sizing: border-box; }
  body {
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", "Noto Sans Arabic", "Noto Sans Hebrew", "Noto Sans Devanagari", "Noto Sans Gurmukhi", "Noto Sans Bengali", "Noto Sans Telugu", "Noto Sans Tamil", "Noto Sans Thai", "Noto Sans CJK SC", "PingFang SC", "Microsoft YaHei", "Hiragino Sans", "Malgun Gothic", sans-serif;
    color: #0f172a;
    margin: 0;
    padding: 10px;
    font-size: 9.5px;
    line-height: 1.3;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  .cover-page {
    padding: 2px 0 6px;
  }
  .cover-page.has-invoices {
    page-break-after: always;
    break-after: page;
  }
  .cover-header {
    border-bottom: 2px solid #0f172a;
    padding-bottom: 6px;
    margin-bottom: 8px;
  }
  .cover-header h1 {
    font-size: 15px;
    margin: 0 0 3px;
  }
  .cover-store-details {
    font-size: 10.5px;
    color: #1e293b;
    margin-bottom: 3px;
  }
  .cover-meta {
    font-size: 9.5px;
    color: #475569;
  }
  .kpi-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
    margin: 8px 0 10px;
  }
  .kpi-card {
    border: 1px solid #cbd5e1;
    border-radius: 4px;
    padding: 5px 7px;
    background: #f8fafc;
  }
  .kpi-label {
    font-size: 8.5px;
    text-transform: uppercase;
    color: #475569;
    letter-spacing: 0.03em;
  }
  .kpi-value {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", "Noto Sans Arabic", "Noto Sans Hebrew", "Noto Sans Devanagari", "Noto Sans Gurmukhi", "Noto Sans Bengali", "Noto Sans Telugu", "Noto Sans Tamil", "Noto Sans Thai", "Noto Sans CJK SC", "PingFang SC", "Microsoft YaHei", "Hiragino Sans", "Malgun Gothic", sans-serif;
    font-size: 12px;
    font-weight: 700;
    color: #0f172a;
    margin-top: 2px;
  }
  h2 {
    font-size: 11px;
    margin: 8px 0 4px;
    border-bottom: 1px solid #cbd5e1;
    padding-bottom: 2px;
  }
  table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 6px;
    table-layout: fixed;
  }
  th, td {
    border: 1px solid #cbd5e1;
    padding: 2px 5px;
    text-align: left;
    vertical-align: top;
    overflow-wrap: anywhere;
  }
  th {
    background: #f1f5f9;
    font-weight: 600;
  }
  td.num, th.num {
    text-align: right;
    font-variant-numeric: tabular-nums;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", "Noto Sans Arabic", "Noto Sans Hebrew", "Noto Sans Devanagari", "Noto Sans Gurmukhi", "Noto Sans Bengali", "Noto Sans Telugu", "Noto Sans Tamil", "Noto Sans Thai", "Noto Sans CJK SC", "PingFang SC", "Microsoft YaHei", "Hiragino Sans", "Malgun Gothic", sans-serif;
  }
  td.mono, .mono {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", "Noto Sans Arabic", "Noto Sans Hebrew", "Noto Sans Devanagari", "Noto Sans Gurmukhi", "Noto Sans Bengali", "Noto Sans Telugu", "Noto Sans Tamil", "Noto Sans Thai", "Noto Sans CJK SC", "PingFang SC", "Microsoft YaHei", "Hiragino Sans", "Malgun Gothic", sans-serif;
  }
  td.muted {
    color: #64748b;
    font-style: italic;
  }
  .invoices-flow {
    display: block;
  }
  .appendix-section {
    page-break-before: always;
    break-before: page;
    padding-top: 4px;
  }
  .invoice-card {
    border: 1px solid #94a3b8;
    border-radius: 4px;
    padding: 7px 9px;
    margin-bottom: 8px;
    background: #ffffff;
    page-break-inside: avoid;
    break-inside: avoid;
  }
  .invoice-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    border-bottom: 1px solid #e2e8f0;
    padding-bottom: 4px;
    margin-bottom: 4px;
  }
  .invoice-store-name {
    font-size: 11px;
    font-weight: 700;
  }
  .invoice-store-meta {
    font-size: 9px;
    color: #475569;
  }
  .invoice-title-right {
    text-align: right;
  }
  .invoice-number {
    font-size: 11px;
    font-weight: 700;
    margin-top: 2px;
  }
  .status-badge {
    display: inline-block;
    padding: 1px 5px;
    border-radius: 3px;
    font-size: 9px;
    font-weight: 700;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", "Noto Sans Arabic", "Noto Sans Hebrew", "Noto Sans Devanagari", "Noto Sans Gurmukhi", "Noto Sans Bengali", "Noto Sans Telugu", "Noto Sans Tamil", "Noto Sans Thai", "Noto Sans CJK SC", "PingFang SC", "Microsoft YaHei", "Hiragino Sans", "Malgun Gothic", sans-serif;
  }
  .status-paid {
    background: #dcfce7;
    color: #166534;
    border: 1px solid #86efac;
  }
  .status-partially_refunded {
    background: #fef3c7;
    color: #92400e;
    border: 1px solid #fcd34d;
  }
  .status-refunded {
    background: #fee2e2;
    color: #991b1b;
    border: 1px solid #fca5a5;
  }
  .invoice-meta-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 2px 10px;
    font-size: 9px;
    margin-bottom: 5px;
    color: #334155;
  }
  .invoice-items-table {
    margin-bottom: 5px;
    font-size: 9px;
  }
  .invoice-items-table th, .invoice-items-table td {
    padding: 2px 4px;
  }
  .item-meta {
    font-size: 8px;
    color: #64748b;
  }
  .invoice-footer-grid {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 10px;
    font-size: 9px;
  }
  .invoice-payments {
    flex: 1;
  }
  .payment-pill {
    display: inline-block;
    background: #f1f5f9;
    border: 1px solid #cbd5e1;
    border-radius: 3px;
    padding: 1px 4px;
    margin-right: 4px;
    margin-bottom: 2px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", "Noto Sans Arabic", "Noto Sans Hebrew", "Noto Sans Devanagari", "Noto Sans Gurmukhi", "Noto Sans Bengali", "Noto Sans Telugu", "Noto Sans Tamil", "Noto Sans Thai", "Noto Sans CJK SC", "PingFang SC", "Microsoft YaHei", "Hiragino Sans", "Malgun Gothic", sans-serif;
  }
  .invoice-totals {
    width: 210px;
  }
  .totals-line {
    display: flex;
    justify-content: space-between;
    padding: 1px 0;
  }
  .totals-grand {
    border-top: 1px solid #0f172a;
    margin-top: 2px;
    padding-top: 2px;
    font-weight: 700;
    font-size: 10px;
  }
  .refund-box {
    margin-top: 5px;
    padding: 4px 6px;
    background: #fff1f2;
    border: 1px solid #fecdd3;
    border-radius: 3px;
    font-size: 9px;
    color: #881337;
  }
  .refund-box-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 2px;
  }
  .refund-list {
    margin: 0;
    padding-left: 14px;
  }
  .empty-invoices {
    padding: 12px;
    border: 1px dashed #cbd5e1;
    color: #64748b;
    text-align: center;
  }
</style>
</head>
<body>
  <section class="cover-page has-invoices" data-section="cover-page">
    <header class="cover-header">
      <h1>Daily Invoices &amp; Fiscal Summary Report</h1>
      <div class="cover-store-details">
        <strong>FloCafe Live Verify</strong>
        · <span>EIN: N/A</span>
        
      </div>
      <div class="cover-meta">
        Business Date: <strong>2026-11-08</strong>
        · Timezone: UTC
        · Day Start: 00:00
        · Currency: USD
      </div>
    </header>

    <div class="kpi-grid" data-section="cover-kpis">
      <div class="kpi-card" data-kpi="total_invoices_count" data-value="6">
        <div class="kpi-label">Total Invoices Count</div>
        <div class="kpi-value">6</div>
      </div>
      <div class="kpi-card" data-kpi="total_gross_sales" data-value="2970">
        <div class="kpi-label">Total Gross Sales (USD)</div>
        <div class="kpi-value

... [17521 bytes truncated] ...

l="450" data-item-total="495">
                  <td class="num">1</td>
                  <td>
                    <span class="item-name">Espresso #4</span>
                    
                  </td>
                  <td class="num">$450.00</td>
                  <td class="num" data-col="item-subtotal">$450.00</td>
                  <td class="num" data-col="item-total">$495.00</td>
                </tr>
                </tbody>
              </table>

              <div class="invoice-footer-grid">
                <div class="invoice-payments">
                  <div class="payments-label"><strong>Payments:</strong> <span class="payment-pill">cash: $495.00</span></div>
                </div>
                <div class="invoice-totals">
                  <div class="totals-line"><span>Subtotal</span><span class="mono">$450.00</span></div>
                  
                  
                  <div class="totals-line tax-component-line"><span>Tax</span><span class="mono">$45.00</span></div>
                  
                  
                  <div class="totals-line totals-grand"><span>Total (USD)</span><span class="mono">$495.00</span></div>
                </div>
              </div>

              
            </article>
<article class="invoice-card" data-section="invoice" data-bill-number="INV-0005" data-order-number="ORD-LIVE-5" data-status="paid">
              <header class="invoice-header">
                <div class="invoice-store">
                  <div class="invoice-store-name">FloCafe Live Verify</div>
                  <div class="invoice-store-meta">
                    <span>EIN: N/A</span>
                    
                  </div>
                </div>
                <div class="invoice-title-right">
                  <span class="status-badge status-paid" data-status-badge="[PAID]">[PAID]</span>
                  <div class="invoice-number mono">Invoice #INV-0005</div>
                </div>
              </header>

              <div class="invoice-meta-grid">
                <div><strong>Order:</strong> <span class="mono">ORD-LIVE-5</span> (dine-in)</div>
                <div><strong>Paid:</strong> <span class="mono">2026-11-08 12:00:00</span> (Created: <span class="mono">2026-11-08 12:00:00</span>)</div>
                <div><strong>Staff:</strong> N/A</div>
                <div><strong>Customer:</strong> Walk-in</div>
              </div>

              <table class="invoice-items-table">
                <thead>
                  <tr>
                    <th class="num" style="width: 8%;">Qty</th>
                    <th style="width: 44%;">Item</th>
                    <th class="num" style="width: 16%;">Unit (USD)</th>
                    <th class="num" style="width: 16%;">Subtotal (USD)</th>
                    <th class="num" style="width: 16%;">Total (USD)</th>
                  </tr>
                </thead>
                <tbody>
                  <tr class="invoice-item-row" data-item-subtotal="450" data-item-total="495">
                  <td class="num">1</td>
                  <td>
                    <span class="item-name">Espresso #5</span>
                    
                  </td>
                  <td class="num">$450.00</td>
                  <td class="num" data-col="item-subtotal">$450.00</td>
                  <td class="num" data-col="item-total">$495.00</td>
                </tr>
                </tbody>
              </table>

              <div class="invoice-footer-grid">
                <div class="invoice-payments">
                  <div class="payments-label"><strong>Payments:</strong> <span class="payment-pill">cash: $495.00</span></div>
                </div>
                <div class="invoice-totals">
                  <div class="totals-line"><span>Subtotal</span><span class="mono">$450.00</span></div>
                  
                  
                  <div class="totals-line tax-component-line"><span>Tax</span><span class="mono">$45.00</span></div>
                  
                  
                  <div class="totals-line totals-grand"><span>Total (USD)</span><span class="mono">$495.00</span></div>
                </div>
              </div>

              
            </article>
<article class="invoice-card" data-section="invoice" data-bill-number="INV-0006" data-order-number="ORD-LIVE-6" data-status="paid">
              <header class="invoice-header">
                <div class="invoice-store">
                  <div class="invoice-store-name">FloCafe Live Verify</div>
                  <div class="invoice-store-meta">
                    <span>EIN: N/A</span>
                    
                  </div>
                </div>
                <div class="invoice-title-right">
                  <span class="status-badge status-paid" data-status-badge="[PAID]">[PAID]</span>
                  <div class="invoice-number mono">Invoice #INV-0006</div>
                </div>
              </header>

              <div class="invoice-meta-grid">
                <div><strong>Order:</strong> <span class="mono">ORD-LIVE-6</span> (dine-in)</div>
                <div><strong>Paid:</strong> <span class="mono">2026-11-08 12:00:00</span> (Created: <span class="mono">2026-11-08 12:00:00</span>)</div>
                <div><strong>Staff:</strong> N/A</div>
                <div><strong>Customer:</strong> Walk-in</div>
              </div>

              <table class="invoice-items-table">
                <thead>
                  <tr>
                    <th class="num" style="width: 8%;">Qty</th>
                    <th style="width: 44%;">Item</th>
                    <th class="num" style="width: 16%;">Unit (USD)</th>
                    <th class="num" style="width: 16%;">Subtotal (USD)</th>
                    <th class="num" style="width: 16%;">Total (USD)</th>
                  </tr>
                </thead>
                <tbody>
                  <tr class="invoice-item-row" data-item-subtotal="450" data-item-total="495">
                  <td class="num">1</td>
                  <td>
                    <span class="item-name">Espresso #6</span>
                    
                  </td>
                  <td class="num">$450.00</td>
                  <td class="num" data-col="item-subtotal">$450.00</td>
                  <td class="num" data-col="item-total">$495.00</td>
                </tr>
                </tbody>
              </table>

              <div class="invoice-footer-grid">
                <div class="invoice-payments">
                  <div class="payments-label"><strong>Payments:</strong> <span class="payment-pill">cash: $495.00</span></div>
                </div>
                <div class="invoice-totals">
                  <div class="totals-line"><span>Subtotal</span><span class="mono">$450.00</span></div>
                  
                  
                  <div class="totals-line tax-component-line"><span>Tax</span><span class="mono">$45.00</span></div>
                  
                  
                  <div class="totals-line totals-grand"><span>Total (USD)</span><span class="mono">$495.00</span></div>
                </div>
              </div>

              
            </article>
  </section>

  <section class="appendix-section" data-section="daily-tax-appendix">
    <h2>Daily Tax Breakdown Appendix</h2>
    <table data-section="taxes">
      <thead>
        <tr>
          <th>Date</th>
          <th>Tax Name</th>
          <th class="num">Rate</th>
          <th class="num">Taxable Base</th>
          <th class="num">Tax Amount</th>
          <th class="num">Gross Amount</th>
        </tr>
      </thead>
      <tbody>
        <tr data-section="tax" data-date="2026-11-08" data-name="Unknown" data-rate="" data-base="" data-tax="270" data-gross="" data-shared-base="false" data-base-additive="false" data-incomplete-detail="true">
            <td class="mono">2026-11-08</td>
            <td>Unknown</td>
            <td class="num">-</td>
            <td class="num"></td>
            <td class="num">$270.00</td>
            <td class="num"></td>
          </tr>
      </tbody>
    </table>
    
  </section>
</body>
</html>
- Outcome: 🔧 1 issue found → no changes applied ✅ across 2 runs (41m19s)

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

✅ **Review** - passed

✅ No issues found.

🔧 **Test** - 1 issue found → no changes applied ✅
  • ⚠️ The Test agent did not finish within its invocation budget. Reported: agent run tests timed out after 30m0s: agent last produced output 387ms ago (83 observed); agent reported: antigravity parse events: context deadline exceeded. This is a budget or provider-slowness cut, not a code failure. Re-running the same request costs another full budget, so no further attempt is made automatically. If this repository's targeted tests or evidence gathering routinely approach the default 30m0s, raise test_agent_timeout in global config. Respond with fix to spend another budget: a repair turn runs only for selected findings other than this budget cut, then validation re-runs. Or abort and retry after raising the budget.

🔧 No changes applied.
✅ Re-checked - no issues remain.

  • Live validation: ✅ go - 6 of 6 scenarios driven live against the product
Scenario Result Live Evidence
Exporting HTML to PDF via save-html-as-pdf IPC uses a 30s default rendering deadline that starts only after the save dialog resolves, producing a valid PDF even when the user pauses in the save dialog… ✅ pass live ~/.no-mistakes/evidence/01M6YFKNJNAQ24EK0STXX2TQM7/live-exported-invoices.pdf and ~/.no-mistakes/evidence/01M6YFKNJNAQ24EK0STXX2TQM7/live-verification-results.j…
When offscreen PDF rendering stalls past the rendering deadline, export fails with a timeout error, immediately destroys the hidden BrowserWindow so work cannot continue in the background, deletes the… ✅ pass live ~/.no-mistakes/evidence/01M6YFKNJNAQ24EK0STXX2TQM7/live-verification-results.json (scenario2_renderTimeout) and npx tsx tests/printer-ipc.test.ts
When the offscreen PDF renderer process terminates unexpectedly (render-process-gone), renderHtmlToPdfBuffer rejects immediately with the termination reason and cleans up the hidden BrowserWindow,… ✅ pass live ~/.no-mistakes/evidence/01M6YFKNJNAQ24EK0STXX2TQM7/live-verification-results.json (scenario3_rendererCrash) and npx tsx tests/printer-ipc.test.ts
When the hidden PDF BrowserWindow closes unexpectedly during rendering (closed event), renderHtmlToPdfBuffer rejects immediately and cleans up the staging HTML file, timers, and listeners ✅ pass live ~/.no-mistakes/evidence/01M6YFKNJNAQ24EK0STXX2TQM7/live-verification-results.json (scenario4_windowClosed) and npx tsx tests/printer-ipc.test.ts
When pdfWindow.loadFile() fails to load the document, the rejection propagates directly without registering a redundant did-fail-load listener, and cleans up the hidden BrowserWindow, staging HTML… ✅ pass live ~/.no-mistakes/evidence/01M6YFKNJNAQ24EK0STXX2TQM7/live-verification-results.json (scenario5_loadFileFailure) and npx tsx tests/printer-ipc.test.ts
Projecting a multi-bill batch through getOrdersWithItemsForBills hoists the tenant currency minor-unit factor lookup outside the per-bill loop so SQLite settings is queried once per call rather th… ✅ pass live ~/.no-mistakes/evidence/01M6YFKNJNAQ24EK0STXX2TQM7/live-verification-results.json (scenario6_currencyHoist) plus npx tsx tests/printer-ipc.test.ts and `npx tsx tests/daily-invoic…
  • npx tsx tests/printer-ipc.test.ts
  • npx tsx tests/daily-invoices-export.test.ts
  • npx tsx tests/reports-export.test.ts
  • ./node_modules/.bin/electron --no-sandbox live verification driving save-html-as-pdf IPC, renderHtmlToPdfBuffer failure modes (forcefullyCrashRenderer, window.close, stalled printToPDF, failed loadFile), and getOrdersWithItemsForBills SQLite query count across 6 bills
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

Add a 30-second rendering deadline, renderer termination handling, and window-close cleanup in renderHtmlToPdfBuffer, and hoist the currency minor-unit factor lookup out of the per-bill loop in getOrdersWithItemsForBills.

Fixes #1518
@coderabbitai

coderabbitai Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@qodo-code-review

Copy link
Copy Markdown

ⓘ Your Qodo trial ends soon. Ask your workspace admin to set up billing to keep reviews running after the trial. Manage billing

@qodo-code-review

Copy link
Copy Markdown

PR Summary by Qodo

Add a PDF render deadline and avoid repeated bill currency lookups

🐞 Bug fix 🧪 Tests 🕐 40+ Minutes

Grey Divider

AI Description

• Limit PDF rendering to 30 seconds without counting time spent in the save dialog.
• Abort stalled or terminated renders and clean up the hidden window and staged HTML.
• Read the tenant currency factor once per bill batch instead of once per bill.
Diagram

graph TD
  subgraph PDF_export
    Dialog["Save dialog"] --> Renderer["PDF renderer"] --> Stage[("Staged HTML")] --> Window["Hidden window"] --> Buffer["PDF buffer"]
  end
  subgraph Bill_projection
    Bills["Bill batch"] --> Factor["Currency factor"] --> Orders["Projected orders"]
  end
Loading
High-Level Assessment

Keep the deadline inside the shared PDF rendering service and destroy the window on timeout. A Promise.race alone would leave rendering work running; placing the deadline around the IPC handler would incorrectly include time in the save dialog. Hoisting the currency factor within the batch function avoids repeated settings reads without introducing caching or invalidation concerns.

Files changed (5) +322 / -22

Bug fix (2) +87 / -9
bills.tsCalculate the currency factor once per bill batch +1/-1

Calculate the currency factor once per bill batch

• Moves the tenant currency minor-unit factor lookup outside the bill loop so every projected bill uses the same factor without repeating settings reads.

main/routes/bills.ts

html-to-pdf.tsBound PDF rendering and handle renderer failures +86/-8

Bound PDF rendering and handle renderer failures

• Adds a 30-second render deadline and immediate rejection on renderer termination or unexpected window closure. Timeout destroys the hidden window; final cleanup clears guards and removes the staged HTML. A timeout override supports tests.

main/services/html-to-pdf.ts

Tests (3) +235 / -13
daily-invoices-export.test.tsSupport PDF lifecycle listeners in invoice test doubles +5/-4

Support PDF lifecycle listeners in invoice test doubles

• Makes the fake BrowserWindow and its webContents event emitters so invoice export tests remain compatible with the new render guards.

tests/daily-invoices-export.test.ts

printer-ipc.test.tsCover PDF abort paths and batch currency reads +225/-5

Cover PDF abort paths and batch currency reads

• Adds tests for save-dialog timing, render timeout, renderer termination, window closure, load failure, resource cleanup, and the number of settings reads for a multi-bill batch.

tests/printer-ipc.test.ts

reports-export.test.tsSupport PDF lifecycle listeners in report test doubles +5/-4

Support PDF lifecycle listeners in report test doubles

• Makes the mocked report export window and webContents event emitters to accommodate the new renderer and window-close listeners.

tests/reports-export.test.ts

@qodo-code-review

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider

Great, no issues found!

Qodo reviewed your code and found no material issues that require review

Grey Divider

Tip of the day
💡 Did you know, you can pick a display mode instead of tweaking every Display option by hand

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

@khaira777 khaira777 changed the title fix: add PDF render timeout and hoist bill currency lookup fix(export): add PDF timeout and hoist currency Nov 8, 2026
@khaira777
khaira777 merged commit 13e6aa4 into main Nov 8, 2026
23 checks passed
@khaira777
khaira777 deleted the fm/flocafe-export-pdf-timeout-and-currency-hoist branch November 8, 2026 22:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(export): add 30s PDF render deadline and hoist currency lookup

1 participant