Fix silent recalculate failures and wrong step count in the recalculate progress UI¶
Problem¶
Two bugs reported against the BackOffice "Recalculate" action (confirm dialog in
ModuleRecalculationDialog.vue, triggered via useRecalculation.ts):
-
Failures aren't surfaced.
subscribeToJobUpdates(frontend/src/stores/backofficeDataManagement.ts:469-556) exposes two distinct failure signals:onFail(job finished withresult === ERROR, fires aNotify.create({ type: 'negative', ... })inuseRecalculation.ts:80-90/:151-161) andonError(the underlyingEventSourceitself errors — dropped connection, backend crash mid-stream, auth expiry —backofficeDataManagement.ts:549-552). TheonErrorcallback passed fromuseRecalculation.ts(:91-93,:162-164) only resets therecalcRunning/recalcTypeRunningflag — it never callsNotify.create. When the SSE connection drops instead of the job finishing with an explicit error, the spinner just stops with zero feedback: a silent failure. -
Wrong step count during recalculate. Pipeline phase text isn't computed from a count at all — it's hardcoded per
phase_labelinfrontend/src/i18n/backoffice_data_management.ts:624-634:data_management_pipeline_phase_data: 'Step 1/3 - Inserting data...',..._emissions: 'Step 2/3 - Recalculating emissions...',..._aggregation: 'Step 3/3 - Aggregating...'. These three labels are shared by every pipelinekindviaPIPELINE_PHASE_LABEL_KEYSinUploadCard.vue:95-99/ModuleConfig.vue:99-101, keyed only offPipelineProgress.phase_label("data" | "emissions" | "aggregation"), whichcompute_pipeline_progress(backend/app/services/pipeline_progress.py:120-261) derives purely from job state (phase1_doneon root FINISHED,phase2_doneon recalc children FINISHED,phase3_doneon aggregation FINISHED) — it never looks atkind. ARecalculateclick creates a pipeline whose root job is theemission_recalc/module_emission_recalcjob itself (ensure_pipeline_existsindata_sync.py:1610/:1710,kindset at that call — see the comment inUploadCard.vue:101-117), not a preceding CSV/API upload. While that root job is stillRUNNING,phase=1=>phase_label="data"=> the UI shows "Step 1/3 - Inserting data..." even though no data is being inserted and, from the operator's perspective (one "Recalculate" click = one atomic action, ending in a singleNotify.createinuseRecalculation.ts), this is a one-step operation.
Design¶
Fix 1 — surface onError (SSE connection failure) during recalculate¶
useRecalculation.ts already distinguishes onCompleted / onFail from the bare
onError reset callback in both confirmModuleRecalculation (:49-94) and
triggerTypeRecalculation (:120-165). Add the same Notify.create({ type: 'negative',
message: $t('data_management_recalculation_error'), caption: $t(<connection-lost key>) })
call already used in the onFail branch to the onError callback, reusing the existing
data_management_recalculation_error i18n key (add a generic caption key, e.g.
data_management_recalculation_connection_lost, since no payload is available on a raw
EventSource error — distinguish it from the job-level error caption for support/debugging).
This is a store-boundary problem (the onFail/onError split already routes correctly),
not a subscribeToJobUpdates change — no other caller of subscribeToJobUpdates needs
touching, this fix is local to the two recalc call sites.
Fix 2 — recalc-kind pipelines get their own phase vocabulary, not the ingest pipeline's "/3"¶
PipelineProgress already carries kind (pipeline_progress.py:78-85, populated from
pipeline.kind / root job_type) all the way to the frontend (PipelineJob/
PipelineProgress types, pipelineStream, consumed in UploadCard.vue:147-166). Use it:
- Backend: no change to
compute_pipeline_progress's phase/done math (it's correct — root FINISHED, recalc children FINISHED, aggregation FINISHED are still the right oracle for a recalc pipeline, sincemodule_emission_recalcstill chains one aggregation per Design comment atemission_recalculation_tasks.py:590-598). Only the label vocabulary is wrong for thiskind;phase/done/has_errorstay as-is. - Frontend: in
UploadCard.vue(andModuleConfig.vue, which duplicatesPIPELINE_PHASE_LABEL_KEYS), branch the label map onp.kind. Forkind === 'emission_recalc' || kind === 'module_emission_recalc', use a new 1-entry map that collapsesphase_label"data"/"emissions" into a singledata_management_pipeline_phase_recalculatingkey (new i18n string:"Recalculating emissions...", no "Step N/M" prefix — matches the issue's ask that a recalc read as1/1) and suppress the"aggregation"sub-label the same way (aggregation is an implementation detail invisible to whoever clicked "Recalculate", not a phase they triggered). Ingest (csv_ingest/api_ingest/factor_ingest/reference_ingest) pipelines keep the existing 3-keyPIPELINE_PHASE_LABEL_KEYSmap untouched. - De-duplicate
PIPELINE_PHASE_LABEL_KEYS(currently copy-pasted identically in bothUploadCard.vue:95-99andModuleConfig.vue:99-101) into one shared constant/composable while touching both files for the kind-aware map, so the new recalc map doesn't get a third copy to keep in sync.
Steps¶
-
useRecalculation.ts: addNotify.create(negative, reusedata_management_recalculation_error) inside theonErrorcallback ofconfirmModuleRecalculationandtriggerTypeRecalculation - Add
data_management_recalculation_connection_lost(en/fr) tofrontend/src/i18n/backoffice_data_management.ts, used as theNotifycaption for theonErrorpath - Extract
PIPELINE_PHASE_LABEL_KEYS(currently duplicated inUploadCard.vueandModuleConfig.vue) into one shared module - Add a
kind-aware variant:emission_recalc/module_emission_recalcmap to a singledata_management_pipeline_phase_recalculatinglabel instead of the data/emissions/aggregation 3-step map - Add
data_management_pipeline_phase_recalculating(en/fr, e.g. "Recalculating emissions...") tobackoffice_data_management.ts, no step-count prefix - Update
pipelinePhaseLabelKeycomputed inUploadCard.vue(and the equivalent inModuleConfig.vue) to select the map byprops.pipelineProgress?.kind - Regression test: SSE
onerrorduring a recalc job triggers a visibleNotify(mockEventSource, assertNotify.createcalled withtype: 'negative') - Regression test: a
PipelineProgresswithkind: 'emission_recalc'andphase_label: 'data'resolves to the recalculating label, notdata_management_pipeline_phase_data