[kimi] feat: pre-cycle state validation for stale cycle_result.json (#661) #666

Merged
Timmy merged 2 commits from kimi/issue-661 into main 2026-03-21 13:53:12 +00:00
Collaborator

Fixes #661

Changes

Adds validate_cycle_result() to scripts/loop_guard.py as a pre-cycle defense-in-depth measure:

  1. Age check — removes cycle_result.json if older than 2× CYCLE_DURATION (configurable env var, default 5min → 10min stale threshold)
  2. Issue check — removes cycle_result.json if the referenced issue is closed on Gitea
  3. Graceful degradation — keeps file when Gitea API is unreachable (returns None → no action)

Also adds _load_cycle_result() (with markdown-fence handling) and _is_issue_open() helpers.

Tests

15 unit tests in tests/loop/test_loop_guard_validate.py covering:

  • _load_cycle_result(): missing, valid, markdown-fenced, malformed
  • _is_issue_open(): open, closed, no token, API error
  • validate_cycle_result(): no file, stale removal, closed issue removal, API failure graceful degradation, no issue field, threshold boundary
Fixes #661 ## Changes Adds `validate_cycle_result()` to `scripts/loop_guard.py` as a pre-cycle defense-in-depth measure: 1. **Age check** — removes `cycle_result.json` if older than 2× `CYCLE_DURATION` (configurable env var, default 5min → 10min stale threshold) 2. **Issue check** — removes `cycle_result.json` if the referenced issue is closed on Gitea 3. **Graceful degradation** — keeps file when Gitea API is unreachable (returns None → no action) Also adds `_load_cycle_result()` (with markdown-fence handling) and `_is_issue_open()` helpers. ## Tests 15 unit tests in `tests/loop/test_loop_guard_validate.py` covering: - `_load_cycle_result()`: missing, valid, markdown-fenced, malformed - `_is_issue_open()`: open, closed, no token, API error - `validate_cycle_result()`: no file, stale removal, closed issue removal, API failure graceful degradation, no issue field, threshold boundary
kimi added 1 commit 2026-03-21 02:52:56 +00:00
feat: add pre-cycle state validation for stale cycle_result.json
Some checks failed
Tests / lint (pull_request) Has been cancelled
Tests / test (pull_request) Has been cancelled
ca46a6061e
Add validate_cycle_result() to loop_guard.py that runs before each cycle:
1. Age check — deletes cycle_result.json if older than 2× CYCLE_DURATION
2. Issue check — deletes cycle_result.json if referenced issue is closed
3. Graceful degradation — keeps file when Gitea API is unreachable

Also adds _load_cycle_result() (with markdown fence handling),
_is_issue_open() for single-issue lookups, and CYCLE_DURATION config.

Includes 16 unit tests covering all validation paths.

Fixes #661

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
kimi force-pushed kimi/issue-661 from ca46a6061e to cca979d30b 2026-03-21 03:01:43 +00:00 Compare
Timmy added 1 commit 2026-03-21 13:52:05 +00:00
Merge branch 'main' into kimi/issue-661
Some checks failed
Tests / lint (pull_request) Has been cancelled
Tests / test (pull_request) Has been cancelled
8141942b45
Timmy merged commit 9b57774282 into main 2026-03-21 13:53:12 +00:00
Timmy deleted branch kimi/issue-661 2026-03-21 13:53:12 +00:00
Sign in to join this conversation.
No Reviewers
No Label
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Rockachopa/Timmy-time-dashboard#666