@volter/teams 0.1.43 → 0.1.45

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 +6 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@volter/teams",
3
- "version": "0.1.43",
3
+ "version": "0.1.45",
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
@@ -58,6 +58,10 @@ export async function bootstrapServer(api,{initTeam,bootstrap}){
58
58
 
59
59
  /** Expire cursors, idempotency records, staged captures and uploads, and old journal rows. */
60
60
  export async function maintain(api){const now=api.clock.nowMs();
61
+ // Replay records expire after a day; keeping them forever can fill the object and stop heartbeats.
62
+ // Delete them before any retention step that may update a surviving version.
63
+ const expired=await api.store.query('SELECT rowid FROM idempotency WHERE expires_at<=? LIMIT 1000',[now]);
64
+ if(expired.length)await api.store.transaction([{sql:'DELETE FROM idempotency WHERE rowid IN (SELECT rowid FROM idempotency WHERE expires_at<=? LIMIT 1000)',params:[now]}]);
61
65
  // Deletes go first, each in a transaction of its own: on a full database an insert fails, and a run that begins
62
66
  // with one never reaches the deletes that would make room.
63
67
  // A committed capture's parts are its messages in transit; once committed, the session's version holds them, so
@@ -92,8 +96,8 @@ export async function maintain(api){const now=api.clock.nowMs();
92
96
  {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]},
93
97
  {sql:'DELETE FROM uploads WHERE committed=0 AND created_at+86400000<=?',params:[now]},
94
98
  ]).catch(()=>{});
95
- const result={pruned_versions:stale.length,pruned_parts:parts.length,backlog:stale.length>=VERSION_PRUNE_BATCH||parts.length>=PART_PRUNE_BATCH};
96
- if(result.pruned_versions||result.pruned_parts)console.log(`maintain: pruned ${result.pruned_parts} parts, ${result.pruned_versions} versions${result.backlog?' (backlog)':''}`);
99
+ const result={pruned_versions:stale.length,pruned_parts:parts.length,pruned_idempotency:expired.length,backlog:expired.length>=1000||stale.length>=VERSION_PRUNE_BATCH||parts.length>=PART_PRUNE_BATCH};
100
+ if(result.pruned_versions||result.pruned_parts||result.pruned_idempotency)console.log(`maintain: pruned ${result.pruned_idempotency} expired replay records, ${result.pruned_parts} parts, ${result.pruned_versions} versions${result.backlog?' (backlog)':''}`);
97
101
  return result;}
98
102
  /** Session versions `maintain` removes per run: small enough for one Durable Object alarm; a backlog runs again in seconds. */
99
103
  const VERSION_PRUNE_BATCH=20;