aboutsummaryrefslogtreecommitdiffstats
path: root/packages/meshbay-node/src/meshbay_node/daemon.py
diff options
context:
space:
mode:
authorChristophe Besson <cbesson@gmail.com>2026-09-15 16:11:26 +0200
committerChristophe Besson <cbesson@gmail.com>2026-09-15 16:11:26 +0200
commitfce0942cb7d81dbdbae70e50b0164fead7e8bc49 (patch)
tree9f694bf800682c63127da53cf842e0da7b117340 /packages/meshbay-node/src/meshbay_node/daemon.py
parent99f95dadee1a3c892bb0bc87e3564f71d07c88e0 (diff)
downloadmeshbay-fce0942cb7d81dbdbae70e50b0164fead7e8bc49.tar.gz
fix(node): purge the audit log past its retention
AuditStore.cleanup was never called, so audit.db kept every entry. The daemon now runs it at start and daily. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XuNrwLf5EFWCMHzfoEvnpm
Diffstat (limited to 'packages/meshbay-node/src/meshbay_node/daemon.py')
-rw-r--r--packages/meshbay-node/src/meshbay_node/daemon.py22
1 files changed, 21 insertions, 1 deletions
diff --git a/packages/meshbay-node/src/meshbay_node/daemon.py b/packages/meshbay-node/src/meshbay_node/daemon.py
index 7646c5d..666a5cc 100644
--- a/packages/meshbay-node/src/meshbay_node/daemon.py
+++ b/packages/meshbay-node/src/meshbay_node/daemon.py
@@ -41,7 +41,7 @@ from meshbay_common.background import spawn
from meshbay_common.paths import fold
from meshbay_common import MNP_VERSION
from meshbay_common.protocol import MNP
-from meshbay_node.audit import AuditStore
+from meshbay_node.audit import RETENTION_DAYS as AUDIT_RETENTION_DAYS, AuditStore
from meshbay_node.bundle_store import BundleStore
from meshbay_node.chat.store import ChatStore
from meshbay_node.config import Config, DEFAULT_CONFIG_PATH, load_config, write_example_config
@@ -469,6 +469,7 @@ class NodeDaemon:
self._audit_store = AuditStore(db_path=audit_db)
await self._audit_store.open()
log.info("Audit store opened: %s", audit_db)
+ self._tasks.append(asyncio.create_task(self._purge_audit_log()))
# 6b. Media cache (Videos app — TMDB metadata + thumbnails).
# Node-wide like audit.db, not per-group: a thumbnail is the same
@@ -1128,6 +1129,25 @@ class NodeDaemon:
log.warning("Reaping partial uploads failed: %s", exc)
await asyncio.sleep(interval)
+ async def _purge_audit_log(self, interval: float = 86400.0) -> None:
+ """
+ Delete audit entries past the retention period, at start then daily.
+
+ `AuditStore.cleanup` leaves scheduling to its caller; until this loop
+ nobody called it and a node kept every entry for ever. `interval` is a
+ parameter so a test can drive this without waiting a day.
+ """
+ while True:
+ try:
+ if self._audit_store:
+ deleted = await self._audit_store.cleanup()
+ if deleted:
+ log.info("Purged %d audit entries older than %d days",
+ deleted, AUDIT_RETENTION_DAYS)
+ except Exception as exc: # never let the janitor kill the node
+ log.warning("Purging the audit log failed: %s", exc)
+ await asyncio.sleep(interval)
+
def _reap_once(self, now: float | None = None) -> int:
"""One pass over every group. Returns how many files were deleted."""
groups = (self._webrtc._ctx.get("groups") or {}) if self._webrtc else {}