Repository navigation
Commit c24750e
fix(gateway): never enable discharge/export after a failed window write (#5532)
* fix(gateway): never enable discharge/export after a failed window write
For a direct Hub battery, adjust_force_export wrote the discharge start
and end as two separate set_discharge_slot commands, then enabled the
scheduled discharge and switched to export mode regardless of whether
the endpoint writes were applied. schedule_write_ok only withheld the
later commit record. When the end write was refused after the start was
accepted, the Hub was left enabled with a stale wrapping window
(e.g. 02:55-00:01) and actively exporting.
Send both endpoints in one full-serial set_discharge_slot for direct Hub
batteries and verify both endpoint read-backs before continuing. Any
refusal, staged or partial ACK, timeout, publication error or swallowed
async-bridge exception returns before the enable write, export mode and
commit, leaving the commit pending for the next cycle to retry. Both
endpoints are tracked in the control ledger and share one backoff key.
Read-only, entity ownership and serial checks refuse before publishing.
Coordinators keep their staged separate-endpoint sequence; other
providers, disable and midnight windows are unchanged.
Mirrors the charge-window fix in #5531.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018BaJjLpuMEtQYfvmTRcFJf
* fix(gateway): detect coordinator staging before discharge ownership checks
A coordinator whose discharge end entity was not (yet) owned by the
gateway was refused with an ownership error instead of keeping its
staged separate-endpoint sequence. Identify coordinators first, as that
decision only needs the entity names and discovery record.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018BaJjLpuMEtQYfvmTRcFJf
* fix(gateway): stop an armed export when its window move is refused; no re-poll of a refusal
- When the paired window write fails while scheduled export is already
enabled, turn the schedule off and return to Eco instead of leaving
the previous window exporting on a plan that has moved away from it
(skipped in read-only mode).
- A refusal of the exact paired command ends the attempt immediately:
the poll stops when it arrives, and a retry inside the ack window is
not published (_send_control would suppress it anyway), so a refused
write no longer holds the engine for the full poll timeout per retry.
- Drop the unreachable end-serial comparison (the end entity name is
derived from the start, so it carries the same serial) and name the
test case after what it exercises.
- Document that an exception inside a running event loop reaches the
caller as None via run_async's thread, not as an exception.
- Test the write/moved counters for the paired path.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018BaJjLpuMEtQYfvmTRcFJf
* test(gateway): a successful move of an exporting schedule stays enabled
The fail-safe disable applies only to a failed window write.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018BaJjLpuMEtQYfvmTRcFJf
* fix(gateway): only an explicit Hub refusal turns off an exporting schedule
The fail-safe disable fired on any unverified window write, including a
slow but successful one (ACK outside the poll, older firmware without
an applied block, telemetry not yet landed). That stopped a correctly
re-windowed export for a cycle and toggled enable/mode. Take the
disable path only when the Hub refused the exact paired command; an
unconfirmed write leaves the running export alone and keeps the commit
pending for the next cycle. Document that execute.py still reports
"Exporting" for a cycle whose window was refused.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018BaJjLpuMEtQYfvmTRcFJf
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: CI <ci@example.com>1 parent dab5ff6 commit c24750e
4 files changed
Lines changed: 469 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2737 | 2737 | | |
2738 | 2738 | | |
2739 | 2739 | | |
| 2740 | + | |
| 2741 | + | |
| 2742 | + | |
| 2743 | + | |
| 2744 | + | |
| 2745 | + | |
| 2746 | + | |
| 2747 | + | |
| 2748 | + | |
| 2749 | + | |
| 2750 | + | |
| 2751 | + | |
| 2752 | + | |
| 2753 | + | |
| 2754 | + | |
| 2755 | + | |
| 2756 | + | |
| 2757 | + | |
| 2758 | + | |
| 2759 | + | |
| 2760 | + | |
| 2761 | + | |
| 2762 | + | |
| 2763 | + | |
| 2764 | + | |
| 2765 | + | |
| 2766 | + | |
| 2767 | + | |
| 2768 | + | |
| 2769 | + | |
| 2770 | + | |
| 2771 | + | |
| 2772 | + | |
| 2773 | + | |
| 2774 | + | |
| 2775 | + | |
| 2776 | + | |
| 2777 | + | |
| 2778 | + | |
| 2779 | + | |
| 2780 | + | |
| 2781 | + | |
| 2782 | + | |
| 2783 | + | |
| 2784 | + | |
| 2785 | + | |
| 2786 | + | |
| 2787 | + | |
| 2788 | + | |
| 2789 | + | |
| 2790 | + | |
| 2791 | + | |
| 2792 | + | |
| 2793 | + | |
| 2794 | + | |
| 2795 | + | |
| 2796 | + | |
| 2797 | + | |
| 2798 | + | |
| 2799 | + | |
| 2800 | + | |
| 2801 | + | |
2740 | 2802 | | |
2741 | 2803 | | |
2742 | 2804 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2957 | 2957 | | |
2958 | 2958 | | |
2959 | 2959 | | |
| 2960 | + | |
| 2961 | + | |
| 2962 | + | |
| 2963 | + | |
| 2964 | + | |
| 2965 | + | |
| 2966 | + | |
| 2967 | + | |
| 2968 | + | |
| 2969 | + | |
| 2970 | + | |
| 2971 | + | |
| 2972 | + | |
| 2973 | + | |
| 2974 | + | |
| 2975 | + | |
| 2976 | + | |
| 2977 | + | |
| 2978 | + | |
| 2979 | + | |
| 2980 | + | |
| 2981 | + | |
| 2982 | + | |
| 2983 | + | |
| 2984 | + | |
| 2985 | + | |
| 2986 | + | |
| 2987 | + | |
| 2988 | + | |
| 2989 | + | |
| 2990 | + | |
| 2991 | + | |
| 2992 | + | |
| 2993 | + | |
| 2994 | + | |
| 2995 | + | |
| 2996 | + | |
| 2997 | + | |
| 2998 | + | |
| 2999 | + | |
| 3000 | + | |
| 3001 | + | |
| 3002 | + | |
| 3003 | + | |
| 3004 | + | |
| 3005 | + | |
| 3006 | + | |
| 3007 | + | |
| 3008 | + | |
| 3009 | + | |
| 3010 | + | |
| 3011 | + | |
| 3012 | + | |
| 3013 | + | |
| 3014 | + | |
| 3015 | + | |
| 3016 | + | |
| 3017 | + | |
| 3018 | + | |
| 3019 | + | |
| 3020 | + | |
| 3021 | + | |
| 3022 | + | |
| 3023 | + | |
| 3024 | + | |
| 3025 | + | |
| 3026 | + | |
| 3027 | + | |
| 3028 | + | |
| 3029 | + | |
| 3030 | + | |
| 3031 | + | |
| 3032 | + | |
| 3033 | + | |
| 3034 | + | |
| 3035 | + | |
| 3036 | + | |
| 3037 | + | |
| 3038 | + | |
| 3039 | + | |
| 3040 | + | |
2960 | 3041 | | |
2961 | 3042 | | |
2962 | 3043 | | |
| |||
3054 | 3135 | | |
3055 | 3136 | | |
3056 | 3137 | | |
| 3138 | + | |
| 3139 | + | |
| 3140 | + | |
| 3141 | + | |
| 3142 | + | |
| 3143 | + | |
| 3144 | + | |
| 3145 | + | |
| 3146 | + | |
| 3147 | + | |
| 3148 | + | |
| 3149 | + | |
| 3150 | + | |
| 3151 | + | |
| 3152 | + | |
| 3153 | + | |
| 3154 | + | |
| 3155 | + | |
| 3156 | + | |
| 3157 | + | |
| 3158 | + | |
| 3159 | + | |
| 3160 | + | |
| 3161 | + | |
| 3162 | + | |
3057 | 3163 | | |
3058 | | - | |
| 3164 | + | |
3059 | 3165 | | |
3060 | 3166 | | |
3061 | 3167 | | |
| |||
3077 | 3183 | | |
3078 | 3184 | | |
3079 | 3185 | | |
3080 | | - | |
| 3186 | + | |
3081 | 3187 | | |
3082 | 3188 | | |
3083 | 3189 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7444 | 7444 | | |
7445 | 7445 | | |
7446 | 7446 | | |
| 7447 | + | |
7447 | 7448 | | |
7448 | 7449 | | |
7449 | 7450 | | |
| 7451 | + | |
7450 | 7452 | | |
7451 | 7453 | | |
7452 | 7454 | | |
| |||
0 commit comments