Skip to content

Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.

fix(project-limit): settings and license hooks push only a changed state

review8b7a06c0a6a2
diff --git a/src/core/project-limit.test.ts b/src/core/project-limit.test.ts
index 1bf70ce93..59d61dc1f 100644
--- a/src/core/project-limit.test.ts
+++ b/src/core/project-limit.test.ts
@@ -785,6 +785,22 @@ describe('project limit: wiring', () => {
expect(notified.at(-1)).toEqual(handle.state())
})
+ // What main's settings and license hooks call: either fires on every save of settings.json, so it
+ // sends only what the windows have not seen.
+ it('pushIfChanged() sends the state only when it differs from the last one sent', async () => {
+ const { handle } = await boot()
+ const n = notified.length
+ handle.pushIfChanged()
+ expect(notified.length).toBe(n)
+
+ writeLicense({ token: entitlementToken(3600) })
+ handle.pushIfChanged()
+ expect(notified.length).toBe(n + 1)
+ expect(notified.at(-1)).toMatchObject({ pro: true })
+ handle.pushIfChanged()
+ expect(notified.length).toBe(n + 1)
+ })
+
// Nothing but time changes these; the 6 h tick must push them (an app open for days, or one
// that never hears from api.nodeterm.dev, would otherwise stay dormant until a restart).
it('pushes the deadline crossing on the 6 h tick', async () => {
diff --git a/src/core/project-limit.ts b/src/core/project-limit.ts
index 50562f7d6..6339131a8 100644
--- a/src/core/project-limit.ts
+++ b/src/core/project-limit.ts
@@ -31,7 +31,8 @@
* machine check applies. A successful claim also caches the hash it sent, if it came from the OS.
*
* CLAIMS are lazy and never reject: one request shared by concurrent callers, an 8 s timeout over
- * the whole request including the body, and every failure folded into a `ClaimError`. While the
+ * the whole request including the body (the machine read before it is bounded by machine-id.ts's own
+ * per-attempt timeout), and every failure folded into a `ClaimError`. While the
* limit is off a claim asks nobody (no request, no machine read), whoever calls it.
*
* `projectLimit:changed` goes to THIS machine's windows only, through the shell's `notify`. Never
@@ -109,8 +110,11 @@ export interface ProjectLimitHandle {
state(): ProjectLimitState
/** Ask the server for this device's allowance. Never rejects. */
claim(): Promise<ClaimResult>
- /** Re-send the state (a license or settings change can alter it with nothing here noticing). */
+ /** Re-send the state, unconditionally. */
refresh(): void
+ /** Send the state only if it differs from the last one sent — what a license or settings change
+ * calls (either can alter it with nothing here noticing, and settings change on every save). */
+ pushIfChanged(): void
}
const isInt = (v: unknown): v is number => Number.isSafeInteger(v)
@@ -222,7 +226,8 @@ function state(): ProjectLimitState {
return compute()
}
-/** Send the state to this machine's windows, unconditionally (`refresh()`). */
+/** Send the state to this machine's windows, unconditionally (`refresh()`; also the boot-time
+ * machine read landing, which can change what the windows were told at init). */
function notify(): void {
const s = state()
lastSent = JSON.stringify(s)
@@ -372,7 +377,7 @@ export function initProjectLimit(d: ProjectLimitDeps): ProjectLimitHandle {
osMachine = null
claimInFlight = null
lastSent = JSON.stringify(compute())
- const handle: ProjectLimitHandle = { state, claim, refresh: notify }
+ const handle: ProjectLimitHandle = { state, claim, refresh: notify, pushIfChanged }
platform().handle(IPC.projectLimitState, () => handle.state())
platform().handle(IPC.projectLimitClaim, () => handle.claim())
onCheckAnswer(onAnswer)
diff --git a/src/main/index.ts b/src/main/index.ts
index 0f8618ad8..99e3b49a2 100644
--- a/src/main/index.ts
+++ b/src/main/index.ts
@@ -4895,7 +4895,7 @@ app.whenReady().then(async () => {
notify: (s) => sendToMain(IPC.projectLimitChanged, s),
ready: bootWorkspaceLoad
})
- settingsStore.onChange(() => projectLimit.refresh())
+ settingsStore.onChange(() => projectLimit.pushIfChanged())
// DO_NOT_TRACK consent for license and allowance calls (spec §7.4): Settings → Privacy, read on
// every gated call so revoking it applies at once. Installed BEFORE initLicense, whose launch
// refresh runs immediately. Only `licenseNetworkGate()` callers read it — never telemetry or the
@@ -4907,7 +4907,7 @@ app.whenReady().then(async () => {
// It can also change Pro for the project limit, which nothing else would tell the renderer.
initLicense(() => {
watchLinks?.onEntitlementChanged()
- projectLimit.refresh()
+ projectLimit.pushIfChanged()
})
// Lazy getter: sshProjectManager is created just below, so a remote account op (which only runs
// after the user has connected an SSH project) always sees the live manager.
diff --git a/src/main/project-limit-wiring.test.ts b/src/main/project-limit-wiring.test.ts
index e3013da82..8eabc088b 100644
--- a/src/main/project-limit-wiring.test.ts
+++ b/src/main/project-limit-wiring.test.ts
@@ -41,9 +41,13 @@ describe('project-limit wiring (source)', () => {
expect(main.match(/const bootWorkspaceLoad = /g)).toHaveLength(1)
})
- it('a license change and a settings change both re-send it', () => {
- expect(main).toMatch(/initLicense\(\(\) => \{\s*watchLinks\?\.onEntitlementChanged\(\)\s*projectLimit\.refresh\(\)\s*\}\)/)
- expect(main).toMatch(/settingsStore\.onChange\(\(\) => projectLimit\.refresh\(\)\)/)
+ it('a license change and a settings change both push it, only when it changed', () => {
+ // pushIfChanged, not refresh: settings change on every save, and the windows need only news.
+ expect(main).toMatch(
+ /initLicense\(\(\) => \{\s*watchLinks\?\.onEntitlementChanged\(\)\s*projectLimit\.pushIfChanged\(\)\s*\}\)/
+ )
+ expect(main).toMatch(/settingsStore\.onChange\(\(\) => projectLimit\.pushIfChanged\(\)\)/)
+ expect(main).not.toMatch(/projectLimit\.refresh\(\)/)
})
it('DO_NOT_TRACK consent is the Privacy setting, read live, and installed before the first license call', () => {