@volter/teams 0.1.13 → 0.1.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/server/core.mjs +15 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@volter/teams",
3
- "version": "0.1.13",
3
+ "version": "0.1.14",
4
4
  "type": "module",
5
5
  "description": "Volter Teams, the neutral team plane: machine identity and daemon core, the local door and server link, admission from machine grants, product doors, and the Teams server's neutral routes (company RFC 0008).",
6
6
  "license": "MIT",
package/server/core.mjs CHANGED
@@ -66,4 +66,18 @@ export async function maintain(api){const now=api.clock.nowMs();await api.store.
66
66
  {sql:'INSERT OR IGNORE INTO capture_expiries(team_id,source_id,id,expired_at) SELECT team_id,source_id,id,? FROM uploads WHERE committed=0 AND created_at+86400000<=?',params:[now,now]},
67
67
  {sql:'DELETE FROM uploads WHERE committed=0 AND created_at+86400000<=?',params:[now]},
68
68
  {sql:'DELETE FROM journal WHERE created_at+86400000<=?',params:[now]},
69
- ]);}
69
+ ]);
70
+ // Every capture writes its session a new version with a full copy of its messages, so versions pile up (hundreds
71
+ // per session) until listing them outgrew a Worker's memory. Kept: each session's current version, the newest
72
+ // version from each of its sources (the next capture and a correlation read that one), and every version an
73
+ // unexpired list, search or history cursor names. The rest go, a bounded batch per run.
74
+ const stale=await api.store.query(`SELECT v.team_id,v.session_id,v.revision FROM session_versions v JOIN sessions s ON s.team_id=v.team_id AND s.id=v.session_id
75
+ WHERE v.revision<>s.revision
76
+ AND EXISTS (SELECT 1 FROM session_versions n WHERE n.team_id=v.team_id AND n.session_id=v.session_id AND n.revision>v.revision AND json_extract(n.source_projection_json,'$.source_id') IS json_extract(v.source_projection_json,'$.source_id'))
77
+ AND NOT EXISTS (SELECT 1 FROM cursors c, json_each(c.snapshot_json) j WHERE c.team_id=v.team_id AND c.kind IN ('list','search') AND c.expires_at>? AND json_extract(j.value,'$[0]')=v.session_id AND json_extract(j.value,'$[1]')=v.revision)
78
+ AND NOT EXISTS (SELECT 1 FROM cursors c WHERE c.team_id=v.team_id AND c.kind='history' AND c.expires_at>? AND json_extract(c.snapshot_json,'$.session_id')=v.session_id AND json_extract(c.snapshot_json,'$.revision')=v.revision)
79
+ LIMIT ${VERSION_PRUNE_BATCH}`,[now,now]);
80
+ if(stale.length)await api.store.transaction(stale.flatMap(({team_id,session_id,revision})=>['messages','session_artifacts','session_versions'].map(table=>({sql:`DELETE FROM ${table} WHERE team_id=? AND session_id=? AND revision=?`,params:[team_id,session_id,revision]}))));
81
+ return {pruned_versions:stale.length};}
82
+ /** Session versions `maintain` removes per run: small enough for one Durable Object alarm, drains a backlog in hours. */
83
+ const VERSION_PRUNE_BATCH=50;