Investigation Log: BUG-001 - Grafici del Backtest Forecast Anomali

Versione: 1.0 Data: 2025-11-08 Stato: APERTO - NON RISOLTO


1. Sintomo

Dopo il refactoring alla v0.12.0 e il successivo ripristino alla base v11.28 con un ambiente di dipendenze aggiornato, tutti i grafici renderizzati dal componente QCPlotlyChartWidget sono anomali.

  • Comportamento Osservato: Invece dei dati corretti (prezzi, metriche), i grafici mostrano linee rette crescenti a 45 gradi.
  • Componenti Interessati: Il problema affligge sia i grafici dei risultati del “Model Backtester” (forecast, MAE, RMSE) sia il grafico principale del ticker (“Dati Reali”).
  • Assenza di Errori: L’applicazione non va in crash. I worker terminano con successo e non ci sono traceback nel terminale Python.

2. Registro delle Investigazioni e Tentativi Falliti

Questa sezione documenta tutti i tentativi di diagnosi e risoluzione effettuati, che si sono rivelati infruttuosi. Queste piste sono da considerarsi esaurite.

Tentativo #1: Ipotesi di Dati Corrotti dal Worker

  • Ipotesi: Il ForecastBacktestWorker sta generando dati errati (es. indici invece di valori).
  • Azione: Aggiunto logging diagnostico avanzato nel worker per ispezionare il contenuto di forecast_values ad ogni step.
  • Risultato: SMENTITA. I log hanno dimostrato in modo inequivocabile che il worker produce array numpy con valori numerici corretti e sensati.
  • Conclusione: Il problema non è nella generazione dei dati.

Tentativo #2: Ipotesi di Corruzione nella Trasmissione dei Dati

  • Ipotesi: I dati vengono corrotti durante la trasmissione tramite segnali Qt tra il worker e la UI.
  • Azione: Aggiunto logging diagnostico sia nel worker (immediatamente prima di emit) sia nel widget della UI (immediatamente dopo aver ricevuto il segnale).
  • Risultato: SMENTITA. I log hanno dimostrato che il dizionario results, contenente DataFrame e Series pandas, arriva alla UI identico e non corrotto.
  • Conclusione: Il problema non è nel layer di comunicazione Signal/Slot.

Tentativo #3: Ipotesi di Bug nel Rendering JavaScript

  • Ipotesi: Il componente QCPlotlyChartWidget ha un bug nel suo codice JavaScript che causa un errore di rendering silenzioso.
  • Azione: Abilitato il remote debugging di QWebEngine per ispezionare la Console JavaScript del widget durante l’esecuzione.
  • Risultato: SMENTITA. La console del browser è rimasta completamente vuota. Nessun errore, nessun warning, nessun log. Questo indica che il codice JavaScript renderPlotly non viene eseguito o fallisce in un modo che il debugger non cattura.

Tentativo #4: Ipotesi di Bug di Doppia Codifica JSON

  • Ipotesi: Un bug latente nel codice Python di QCPlotlyChartWidget (json.dumps(figure_json)) stava causando un errore di parsing silenzioso in JavaScript.
  • Azione: Corretto il bug oggettivo, passando il JSON a JavaScript in modo corretto.
  • Risultato: FALLITO. Nonostante la correzione, il sintomo visivo è rimasto identico.
  • Conclusione: Sebbene il bug esistesse, non era la causa principale del problema.

3. Stato Attuale e Prossimi Passi

  • Causa Radice: SCONOSCIUTA.
  • Area del Problema: Abbiamo isolato il problema al 100% all’interno del widget QCPlotlyChartWidget.py o del suo ambiente di esecuzione (QWebEngineView). Sappiamo che riceve dati Python corretti ma non riesce a renderizzarli.
  • Prossima Azione: L’investigazione è sospesa per dare priorità alla stabilizzazione dei processi di gestione delle dipendenze. Il prossimo tentativo di debug dovrà concentrarsi esclusivamente sull’interazione tra Python, QWebEngineView e la libreria Plotly.js, forse tentando di renderizzare un grafico statico e minimale per isolare ulteriormente il problema.

Librerie versione 12

(.venv) PS D:\01_DevOps\fire\fireDev> pip show plotly Name: plotly Version: 6.4.0 Summary: An open-source interactive data visualization library for Python Home-page: https://plotly.com/python/ Author: Author-email: Chris P chris@plot.ly License: MIT License

Copyright (c) 2016-2024 Plotly Technologies Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Location: D:\01_DevOps\fire\fireDev.venv\Lib\site-packages Requires: narwhals, packaging Required-by: (.venv) PS D:\01_DevOps\fire\fireDev> pip show pandas Name: pandas Version: 2.3.3 Summary: Powerful data structures for data analysis, time series, and statistics Home-page: https://pandas.pydata.org Author: Author-email: The Pandas Development Team pandas-dev@python.org License: BSD 3-Clause License

Copyright (c) 2008-2011, AQR Capital Management, LLC, Lambda Foundry, Inc. and PyData Development Team All rights reserved.

Copyright (c) 2011-2023, Open source contributors.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

  • Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Location: D:\01_DevOps\fire\fireDev.venv\Lib\site-packages Requires: numpy, python-dateutil, pytz, tzdata Required-by: alpaca-py, cmdstanpy, prophet, seaborn (.venv) PS D:\01_DevOps\fire\fireDev> pip show PySide6 Name: PySide6 Version: 6.10.0 Summary: Python bindings for the Qt cross-platform application and UI framework Home-page: https://pyside.org Author: Author-email: Qt for Python Team pyside@qt-project.org License: LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only Location: D:\01_DevOps\fire\fireDev.venv\Lib\site-packages Requires: PySide6_Addons, PySide6_Essentials, shiboken6 Required-by: (.venv) PS D:\01_DevOps\fire\fireDev> pip show timesfm Name: timesfm Version: 2.0.0 Summary: A time series foundation model. Home-page: Author: Author-email: Rajat Sen senrajat@google.com, Yichen Zhou yichenzhou@google.com, Abhimanyu Das abhidas@google.com, Petros Mol pmol@google.com, Michael Chertushkin chertushkinmichael@gmail.com License: Apache-2.0 Location: D:\01_DevOps\fire\fireDev.venv\Lib\site-packages Requires: huggingface_hub, numpy, safetensors Required-by: (.venv) PS D:\01_DevOps\fire\fireDev>

Librerie versione 11

(.venv) PS D:\01_DevOps\fire\fireDev_11> pip show plotly Name: plotly Version: 6.4.0 Summary: An open-source interactive data visualization library for Python Home-page: https://plotly.com/python/ Author: Author-email: Chris P chris@plot.ly License: MIT License

Copyright (c) 2016-2024 Plotly Technologies Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Location: D:\01_DevOps\fire\fireDev.venv\Lib\site-packages Requires: narwhals, packaging Required-by: (.venv) PS D:\01_DevOps\fire\fireDev_11> pip show pandas Name: pandas Version: 2.3.3 Summary: Powerful data structures for data analysis, time series, and statistics Home-page: https://pandas.pydata.org Author: Author-email: The Pandas Development Team pandas-dev@python.org License: BSD 3-Clause License

Copyright (c) 2008-2011, AQR Capital Management, LLC, Lambda Foundry, Inc. and PyData Development Team All rights reserved.

Copyright (c) 2011-2023, Open source contributors.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

  • Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Location: D:\01_DevOps\fire\fireDev.venv\Lib\site-packages Requires: numpy, python-dateutil, pytz, tzdata Required-by: alpaca-py, cmdstanpy, prophet, seaborn (.venv) PS D:\01_DevOps\fire\fireDev_11> pip show PySide6 Name: PySide6 Version: 6.10.0 Summary: Python bindings for the Qt cross-platform application and UI framework Home-page: https://pyside.org Author: Author-email: Qt for Python Team pyside@qt-project.org License: LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only Location: D:\01_DevOps\fire\fireDev.venv\Lib\site-packages Requires: PySide6_Addons, PySide6_Essentials, shiboken6 Required-by: (.venv) PS D:\01_DevOps\fire\fireDev_11> pip show timesfm Name: timesfm Version: 2.0.0 Summary: A time series foundation model. Home-page: Author: Author-email: Rajat Sen senrajat@google.com, Yichen Zhou yichenzhou@google.com, Abhimanyu Das abhidas@google.com, Petros Mol pmol@google.com, Michael Chertushkin chertushkinmichael@gmail.com License: Apache-2.0 Location: D:\01_DevOps\fire\fireDev.venv\Lib\site-packages Requires: huggingface_hub, numpy, safetensors Required-by: (.venv) PS D:\01_DevOps\fire\fireDev_11>


Risultati dell’Audit: La Mappa delle Differenze

Ecco un riepilogo delle discrepanze più critiche tra la versione fire12 (buggata) e la fire11 (funzionante).

Filefire12 (Buggata)fire11 (Funzionante)Analisi della Differenza
qc_plotly_chart_widget.pyv1.9.0, 185 righev1.8.0, 127 righeCRITICA. La versione fire12 è molto più complessa. Contiene i nostri tentativi di fix (Base64, ecc.) che hanno peggiorato la situazione, portando al grafico completamente vuoto. La versione fire11 è più semplice.
forecast_results_widget.pyv1.8.0, 116 righev1.7, 251 righeLA PISTOLA FUMANTE. La versione fire12 è meno della metà della versione funzionante. Manca quasi tutta la logica di plotting, inclusa la gestione delle date. Questa è la causa principale del bug.
forecast_backtest_widget.pyv1.11.1-debug, 118 righev1.11, 112 righeDifferenza minore. È il file in cui abbiamo aggiunto il popup di debug. Non è la causa del problema.
workers/enrichment/*Mancano fileEsistono fileLa directory enrichment in fire12 non contiene i file presenti in fire11, ma questo è probabilmente un errore del report fire12.
workers/query_worker.pyv3.2.1, 124 righev2.2, 84 righeDifferenza significativa, ma non correlata al nostro bug di charting.

File Identici (Campione)

La maggior parte degli altri file, specialmente nel core e nei connettori, sono risultati identici, confermando che il problema è estremamente localizzato. Esempi:

  • app_state.py (v4.1.0, 127 righe)
  • data_manager.py (v1.9, 105 righe)
  • forecast_backtest_worker.py (v1.6, 199 righe)

Diagnosi Finale e Definitiva

  1. Causa Radice: Durante il refactoring o il ripristino del codice che ha creato fire12, il file forecast_results_widget.py è stato accidentalmente sostituito con una versione vecchia o incompleta, priva di quasi tutta la sua logica fondamentale.
  2. Effetto a Cascata: Questa versione “mutilata” non preparava più i dati per Plotly, innescando il bug di serializzazione delle date che abbiamo scoperto con il test debug_plotly_serialization.py.
  3. Fattore di Confusione: I nostri tentativi di fix sul qc_plotly_chart_widget.py non potevano funzionare perché stavamo cercando di risolvere il problema nel punto sbagliato della catena. Inoltre, il problema di cache dei file .pyc ci ha impedito di vedere i reali risultati delle nostre modifiche, mandandoci fuori strada.