feat(server): add conversation mtime tracking for real-time updates
Add conversation_mtime_ns field to session state that tracks the actual
modification time of conversation files. This enables more responsive
dashboard updates by detecting changes that occur between hook events
(e.g., during streaming tool execution).
Changes:
- state.py: Add _get_conversation_mtime() to stat conversation files
and include mtime_ns in session payloads when available
- conversation.py: Add stable message IDs (claude-{session}-{n} format)
for React key stability and message deduplication
- control.py: Fix FIFO eviction for dismissed_codex_ids - set.pop()
removes arbitrary element, now uses dict with insertion-order iteration
- context.py: Update dismissed_codex_ids type from set to dict
The mtime approach complements existing last_event_at tracking:
- last_event_at: Changes on hook events (session boundaries)
- conversation_mtime_ns: Changes on every file write (real-time)
Dashboard can now detect mid-session conversation updates without
waiting for the next hook event.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -16,10 +16,11 @@ class SessionControlMixin:
|
||||
safe_id = os.path.basename(session_id)
|
||||
session_file = SESSIONS_DIR / f"{safe_id}.json"
|
||||
# Track dismissed Codex sessions to prevent re-discovery
|
||||
# Evict oldest entries if set is full (prevents unbounded growth)
|
||||
# Evict oldest entries via FIFO (dict maintains insertion order in Python 3.7+)
|
||||
while len(_dismissed_codex_ids) >= _DISMISSED_MAX:
|
||||
_dismissed_codex_ids.pop()
|
||||
_dismissed_codex_ids.add(safe_id)
|
||||
oldest_key = next(iter(_dismissed_codex_ids))
|
||||
del _dismissed_codex_ids[oldest_key]
|
||||
_dismissed_codex_ids[safe_id] = True
|
||||
session_file.unlink(missing_ok=True)
|
||||
self._send_json(200, {"ok": True})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user