Skip to content

armgit / mso

Public Imported from GitHub
0

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.

fix(workflow): retain completion during status receipt reads

Abdurrahman Fakhrul3d0a33149679
diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md
index 54c8d1c5..8fbddcae 100644
--- a/docs/CHANGELOG.md
+++ b/docs/CHANGELOG.md
@@ -27,6 +27,7 @@ this is the *what*, and it is what Settings → Account → About shows as “Wh
**Fixed**
+- `workflow` retain completion during status receipt reads
- `security` guard model discovery and isolate CodeQL findings
- close domain integration regressions and preserve strict gates
- satisfy strict CLI and source parsing checks
diff --git a/docs/PROGRESS.md b/docs/PROGRESS.md
index 92d321e0..d9e7112f 100644
--- a/docs/PROGRESS.md
+++ b/docs/PROGRESS.md
@@ -8,6 +8,8 @@ Scorecard #137 is an accurate historical process finding: PR #123 was merged wit
Local candidate verification: 74 focused tests across six files pass, including real URL/DNS-guard execution with intercepted sockets, address pinning, redirect refusal, malformed keys, response cancellation and strict inventory failure cases. Typecheck, zero-warning lint, repository contract checks and the strict high/critical dependency audit pass. Hosted CI remains the full coverage/build/browser gate because this isolated development environment has no Docker daemon for the mandatory Forge fixture. MSO MCP returned an internal error during target discovery, so this entry records repository work rather than a runtime deployment.
+The first hosted candidate passed both CodeQL Actions analyses, the native GitHub CodeQL check and the branch's all-tool inventory with zero open findings. Its push CI exposed a separate workflow status race: a descriptor could return the previous running receipt after execution had saved the final receipt and removed its pending promise. Status now captures that completion promise before reading the receipt, preserving the bounded wait and final reread. Two deterministic regressions reproduce the old stale result for failed and completed runs. All 14 related tests now pass, including the existing execution, idempotence and live-authority cases; typecheck, zero-warning lint and repository checks also pass. Full hosted CI must pass again on the revised candidate before merge.
+
## 2026-10-18: Implement the first three bounded Nakama journeys
Owner onboarding now advances from installation readiness to a selected project and a saved, read-only Workflow receipt. Its first action uses a fixed graph and exact graph revision; it stores the attempt identity before dispatch, reconciles lost responses and reopens the existing receipt after reload. Optional model checks disclose their cost, while the initial project action needs no inference. Viewer and Operator devices can inspect readiness without receiving Owner controls. The backup link describes the actual browser and memory restore surfaces; it does not imply a full installation restore.
diff --git a/lib/workflow/automation-engine.ts b/lib/workflow/automation-engine.ts
index 85444510..31c83361 100644
--- a/lib/workflow/automation-engine.ts
+++ b/lib/workflow/automation-engine.ts
@@ -91,11 +91,13 @@ export async function startFlow(flow: AutomationFlow, project: string, raw: unkn
export async function flowStatus(id: string, context: CapabilityRunContext, waitMs = 0) {
if (!Number.isSafeInteger(waitMs) || waitMs < 0 || waitMs > 25_000) throw new Error("wait_ms must be an integer from 0 to 25000");
const owner = flowOwner(principal(context));
+ // Retain completion even if execution settles while the receipt read is in flight.
+ const work = pending.get(id);
let run = await readFlowRun(owner, id);
if (!run) throw new Error("flow run not found for this principal");
- if (run.state === "running" && pending.has(id) && waitMs > 0) {
+ if (run.state === "running" && work && waitMs > 0) {
let timer: ReturnType<typeof setTimeout> | undefined;
- await Promise.race([pending.get(id), new Promise(resolve => { timer = setTimeout(resolve, waitMs); })]);
+ await Promise.race([work, new Promise(resolve => { timer = setTimeout(resolve, waitMs); })]);
clearTimeout(timer); run = await readFlowRun(owner, id) ?? run;
}
if (run.state === "running" && run.instance !== INSTANCE) {
diff --git a/lib/workflow/automation-status.test.ts b/lib/workflow/automation-status.test.ts
new file mode 100644
index 00000000..650a6288
--- /dev/null
+++ b/lib/workflow/automation-status.test.ts
@@ -0,0 +1,32 @@
+import { afterEach, expect, it, vi } from "vitest";
+import type { FlowRun } from "@/lib/contracts/automation";
+
+const read = vi.hoisted(() => vi.fn());
+vi.mock("./automation-store", async () => {
+ const actual = await vi.importActual<Record<string, unknown>>("./automation-store");
+ return { ...actual, readFlowRun: read };
+});
+const { flowStatus } = await import("./automation-engine");
+const state = globalThis as typeof globalThis & { msoFlowInstance?: string; msoFlowPending?: Map<string, Promise<void>> };
+const pending = state.msoFlowPending!;
+const context = { principal: "status-test-owner", sessionId: "status-test-session", scope: "exec" as const };
+const id = "c".repeat(32);
+
+afterEach(() => { pending.delete(id); read.mockReset(); });
+
+it.each(["failed", "completed"] as const)("refreshes a stale receipt when execution becomes %s during the first read", async (terminal) => {
+ const run: FlowRun = {
+ version: 1, id, owner: "a".repeat(64), sessionId: context.sessionId, project: "fixture", flow: "fixture",
+ fingerprint: "fixture", pid: process.pid, instance: state.msoFlowInstance!, state: "running",
+ startedAt: new Date().toISOString(), updatedAt: new Date().toISOString(), steps: [],
+ };
+ let finish!: () => void;
+ const work = new Promise<void>(resolve => { finish = resolve; }).finally(() => pending.delete(id));
+ pending.set(id, work);
+ // The open descriptor retains the old receipt while execution publishes its final replacement.
+ read.mockImplementationOnce(async () => { finish(); await work; return run; });
+ read.mockResolvedValueOnce({ ...run, state: terminal });
+
+ expect((await flowStatus(id, context, 5000)).state).toBe(terminal);
+ expect(read).toHaveBeenCalledTimes(2);
+});