Why the shutdown could hang: the event heap was never stopped, and its
thread called every handler's dispatchEvent() while holding the handler
list mutex. ~mojoKernel deletes the node / module factories, filters,
media helper ... - all of them event handlers - while the heap kept
calling into them (half-destroyed objects, destroyed mutexes); the
deleting thread then waited forever in removeHandler() for the mutex
the dispatch thread held. A dispatchEvent() that created or deleted a
handler deadlocked the dispatch thread itself (non-recursive mutex).
basicEventHeap:
- Handlers are called without the list locked (snapshot + "still
registered" check per handler); removeHandler() waits until the
handler is no longer being called (5 s cap, logged), except when
called from that very dispatchEvent().
- New pause() / resume() / flush() / clearQueue() and
destroyInstance() (stops the thread; leaves it alone if a handler is
stuck instead of hanging); existingInstance(); getInstance() is
thread-safe.
basicEventHandler:
- detachEvents(): stop delivery first thing in a destructor (the base
destructor runs only after the derived members are gone);
basicEventHandler(false) + attachEvents(): register at the end of the
constructor (registration in the base constructor lets the heap call
into an object whose members are not built yet). Defaults unchanged.
- Removal never creates a new heap (late destructors after exit).
la_mojo:
- ~mojoKernel: deliver queued events (2 s), pause the heap before
deleting the components, drop what was queued during the teardown;
the next kernel (restart) resumes it.
- mojoBackend: destroyInstance() before the log is deleted at exit.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
The report engine now keeps a separate SQLite database for every local
hour inside the day folder:
data/reports/YYYY/MM/DD/report_HH.db (REPORT_DB_NAME_FMT "report_%02d.db")
Pictures and videos stay in the day folder; the stat.db day records are
unchanged.
- sqliteDBC::openHourReport(): opens/creates report_HH.db of the given day
and hour (replaces openDayReport); switchReportToCurrentHour() (renamed
from switchReportToCurrentDay) switches when the local day or hour
changes. connect() opens the current hour's file at startup.
- mojoKernel::handleReportPeriodChange() (was handleDayChange): runs the
same close-then-switch sequence every local hour: an open session that
started in the previous hour is closed in the old file (waiting at most
REPORT_SWITCH_MAX_VIDEO_WAIT for a recording with events), then the
report switches to the new hour; the next event opens a new session.
Each hourly file therefore contains complete sessions.
- getLocalHour() helper in basicFunctionality.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
Before, the report (data/reports/YYYY/MM/DD/report.db, plus pictures and
videos stored next to it) only moved to a new day inside
updateStats(SESSION_START) - and that branch never ran, because
updateStats() skipped every call with evt=false/video=false, which is how
all session status changes are reported. So the report only changed day
when the process restarted; everything after midnight went into the
previous day's report.
- mojoKernel::handleDayChange() (every second from validateReports):
at local midnight an open session that started on the previous day is
closed (END event goes into the old report). If a video segment with
events is still recording, wait for it at most DAY_CHANGE_MAX_VIDEO_WAIT
(90 s) so the video is stored next to its events. After the END event is
written, the report is switched to the new day. The next event starts a
new session in the new day's report.
- sqliteDBC::switchReportToCurrentDay() / openDayReport(): opens (creates)
the current local day's report directory and database, retried until it
succeeds. Report state is protected by a recursive mutex because the
switch runs on the kernel thread while events are written on the event
thread.
- updateStats(): no longer drops SESSION_START/END/DROP calls, so the
session counters in stat.db are updated and SESSION_START also switches
the report if needed.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16