Report renderer
The HTTP server owns reports: their records, templates, schedules, permissions and downloads. The TCP server produces the files, because most of the data a report shows (energy, alerts, presence) lives here. This page describes the TCP side of that contract: what the renderer does with a request, what it sends back, and what is built so far.
The contract itself — every field of both events, the manifest, the templates and their sections, the redaction rules — is the HTTP server's report spec of 2026-11-02 (ADR 0008, TCP-REQ-11). This page does not repeat it.
Flow
What the renderer guarantees
| Situation | Behaviour |
|---|---|
| The same request delivered again after the attempt finished | Nothing is rendered or uploaded again. The files the HTTP server verified by sha256 are never overwritten. |
| Sending the outcome fails | Retried in the same run (4 tries, 1 s → 4 s apart). If it still fails, the message is put back with a 30-second delay, not the queue's 30-minute timeout, so the retry comes within the report's deadline: the stored READY/FAILED event is sent again and nothing is re-rendered. |
| A brief S3 or database error reading the manifest or the report's figures | Retried in the same run (3 tries, 1 s then 2 s apart). |
| A lasting S3 or database error | The message is redelivered after 30 seconds and the render starts again; seq continues above the last one sent (it is stored before each event goes out). On the queue's last delivery (the 3rd) the attempt is reported FAILED RENDERER_ERROR instead, so the HTTP server is never left waiting for RENDER_TIMEOUT. |
| A crash mid-render | Redelivered: re-renders and overwrites the same keys. A crash that kills the process before it can shorten the wait is redelivered after the queue's 30 minutes, which is past the deadline of most reports. |
| A newer attempt of the same report was picked up | The older one stops before uploading and sends nothing more. |
Past the request's deadline, on arrival or while rendering | Nothing is uploaded or sent: the HTTP server has already marked the report RENDER_TIMEOUT. |
| An upload keeps failing | Retried with backoff (1 s doubling to 30 s) until 30 s before the deadline or before the Lambda's own time runs out, whichever is first, then FAILED UPLOAD_FAILED. |
| A render that cannot finish within the Lambda's 15 minutes | FAILED RENDERER_ERROR ("The report took too long to generate…") 30 s before the limit, rather than retrying into the same limit. |
locale other than en | FAILED TEMPLATE_UNSUPPORTED; for ur: "Urdu reports are not available yet". |
PARTNER_COMMISSION_STATEMENT, or any template not live | FAILED TEMPLATE_UNSUPPORTED. |
A request or manifest that breaks the contract (wrong uploads for the format, manifest older than v3 or for another attempt, a field of the wrong type, a scopeLevel other than OPERATOR or PLATFORM) | FAILED RENDERER_ERROR; the detail is in the renderer's log only. A malformed field still fails the attempt it names, so the HTTP server is not left waiting for RENDER_TIMEOUT. |
| A logo that is missing, too large (over 5 MB) or not next to the manifest | The cover renders without it. |
Progress events (RENDERING with a stage) are sent at most every 10
seconds. Status events go out on cse-tcp-be-<stage>-events with the type
in the body and as the SNS message attribute type. Every upload carries
an S3 SHA-256 checksum, so S3 rejects bytes that do not match the hash
reported in READY.
Files
- PDF: A4 portrait, laid out by headless Chromium from an HTML template. Cover (logo when the request asks for the customer logo and the manifest has one, title, period, the issuing Business, report code, plant count, generation time in the period's timezone), the sections in the requested order (key figures, a table, notes), then footnotes (timezone, the CO₂ factor marked "provisional factor", a note when the period has not ended or some plants recorded no data).
- PREVIEW: page 1 as a PNG, 1200 px wide.
Chromium prints only once the page has loaded, its fonts are ready and the cover logo has decoded, so the logo is never missing from the PDF. A browser that crashed is fully stopped before the next render starts a new one.
Chromium runs in Lambda with --no-sandbox --no-zygote. Lambda refuses the
namespace calls Chromium's zygote makes before forking its helper
processes, so without --no-zygote it never starts. The image builds its
font cache at build time (fc-cache), so a cold start does not rebuild it
in /tmp. Chromium may take up to 60 s to start, and if it fails, its own
output is in the renderer's log. A one-plant monthly report renders in about
25 s on a cold start, using about 640 MB.
- XLSX: a
Reportsheet with the cover fields and footnotes, then one sheet per section, named by its heading (cut to Excel's 31 characters, without the characters Excel refuses, numbered when two collide). Numbers stay numbers; a figure that was not measured is an empty cell, never 0.
The Business name on the cover is the manifest's operator.name (manifest
v4) when the HTTP server sends it, else the operator org's name from TCP's
org projection (org.upserted.v1). The renderer accepts manifest v3 and
later and reads fields by presence: v4 added operator and
plants[].regionName, v5 adds platform reports (below).
Platform reports (manifest v5)
Crown HQ (Super Admin or Administrator in the platform org) can generate a
report across several Businesses. The HTTP server marks it with manifest
v5's scopeLevel: "PLATFORM", lists the Businesses in operators[]
(orgId, name, plantCount, sorted by name) and gives every plant its
operatorOrgId. operator and the request's operatorOrgId are then the
platform org, and branding.logo is Crown's own brand asset. Without
scopeLevel, or with OPERATOR, a report renders exactly as before.
| Operator report | Platform report | |
|---|---|---|
| Cover | Issued by the Business | Issued by the platform org; a "Scope" line and the Businesses (their names when 5 or fewer, else how many) |
| Logo | The Business's, when the template uses the customer logo | Crown's, under the same rule |
| Plant order in tables | Manifest order | Grouped by Business (by name, unnamed ones last), manifest order within each |
| Per-plant tables | Plant column | Plant, then a Business column |
AVAILABILITY_BY_REGION | One row per region | One row per region of each Business, with its Business: region tags belong to a Business, so two Businesses' "Lahore" are never merged |
| Extra section | — | Summary by Business, first: per Business and for all, plants, capacity, plants with data, production, expected and actual vs expected (when the template reads plant targets), availability, estimated saving per currency (when the template has SAVINGS_ESTIMATE) and open work orders (when the manifest has work orders). Also a sheet in the XLSX. |
XLSX Report sheet | Adds a Businesses row |
Alert counts (ALERTS_SUMMARY, ALERT_MIX_MTTR) are read for the report
as a whole and are not split per Business; the summary says so.
Telemetry is read by plant id only, never by org, so plants of every
Business in the manifest are read; nothing filters them by the request's
operatorOrgId. A Business that operators[] sends without a name is
named from TCP's org projection (at most 50 lookups; otherwise its org id
is printed). A plant without operatorOrgId is grouped under "Business not
recorded".
Size. A platform report may hold 5,000 plants. Building a 5,000-plant, 40-Business document takes about 0.1 s in the renderer's tests (HTML about 180 KB); the figure reads are one query per kind of data over all plant ids. Tables are still capped at 500 rows in both PDF and XLSX, so a 5,000-plant report lists 500 plants per table and says how many were left out; the Summary by Business and the key figures cover all plants.
No file carries a user id, an email, a phone number or (with
omitDeviceSerials) a device serial; the request's requestedBy is never
read.
The CO₂ factor is ANALYTICS_CO2_KG_PER_KWH, the same value the Analytics
screens use (0.5 kg CO₂/kWh, the product owner's provisional figure).
Sections
Every figure comes from the same stored rollups and rules the Analytics and fleet screens use, so a report and a screen over the same plants and period agree. A section with no data source, or no data for any plant, prints a "not available" block with the reason, never zeros; a plant without a figure shows "—". Tables are capped at 500 rows (the report says how many were left out).
| Section | Content | Source |
|---|---|---|
PRODUCTION_VS_EXPECTATION | Per plant: production, expected, actual vs expected, and what "expected" is based on | plant_energy_daily; expected = the plant's targets (monthly, yearly, expected-yield model), else the manifest's expectedAnnualYieldKwh above 0, else an estimate of 1,500 kWh per kWp a year ("Estimate (1,500 kWh/kWp a year)") — the console's rule |
SELF_CONSUMPTION_EXPORT | Production, exported, self-consumed, imported, consumption | plant_energy_daily flows; "—" for a plant whose grid counters are not mapped (IP20, Aotai without a meter) |
SAVINGS_ESTIMATE | Self-consumed × import rate + exported × export rate, per plant, in the plant's own currency (never converted) | Manifest money (tariff, else flat electricity rate) × measured flows. A time-of-use plant is priced every 15 minutes at the rate in force in its local time, from telemetry_15m; a period starting more than 4 months ago (that data's retention) says "not available" for it |
ALERTS_SUMMARY | Alerts raised by severity, cleared, mean time to clear | alert_history + alerts_active, raised in the period |
NEW_CRITICAL_ALERTS | Critical alerts raised in the period, newest 200 | Same; logger id only when omitDeviceSerials is false |
SERVICE_VISITS, SERVICE_ACTIONS | Completed work orders | Manifest workOrders; internal notes only on an INTERNAL report without omitInternalNotes |
MAINTENANCE_CARRIED_OUT | Completed maintenance, repair, cleaning, inspection, replacement and firmware work, with counts by type | Manifest workOrders |
SERVICE_BACKLOG | Open work orders per plant by priority, oldest age | Manifest workOrders |
AVAILABILITY_BY_REGION | Availability per region and for the fleet, grid-outage hours | Stored per-day availability (D-3, below); region name from the manifest's plants[].regionName (v4) when sent, else the region id |
DOWNTIME_CAUSES | Device-hours of fault downtime, logger offline, grid outage (shown, but excluded from availability), and no-data time (no readings with no alert open: lowers availability, not downtime) | The console's downtime rule; curtailment is not measured |
DOWNTIME_RECORD | Per plant: availability, fault, offline, grid-outage and no-data hours (empty when not measured); technician-recorded downtime as context | Same, plus workOrders |
ALERT_MIX_MTTR | Alerts by kind with share, mean time to clear by severity | Alert history; human repair time is in the service sections |
WORST_PLANTS | The 10 plants with the lowest yield per kWp | plant_energy_daily ÷ manifest capacityKwp |
YIELD_BY_PLANT, PRODUCTION_BY_PLANT | Production, capacity, yield per kWp, best first | Same |
PLANTS_BELOW_EXPECTATION | Plants under 80 % of expected | As PRODUCTION_VS_EXPECTATION |
DEVICES_NOT_REPORTING | Devices with no report for 24 hours or more at generation time. Out-of-service devices (deactivated or revoked) are left out | devices, device_alert_state |
YEARLY_PRODUCTION | Production per month, total, vs expected | plant_energy_monthly |
CO2_AVOIDED | Production × the CO₂ factor | plant_energy_daily, ANALYTICS_CO2_KG_PER_KWH |
PLANTS_UNDER_MANAGEMENT | Plants and installed capacity | Manifest |
PR_VS_GUARANTEE | Not available: no performance guarantee is recorded | — |
COMMISSION_CALCULATION | Not available: commission rules are not modelled | — |
Availability is producing ÷ (daylight − grid outage) in 15-minute device slots, computed per plant-day and shared with the console. See Fleet analytics.
When any plant in the report has no-data time (daylight during which a
device sent no readings while no offline or fault alert was open), the
availability and downtime sections add a note with the total device-hours.
It is the same figure as the console's availability.noDataHours, and it
explains a low availability that the downtime figures do not. A second
note says it may be understated when some measured days were stored
before it was recorded (until the rollup re-measures them). See Why
availability can be low with no
downtime.
completeness and dataAsOf are sent with READY. A plant is
missing when no device reported on any day of the period;
plantsIncluded counts the others. dataAsOf is the latest time the
plant rollups read were computed.
State
| Part | State |
|---|---|
| Queue, role, Lambda, status events, idempotency, uploads | Deployed on dev |
| End-to-end report (customer monthly summary, PDF + XLSX + preview) | Verified on dev 2026-11-05: READY, accepted by the HTTP server |
Section content, time-of-use savings, completeness, dataAsOf, Business name on the cover | Deployed on dev: the renderer image running on dev was pushed 2026-11-25 and contains them (committed 2026-11-04). No report has rendered on dev since 2026-11-06, so they are not verified end to end there yet |
| Platform reports (manifest v5) | Built and unit-tested, not deployed yet (next npm run deploy) |
Template samples
server/internal/reports/samples/ in this repo holds one sample per
template, tpl-01-sample.pdf / .png to tpl-05-sample.pdf / .png, plus
tpl-02-platform-sample.* (a platform report across three Businesses). The
PNG is page 1, as the real preview is. They come from the real document
builder and Chromium over a made-up fleet ("Demo …" plants and
Businesses); no customer data is read. TPL-05 is built directly because the
renderer answers TEMPLATE_UNSUPPORTED for it. To regenerate them, from
server/:
REPORTS_CHROME_PATH="/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" REPORTS_SAMPLES_OUT=samples go test ./internal/reports/ -run TestTemplateSamples -v
The files are not hosted anywhere. The HTTP server shows a sample when
REPORT_SAMPLES_BASE_URL points at a place that serves these file names.
Data the sections read
| Data | Kept |
|---|---|
Daily energy per device and per plant (energy_daily, plant_energy_daily, plant_energy_monthly) | Indefinitely, from when the energy rollup started |
15-minute aggregates (telemetry_15m) | 4 months: time-of-use savings |
| Alert history | 400 days (365 before migration 0112), so a full calendar year is still there for an annual certificate generated in January |
A period that predates any of these is reported as missing data
(completeness and a "not available" block), not as
PERIOD_OUTSIDE_RETENTION.
Operations
- Logs:
aws logs tail /cse-tcp-be/dev/report-renderer --follow --region us-east-1. - Messages that failed three times are in
cse-tcp-be-dev-report-render-dlq.fifo. - At most
reportRendererMaxConcurrency(2) reports render at once, one database connection each. The HTTP server paces dispatch (reportDispatchPerMinute) to the throughput that sustains. - Deployment and cost: see Infrastructure.