Skip to content

Conversation

@springfall2008
Copy link
Owner

… to predbat stopping running

Copilot AI review requested due to automatic review settings January 23, 2026 08:11
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a critical bug where exceptions in load_user_config() or validate_config() would cause the prediction_started flag to remain True, permanently blocking all future predictions and causing Predbat to stop running. The fix moves these potentially-failing operations inside try-catch blocks so that the finally block can properly reset the flag.

Changes:

  • Moved load_user_config() and validate_config() calls inside try-catch blocks in both update_time_loop() and run_time_loop()
  • Improved error logging in hass.py timer_tick() to provide better context
  • Version bump from v8.32.10 to v8.32.11

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
apps/predbat/predbat.py Moved config loading operations inside try-catch blocks in update_time_loop() and run_time_loop() to ensure prediction_started flag is properly reset on exceptions; version bump
apps/predbat/hass.py Enhanced error message in timer_tick() exception handler to include more context
Comments suppressed due to low confidence (2)

apps/predbat/predbat.py:1593

  • The changes to exception handling in update_time_loop() lack test coverage. Consider adding tests that verify: 1) prediction_started is properly reset to False when exceptions occur in load_user_config() or validate_config(), and 2) subsequent iterations can run after an exception. This is critical functionality that prevents predbat from stopping permanently.
            try:
                self.load_user_config()
                self.validate_config()
                self.update_pred(scheduled=False)
                self.create_entity_list()
            except Exception as e:
                self.log("Error: Exception raised {}".format(e))
                self.log("Error: " + traceback.format_exc())
                self.record_status("Error: Exception raised {}".format(e), debug=traceback.format_exc(), had_errors=True)
                raise e
            finally:
                self.prediction_started = False

apps/predbat/predbat.py:1667

  • The changes to exception handling in run_time_loop() lack test coverage. Consider adding tests that verify: 1) prediction_started is properly reset to False when exceptions occur during config loading or prediction, 2) update_pending state is handled correctly on exception, and 3) subsequent iterations can run after an exception. This is critical functionality that prevents predbat from stopping permanently.
            try:
                config_changed = False
                if self.update_pending:
                    self.update_pending = False
                    self.ha_interface.update_states()
                    self.load_user_config()
                    self.validate_config()
                    config_changed = True

                # Run the prediction
                self.update_pred(scheduled=True)

                if config_changed:
                    self.create_entity_list()
            except Exception as e:
                self.log("Error: Exception raised {}".format(e))
                self.log("Error: " + traceback.format_exc())
                self.record_status("Error: Exception raised {}".format(e), debug=traceback.format_exc(), had_errors=True)
                raise e
            finally:
                self.prediction_started = False

self.check_entity_refresh()
if self.update_pending and not self.prediction_started:
# Full update required
self.update_pending = False
Copy link

Copilot AI Jan 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent handling of update_pending flag compared to run_time_loop(). In run_time_loop() (line 1650), update_pending is set to False inside the try block, ensuring it's only cleared after successful config loading. However, here it's set to False before the try block. If an exception occurs in load_user_config() or validate_config(), the pending update will be lost and won't retry on the next iteration. Consider moving line 1580 inside the try block for consistency and correctness.

Copilot uses AI. Check for mistakes.
@springfall2008 springfall2008 changed the title Fix code outside catch but instead prediction_started that could lead… Fix potential crash, GECloud missing entity, Web dashboard html escape issue Jan 23, 2026
@springfall2008 springfall2008 merged commit fa9a642 into main Jan 23, 2026
1 check passed
@springfall2008 springfall2008 deleted the fix_crash2 branch January 23, 2026 08:37
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.

2 participants