Browser-based graphical shell and control plane for a Linux server you own — real terminal, file manager, live metrics and BYOK AI in one mobile-first workspace. Next.js 16 · React 19 · node-pty · Tailwind v4 · shadcn/ui. Public alpha, self-hosted.
TypeScript browser-shellcontrol-planefile-managerhomelabmobile-firstnextjsptyreactself-hostedserver-managementshadcn-uisysadmintailwindcssterminaltypescriptvpsweb-desktopweb-terminal
fix(agent): preserve overlapping standby wakeups
Abdurrahman Fakhrulf9977bac6943
diff --git a/app/api/models/route.test.ts b/app/api/models/route.test.tsindex b88b1fbe..ab688648 100644--- a/app/api/models/route.test.ts+++ b/app/api/models/route.test.ts@@ -1,5 +1,6 @@import { beforeEach, describe, expect, it, vi } from "vitest";import { NextRequest } from "next/server";+import { requireSession } from "@/lib/auth/require-session";const listModels = vi.fn();const readOAuthBundle = vi.fn();@@ -20,6 +21,7 @@ vi.mock("@/lib/ai/oauth/codex", () => ({describe("/api/models dynamic pricing and provider mapping", () => {beforeEach(() => {+ vi.mocked(requireSession).mockReset().mockResolvedValue(true);listModels.mockReset().mockResolvedValue([{ref: "zhipuai/glm-free",@@ -71,4 +73,18 @@ describe("/api/models dynamic pricing and provider mapping", () => {const body = await res.json();expect(body.models.map((m: { id: string }) => m.id)).toEqual(["glm-free"]);});++ it.each(["openai-codex", "glm", ""])("requires an owner before any provider access (%s)", async (provider) => {+ vi.mocked(requireSession).mockResolvedValue(false);+ const { GET } = await import("./route");+ const res = await GET(new NextRequest(`http://localhost/api/models?provider=${provider}&free=1`));+ expect(res.status).toBe(401);+ expect(await res.json()).toEqual({ error: "Unauthorized" });+ expect(requireSession).toHaveBeenCalledWith("owner");+ expect(listModels).not.toHaveBeenCalled();+ expect(readOAuthBundle).not.toHaveBeenCalled();+ expect(writeOAuthBundle).not.toHaveBeenCalled();+ expect(ensureFreshCodex).not.toHaveBeenCalled();+ expect(codexModels).not.toHaveBeenCalled();+ });});diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.mdindex 4c321bd2..23f5673d 100644--- a/docs/CHANGELOG.md+++ b/docs/CHANGELOG.md@@ -4,38 +4,25 @@Newest first. `docs/PROGRESS.md` is the source of truth for *why* a change was made;this is the *what*, and it is what Settings → Account → About shows as “What's new”.-## 2026-10-05+## 2026-10-06**Added**-- `shell` import reviewed macOS chrome and security candidate-- `tenancy` compose scoped durable memory runtime-- `tenancy` pin credential generations across OAuth lifecycle-- `tenancy` add atomic durable registry and memory adapter-- `tenancy` add disabled identity and scoped read seam+- integrate verified MSO shell and tenant changes**Fixed**-- `ci` retain executable verification entrypoint-- `managed-apps` refresh install state on return--**Tests**+- `agent` preserve overlapping standby wakeups-- `shell` wait for settled desktop geometry before switching-- `tenancy` keep persistent route mock fully parseable-- `ci` cover both shell journeys in build isolation fixture-- `tenancy` verify claim corruption and document rollout gates+## 2026-10-05**Chores**- `deps-dev` bump simple-icons-- `lint` ignore linked worktrees**CI**-- preserve strict auditing before the native dependency check-- verify both shell candidates in isolated builds-- gate combined macOS and iOS release journeys+- preserve strict audit and require native audit and shell journeys## 2026-10-04@@ -45,18 +32,9 @@ this is the *what*, and it is what Settings → Account → About shows as “Wh**Fixed**-- `shell` retain focus contrast with screen light enabled-- `shell` preserve focus contrast within CSS budget-- `shell` reuse accessible focus token within CSS budget-- `shell` make iOS lock privacy-safe and keyboard accessible- `appearance` version immutable default wallpaper URLs-- `shell` match complete lock weather locale subtags- `appearance` refine default 27 desktop wallpapers- `security` clear unfixed dependency and Semgrep audit gates-- `shell` use Semibold for the iOS lock time-- `shell` shrink iOS widgets and paint glass fills-- `shell` tighten the lock date and lighten the time-- `shell` build the iOS lock screen on the shell wallpaper**Chores**@@ -64,19 +42,6 @@ this is the *what*, and it is what Settings → Account → About shows as “Wh- `deps` bump the production-minor-patch group with 5 updates- `deps-dev` bump the test-toolchain group with 2 updates-## 2026-10-03--**Added**--- `shell` restyle iPhone and iPad tab bars as iOS 27 glass capsules--**Fixed**--- `shell` correct lock date tracking and cover the home-- `shell` match iOS Large type styles and touch sizes-- `shell` place each widget size on its own home screen-- `shell` match the iOS 27 home screen frames-## 2026-10-02**Fixed**diff --git a/docs/PROGRESS.md b/docs/PROGRESS.mdindex 4ba578e7..546c49dd 100644--- a/docs/PROGRESS.md+++ b/docs/PROGRESS.md@@ -1,3 +1,9 @@+## 2026-10-06: Preserve overlapping standby wakeups++The PR integration exposed a dropped-wakeup race in local-agent standby: a drain requested while another pass was reading an empty mailbox returned immediately, so a newly invalid workflow or arriving authorized message could remain unprocessed. Concurrent drains now share one completion promise and request a fresh validated pass. Cleanup happens inside the runner's own finalization step, without a microtask window that could discard a late join. Per-pass bounds, sequential message execution, claim checks and fatal blocking remain intact.++Three deferred-promise regressions reproduce the empty-snapshot and finalization boundaries without timer delays; each failed the relevant earlier implementation. The existing stale-workflow and sequential execution tests remain unchanged. Models-catalog tests also prove that denied owner authorization returns 401 before either ordinary catalog or OAuth-account access, for Codex, regular and empty provider selectors. Focused checks and full local coverage passed 4,041 tests across 673 files; final publication checks and the separately identified dependency advisory remain pending.+## 2026-10-05: Reconcile reviewed shell and tenant candidatesCI keeps the strict dependency-audit wrapper, including its timeout, malformed-report checks and redacted diagnostics, and adds the native Bun high/critical audit as a separate required step. Both run after removal of the vulnerable dependency chain and its exception files. Workflow permissions remain read-only. A contract test prevents either audit from becoming optional.diff --git a/lib/agent/local-agent-standby-drain-race.test.ts b/lib/agent/local-agent-standby-drain-race.test.tsnew file mode 100644index 00000000..228d1aef--- /dev/null+++ b/lib/agent/local-agent-standby-drain-race.test.ts@@ -0,0 +1,133 @@+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";+import type { LocalAgentMessageView, LocalAgentStandbyRecord } from "./local-agent-types";++const mocks = vi.hoisted(() => ({+ active: true,+ record: undefined as LocalAgentStandbyRecord | undefined,+ inbox: vi.fn<() => Promise<LocalAgentMessageView[]>>(),+ recordRead: vi.fn<() => Promise<LocalAgentStandbyRecord | undefined>>(),+ execute: vi.fn(),+ block: vi.fn(),+}));+vi.mock("@/lib/workflow", () => ({+ activeWorkflowForActor: async () => mocks.active ? { id: "workflow" } : null,+}));+vi.mock("./session-store", () => ({ getAgentSession: async () => ({ id: "worker" }) }));+vi.mock("./local-agent-mailbox", () => ({ listLocalAgentExecutableInbox: mocks.inbox }));+vi.mock("./local-agent-standby-execution", () => ({ executeLocalAgentStandbyMessage: mocks.execute }));+vi.mock("./local-agent-events", () => ({+ localAgentConsumerConnected: () => false,+ subscribeLocalAgentStandbyMessages: () => () => undefined,+}));+vi.mock("./local-agent-standby-store", () => ({+ armLocalAgentStandbyRecord: async () => mocks.record,+ blockLocalAgentStandby: mocks.block,+ disarmLocalAgentStandbyForWorkflow: async () => [],+ disarmLocalAgentStandbyRecord: async () => undefined,+ getLocalAgentStandbyRecord: mocks.recordRead,+ listAllArmedLocalAgentStandbyRecords: async () => [],+}));++const standby = await import("./local-agent-standby");+const capabilities = { list: () => [], invoke: vi.fn(async () => ({ content: [] })) };++function deferred<T>() {+ let resolve!: (value: T) => void;+ const promise = new Promise<T>((done) => { resolve = done; });+ return { promise, resolve };+}++beforeEach(async () => {+ standby.resetLocalAgentStandbyRuntimeForTest();+ mocks.active = true;+ mocks.record = {+ principal: "owner", principalHash: "owner-hash", sessionId: "worker",+ workflowActor: "owner:worker", workflowId: "workflow", armed: true, state: "waiting",+ armedAt: "2026-10-01T00:00:00Z", updatedAt: "2026-10-01T00:00:00Z",+ };+ mocks.recordRead.mockReset().mockImplementation(async () => mocks.record);+ mocks.inbox.mockReset().mockResolvedValue([]);+ mocks.execute.mockReset().mockResolvedValue({ advanced: true, fatal: false });+ mocks.block.mockReset().mockImplementation(async () => {+ mocks.record = { ...mocks.record!, armed: false, state: "blocked" };+ });+ await standby.ensureLocalAgentStandbyRuntime(capabilities);+});+afterEach(() => standby.resetLocalAgentStandbyRuntimeForTest());++async function overlapEmptySnapshot() {+ const entered = deferred<void>();+ const snapshot = deferred<LocalAgentMessageView[]>();+ mocks.inbox.mockImplementationOnce(async () => {+ entered.resolve();+ return snapshot.promise;+ });+ const first = standby.drainStandbySession("owner", "worker");+ await entered.promise;+ return { first, snapshot };+}++async function joinHeldDrain() {+ const completion = standby.drainStandbySession("owner", "worker");+ // Complete the record-read and catch continuations while the inbox remains held.+ await Promise.resolve();+ await Promise.resolve();+ return { completion };+}++describe("standby overlapping drains", () => {+ it("revalidates a stale workflow after an overlapping wake during an empty snapshot", async () => {+ const { first, snapshot } = await overlapEmptySnapshot();+ mocks.active = false;+ const { completion } = await joinHeldDrain();+ snapshot.resolve([]);+ await Promise.all([first, completion]);+ expect(mocks.record).toMatchObject({ armed: false, state: "blocked" });+ expect(mocks.block).toHaveBeenCalledWith("owner", "worker", "standby workflow is no longer active");+ expect(mocks.execute).not.toHaveBeenCalled();+ });++ it("processes a message arriving during an empty snapshot exactly once", async () => {+ const { first, snapshot } = await overlapEmptySnapshot();+ const message: LocalAgentMessageView = {+ id: "message", senderSessionId: "sender", senderLabel: "sender",+ targetSessionId: "worker", targetLabel: "worker", kind: "task", intent: "request",+ requiresUserRelay: false, text: "authorized work", state: "queued",+ execution: { requested: true, authorized: true, state: "pending" },+ createdAt: "2026-10-01T00:00:00Z",+ };+ let pending = true;+ mocks.inbox.mockImplementation(async () => pending ? [message] : []);+ mocks.execute.mockImplementation(async () => {+ pending = false;+ return { advanced: true, fatal: false };+ });+ const { completion } = await joinHeldDrain();+ snapshot.resolve([]);+ await Promise.all([first, completion]);+ expect(mocks.execute).toHaveBeenCalledTimes(1);+ expect(mocks.execute).toHaveBeenCalledWith(expect.objectContaining({ message, capabilities }));+ expect(mocks.block).not.toHaveBeenCalled();+ });++ it("accepts a drain whose initial read completes during runner finalization", async () => {+ const entered = deferred<void>();+ const snapshot = deferred<LocalAgentMessageView[]>();+ mocks.inbox.mockImplementationOnce(() => {+ entered.resolve();+ return snapshot.promise;+ });+ const first = standby.drainStandbySession("owner", "worker");+ await entered.promise;+ const initialRead = deferred<LocalAgentStandbyRecord | undefined>();+ mocks.recordRead.mockImplementationOnce(() => initialRead.promise);+ mocks.active = false;+ const completion = standby.drainStandbySession("owner", "worker");+ // Queue the second lookup between the first runner's exit and a chained finally.+ initialRead.resolve(mocks.record);+ snapshot.resolve([]);+ await Promise.all([first, completion]);+ expect(mocks.record).toMatchObject({ armed: false, state: "blocked" });+ expect(mocks.execute).not.toHaveBeenCalled();+ });+});diff --git a/lib/agent/local-agent-standby.ts b/lib/agent/local-agent-standby.tsindex b46a6021..bc063f81 100644--- a/lib/agent/local-agent-standby.ts+++ b/lib/agent/local-agent-standby.ts@@ -20,7 +20,7 @@ import type { LocalAgentStandbyRecord } from "./local-agent-types";const runtimeId = `standby:${process.pid}:${randomUUID()}`;const subscriptions = new Map<string, () => void>();-const inFlightSessions = new Set<string>();+const inFlightSessions = new Map<string, { rerun: boolean; promise: Promise<void> }>();let runtimeCapabilities: CapabilityRuntime | null = null;let reconcilePromise: Promise<void> | null = null;@@ -63,39 +63,48 @@ export async function drainStandbySession(principal: string,sessionId: string,): Promise<void> {- if (!runtimeCapabilities) return;+ const capabilities = runtimeCapabilities;+ if (!capabilities) return;const initial = await getLocalAgentStandbyRecord(principal, sessionId).catch(() => null);if (!initial?.armed) return;const key = executionKey(initial);- if (inFlightSessions.has(key)) return;- inFlightSessions.add(key);- try {- for (let processed = 0; processed < 100; processed += 1) {- const record = await getLocalAgentStandbyRecord(principal, sessionId);- if (!record?.armed) break;- const validation = await validateRecord(record);- if (!validation.valid) {- await blockLocalAgentStandby(principal, sessionId, validation.reason);- removeSubscription(sessionId);- break;- }- const [next] = await listLocalAgentExecutableInbox(principal, sessionId, 1);- if (!next) break;- const result = await executeLocalAgentStandbyMessage({- record,- message: next,- capabilities: runtimeCapabilities,- runtimeId,- });- if (result.fatal) {- removeSubscription(sessionId);- break;- }- if (!result.advanced) break;- }- } finally {- inFlightSessions.delete(key);+ const active = inFlightSessions.get(key);+ if (active) {+ active.rerun = true;+ return active.promise;}+ const flight = { rerun: false, promise: Promise.resolve() };+ inFlightSessions.set(key, flight);+ flight.promise = (async () => {+ try {+ do {+ flight.rerun = false;+ for (let processed = 0; processed < 100; processed += 1) {+ const record = await getLocalAgentStandbyRecord(principal, sessionId);+ if (!record?.armed) break;+ const validation = await validateRecord(record);+ if (!validation.valid) {+ await blockLocalAgentStandby(principal, sessionId, validation.reason);+ removeSubscription(sessionId);+ break;+ }+ const [next] = await listLocalAgentExecutableInbox(principal, sessionId, 1);+ if (!next) break;+ const result = await executeLocalAgentStandbyMessage({+ record, message: next, capabilities, runtimeId,+ });+ if (result.fatal) {+ removeSubscription(sessionId);+ break;+ }+ if (!result.advanced) break;+ }+ } while (flight.rerun && inFlightSessions.get(key) === flight);+ } finally {+ if (inFlightSessions.get(key) === flight) inFlightSessions.delete(key);+ }+ })();+ return flight.promise;}export async function ensureLocalAgentStandbyRuntime(