Touch runtime.json updated_at on real routine fires - #688
Open
akeslo wants to merge 1 commit into
Open
Conversation
An always-on session cycling background routines via the Monitor mechanism never updates runtime.json's updated_at unless a session open/close/heartbeat transition happens — routine fires only append to routine-metrics.jsonl. evaluate-session.ts's stale-session nudge (and the dashboard's stale-session detector downstream) reads that staleness as "session may be hung," even when the session is doing exactly what it's supposed to: standing by between scheduled routine cycles. Have logRoutineEvent bump runtime.json's updated_at whenever a routine actually fires or starts (not on skipped-paused/skipped-waiting, which aren't real activity). Fail-soft: a missing/corrupt runtime.json must not block the routine event itself.
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Updates routine event logging to also “touch” the session runtime state when real routine activity occurs, preventing active sessions from being considered stale.
Changes:
- Add
localISOStampimport and use it to updateruntime.json’supdated_at. - After successfully appending a routine event, update
runtime.jsonforfired/startedevents in a fail-soft manner.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| return appendJsonlLine( | ||
| const err = appendJsonlLine( | ||
| metrics, | ||
| JSON.stringify({ ts: utcISOStamp(), routine_id: id, event, delivery }), |
| try { | ||
| const runtimePath = path.join(root, '.claude-code-hermit', 'state', 'runtime.json'); | ||
| const runtime = JSON.parse(fs.readFileSync(runtimePath, 'utf-8')); | ||
| runtime.updated_at = localISOStamp(); |
Comment on lines
+81
to
+86
| const runtimePath = path.join(root, '.claude-code-hermit', 'state', 'runtime.json'); | ||
| const runtime = JSON.parse(fs.readFileSync(runtimePath, 'utf-8')); | ||
| runtime.updated_at = localISOStamp(); | ||
| const tmp = `${runtimePath}.${process.pid}.tmp`; | ||
| fs.writeFileSync(tmp, JSON.stringify(runtime, null, 2) + '\n', 'utf-8'); | ||
| fs.renameSync(tmp, runtimePath); |
Comment on lines
+84
to
+87
| const tmp = `${runtimePath}.${process.pid}.tmp`; | ||
| fs.writeFileSync(tmp, JSON.stringify(runtime, null, 2) + '\n', 'utf-8'); | ||
| fs.renameSync(tmp, runtimePath); | ||
| } catch { /* fail-soft — runtime.json missing/corrupt must not block the routine */ } |
Owner
|
@akeslo did you encounter this issue on the latest 1.2.36 version? this should already be fixed with these commtis:
Before those, sessions could get stuck To update to the latest version run the skill: /claude-code-hermit:evolve |
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.
Problem
An always-on session that's cycling background routines via the Monitor mechanism (routine-monitor.sh polling
due.ts) never touchesruntime.json'supdated_atunless an explicit session open/close/heartbeat transition happens. Routine fires only append tostate/routine-metrics.jsonlvialogRoutineEvent.evaluate-session.ts's stale-session nudge (and any downstream stale-session detector) reads that gap as "no recent activity," even though the session is doing exactly what it's designed to do: standing by between scheduled routine cycles without a fresh Progress Log line.Fix
logRoutineEventinscripts/lib/routines/event.tsnow bumpsruntime.json'supdated_atwhenever a routine actually fires or starts (event === 'fired' || event === 'started'). Skipped events (skipped-paused,skipped-waiting) are excluded since they aren't real activity. The write is fail-soft — a missing or corruptruntime.jsondoesn't block the routine event itself.Testing
bunx tsc --noEmitclean from repo root.bun test tests/evaluate-session-stale.test.ts— 7/7 pass, no changes needed to existing regression coverage.bun test tests/— 3398 pass, 8 pre-existing failures all unrelated (macOS/tmpvs/private/tmprealpath mismatches incc-compat-hermitdir.test.ts/hermit-run.test.ts), confirmed untouched by this change.