codehost 0.23.1 → 0.23.2

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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## [0.23.2](https://github.com/snomiao/codehost/compare/v0.23.1...v0.23.2) (2026-06-16)
2
+
3
+
4
+ ### Performance Improvements
5
+
6
+ * **cli:** throttle meta pushes to the signaling room ([654ee10](https://github.com/snomiao/codehost/commit/654ee1088bc88f95ca6b57545fa477ccb77b994f))
7
+
1
8
  ## [0.23.1](https://github.com/snomiao/codehost/compare/v0.23.0...v0.23.1) (2026-06-16)
2
9
 
3
10
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codehost",
3
- "version": "0.23.1",
3
+ "version": "0.23.2",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",
@@ -56,6 +56,13 @@ export interface RunServerOptions {
56
56
  /** How often a daemon re-enumerates its workspaces (manual clones show up). */
57
57
  const META_REFRESH_MS = 60_000;
58
58
 
59
+ /** Floor between meta pushes to the room. `serve` re-evaluates meta every ~3s so
60
+ * live agent titles stay fresh, but each push is a billable DO request that
61
+ * fans out to every peer — so coalesce bursts (a churning agent title) into at
62
+ * most one push per this interval. The first change in a quiet period goes out
63
+ * immediately; rapid follow-ups ride a single trailing push. */
64
+ const MIN_META_PUSH_MS = 15_000;
65
+
59
66
  /**
60
67
  * Foreground server loop shared by `serve`, `dev`, and `expose`: register in the
61
68
  * signaling room with the given meta and bridge each client's data channel to a
@@ -113,15 +120,36 @@ export async function runServer(opts: RunServerOptions): Promise<never> {
113
120
  onSignal: (from, data) => rtc.handleSignal(from, data),
114
121
  });
115
122
 
116
- // Re-advertise when the workspace set changes (provision, manual clone).
117
- let lastMeta = JSON.stringify(opts.meta);
123
+ // Re-advertise when the workspace set changes (provision, manual clone),
124
+ // throttled so a burst of changes is at most one room push per MIN_META_PUSH_MS.
125
+ let sentMeta = JSON.stringify(opts.meta); // last meta the room actually has
126
+ let lastPushAt = 0; // ms of the last updateMeta send (0 = none since connect)
127
+ let pushTimer: ReturnType<typeof setTimeout> | null = null;
128
+ const sendMeta = (meta: PeerMeta) => {
129
+ const s = JSON.stringify(meta);
130
+ if (s === sentMeta) return; // nothing new since the last push
131
+ sentMeta = s;
132
+ lastPushAt = Date.now();
133
+ client.updateMeta(meta);
134
+ };
118
135
  const refreshMeta = () => {
119
136
  if (!opts.refreshMeta) return;
120
137
  const meta = opts.refreshMeta();
121
- const s = JSON.stringify(meta);
122
- if (s === lastMeta) return;
123
- lastMeta = s;
124
- client.updateMeta(meta);
138
+ if (JSON.stringify(meta) === sentMeta) return; // unchanged — nothing to do
139
+ const wait = MIN_META_PUSH_MS - (Date.now() - lastPushAt);
140
+ if (wait <= 0) {
141
+ // Cooldown elapsed: push the leading change now, dropping any pending one.
142
+ if (pushTimer) clearTimeout(pushTimer);
143
+ pushTimer = null;
144
+ sendMeta(meta);
145
+ } else if (!pushTimer) {
146
+ // Within the cooldown: schedule one trailing push that re-reads the
147
+ // freshest meta when it fires, so coalesced changes all ship at once.
148
+ pushTimer = setTimeout(() => {
149
+ pushTimer = null;
150
+ sendMeta(opts.refreshMeta!());
151
+ }, wait);
152
+ }
125
153
  };
126
154
  const provision: ProvisionDeps | undefined = opts.provision
127
155
  ? { ...opts.provision, onProvisioned: refreshMeta }