Skip to content

Linger is An Open-Source Personal Agent That Runs Fully on Your PC. We aim to break Big Tech’s grip on AI by bringing powerful local AI to everyday computers through efficient model–harness co-design, so everyone can run their own.

fix(computer): run the UI bridge setup outside the guest CPU budget

jeffreyc251661f6524
diff --git a/apps/computer/local-daemon/internal/uiruntime/runtime.mjs b/apps/computer/local-daemon/internal/uiruntime/runtime.mjs
index b8c056bf..a131f1b8 100644
--- a/apps/computer/local-daemon/internal/uiruntime/runtime.mjs
+++ b/apps/computer/local-daemon/internal/uiruntime/runtime.mjs
@@ -57,8 +57,10 @@ function fail(message) {
process.stdin.destroy();
}
}
-function evaluate(source) {
- deadline = performance.now() + limits.pumpMs;
+// The CPU budget bounds guest work. The trusted bridge setup runs unbounded,
+// so a slow host cannot fail the runtime before it is ready.
+function evaluate(source, budgetMs = limits.pumpMs) {
+ deadline = performance.now() + budgetMs;
try {
// Only bytecode produced by our own compiler enters the guest.
using value = guest.evalBytecode(
@@ -73,7 +75,8 @@ function evaluate(source) {
}
// Functions, Promises and errors below originate inside the context. Go treats
// every bridge request as untrusted and applies its own limits and validation.
-evaluate(`(() => {
+evaluate(
+ `(() => {
'use strict';
const stringify = JSON.stringify, parse = JSON.parse;
const pending = new Map();
@@ -250,7 +253,9 @@ evaluate(`(() => {
return '';
}
}) });
-})()`);
+})()`,
+ Infinity,
+);
function pump() {
if (dead || !active || waiting) return;
if (process.memoryUsage().rss > limits.rssBytes)
diff --git a/apps/computer/local-daemon/internal/uiruntime/runtime_test.go b/apps/computer/local-daemon/internal/uiruntime/runtime_test.go
index 3d4aff2f..760cdb7b 100644
--- a/apps/computer/local-daemon/internal/uiruntime/runtime_test.go
+++ b/apps/computer/local-daemon/internal/uiruntime/runtime_test.go
@@ -550,3 +550,10 @@ func TestInvalidatedIdleChildIsReplaced(t *testing.T) {
t.Fatalf("second=%+v", second)
}
}
+func TestBridgeSetupIgnoresGuestCPUBudget(t *testing.T) {
+ // The smallest budget is shorter than the trusted bridge setup.
+ r := nodeRuntime(t, noCalls(t), Limits{PumpTimeout: time.Millisecond})
+ if got := execute(t, r, `return 1;`); string(got.Value) != "1" {
+ t.Fatalf("result=%+v", got)
+ }
+}