fix(hud): session self-heal & stale state detection (Wave 1-B)#1469
Closed
JeremyDev87 wants to merge 2 commits into
Closed
fix(hud): session self-heal & stale state detection (Wave 1-B)#1469JeremyDev87 wants to merge 2 commits into
JeremyDev87 wants to merge 2 commits into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Resolves the bug where statusLine renders leftover fields from a prior session (e.g. sessionId="manual-fix", currentMode="ACT" when user is in PLAN mode) instead of the current state. New lib/hud_session.py module: - detect_stale_session(): 4-signal staleness check (empty / repair marker / stdin mismatch / age > 4h) - heal_stale_state(): soft reset, returns copy, doesn't write disk - reset_stale_session(): durable variant for session-start boot - SESSION_STALE_SECONDS constant (4 hours) codingbuddy-hud.py::main() heals state before rendering so every statusLine render sees a valid snapshot. 24 new tests in test_hud_session.py cover all 4 staleness signals, heal semantics (clear / preserve / non-mutation / empty state), and reset_stale_session edge cases (fresh noop, marker healed, missing file silent, malformed silent). 179/179 tests pass (Golden Rule 133 + Wave 0 22 + Wave 1-B 24). Closes #1468 Part of #1464 (Wave 0 statusbar refactor)
7af514c to
dc78f1f
Compare
fe6f8c0 to
bd8346d
Compare
7b89e0b to
11c38dd
Compare
Combined Wave 0 polish items from the #1465/#1485 review cycle: 1. Narrow `except Exception` to `except ImportError` in the 3 lib fallback import blocks (qual-1465 HIGH-1). Real logic bugs (SyntaxError, NameError, AttributeError) inside lib modules now surface immediately instead of being silently swallowed by a catch-all. 2. Drop inline stub functions for format_rate_limits and _get_fresh_version (qual-1465 HIGH-2). Eliminates the signature drift between canonical lib definitions and in-file fallback stubs observed on the integrator branch (Wave 1-A plugin_json_file kwarg drift). The outer main() try/except still catches any runtime failure and emits the minimal safe output via the BUDDY_FACE constant. 3. Hoist hud_velocity and hud_cache_savings imports to module top as _format_velocity_segment and _format_cache_savings (perf-1485 H1). Eliminates ~0.47us sys.modules lookup per render. Integrator branch only - no-op on refactor/wave branches where the inline imports don't exist yet. 4. Bump next to 16.2.3 for GHSA-q4gf-8mx6-v5v3 (landing-security-check). Aligns eslint-config-next and updates setup.test.ts assertion. Refs: qual-1465 HIGH-1/2, perf-1485 H1, GHSA-q4gf-8mx6-v5v3
bd8346d to
c7eb3b9
Compare
Owner
Author
Superseded by #1485This PR was part of a stacked PR structure ( All of this PR's commits have been consolidated into #1485 (now with
EVAL review results from this PR (all reviewers, iter1 converged → Critical=0, High=0) already applied in #1485. Closing as superseded. Use #1485 with GitHub's Rebase and merge button to land all 12 commits linearly on master. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1468
Stacked on #1465 (Wave 0 refactor — must merge first)
Summary
Fixes the status bar "PLAN shown as ACT" bug by introducing a 4-signal staleness check and soft-reset healing that runs on every statusLine render.
Root Cause
hud-state.jsonis written at session-start and never invalidated. Real-world incident: the hud-state.json showedsessionId: \"manual-fix\",sessionStartTimestamp: 2026-03-29(12 days old),currentMode: \"PLAN\",version: \"5.2.0\"— but the actual current session was on 2026-04-11 with plugin v5.5.0.Design
New
lib/hud_session.pymodule (replaces Wave 0 skeleton):detect_stale_session(state, *, now=None, stdin_session_id=\"\")heal_stale_state(state) -> dictreset_stale_session(state_file)SESSION_STALE_SECONDS = 14400Integration
codingbuddy-hud.py::main()now calls:```python
hud_state = read_state(state_file)
try:
from hud_session import detect_stale_session, heal_stale_state
stdin_session_id = (stdin_data.get("session_id") if stdin_data else "") or ""
if detect_stale_session(hud_state, stdin_session_id=stdin_session_id):
hud_state = heal_stale_state(hud_state)
except Exception:
pass # never block rendering on self-heal failure
```
Defensive try/except ensures a buggy self-heal never crashes the statusLine.
Tests
24 new tests in
test_hud_session.py:detect_stale_session (15 tests):
heal_stale_state (5 tests):
reset_stale_session (4 tests):
Test Results
179/179 tests pass (Golden Rule 133 + Wave 0 22 + Wave 1-B 24)
Backwards Compatibility
codingbuddy-hud.pymain()enhancement is defensive (try/except)