Skip to content

YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context

fix(app): recover from hung enterprise build check

Louis Beaumont464a59f405bf
diff --git a/apps/screenpipe-app-tauri/components/app-entitlement-gate.test.tsx b/apps/screenpipe-app-tauri/components/app-entitlement-gate.test.tsx
index a49248a8a..6bfd405f0 100644
--- a/apps/screenpipe-app-tauri/components/app-entitlement-gate.test.tsx
+++ b/apps/screenpipe-app-tauri/components/app-entitlement-gate.test.tsx
@@ -30,6 +30,7 @@ const mocks = vi.hoisted(() => ({
loadUser: vi.fn().mockResolvedValue(undefined),
updateSettings: vi.fn().mockResolvedValue(undefined),
state: { isSettingsLoaded: true, user: null as any },
+ enterpriseResolutionError: false,
enterprise: {
isManagedDeployment: false,
isManagedDeploymentResolved: true,
@@ -65,6 +66,7 @@ vi.mock("@/lib/hooks/use-managed-policy", () => ({
useManagedPolicy: () => ({
isManagedDeployment: mocks.enterprise.isManagedDeployment,
isManagedDeploymentResolved: mocks.enterprise.isManagedDeploymentResolved,
+ managedDeploymentResolutionError: mocks.enterpriseResolutionError,
authenticationState: mocks.enterprise.authenticationState,
authenticationError: mocks.enterprise.authenticationError,
isManagedAuthenticated: mocks.enterprise.isManagedAuthenticated,
@@ -126,6 +128,7 @@ describe("AppEntitlementGate", () => {
vi.stubEnv("TAURI_ENV_DEBUG", "false");
vi.stubEnv("NEXT_PUBLIC_SCREENPIPE_DEV_BILLING_BYPASS", "false");
mocks.state = { isSettingsLoaded: true, user: null };
+ mocks.enterpriseResolutionError = false;
mocks.windowLabel = "home";
mocks.enterprise = {
isManagedDeployment: false,
@@ -176,6 +179,19 @@ describe("AppEntitlementGate", () => {
await waitFor(() => expect(mocks.stopScreenpipe).toHaveBeenCalled());
});
+ it("surfaces a recoverable error when build detection cannot finish", () => {
+ mocks.enterprise.isManagedDeploymentResolved = false;
+ mocks.enterpriseResolutionError = true;
+
+ render(<AppEntitlementGate>{protectedApp}</AppEntitlementGate>);
+
+ expect(screen.getByText(/couldn't check access/i)).toBeInTheDocument();
+ expect(screen.getByText(/retry automatically/i)).toBeInTheDocument();
+ expect(
+ screen.getByRole("button", { name: /reload and retry/i }),
+ ).toBeInTheDocument();
+ });
+
it("keeps recording while enterprise authentication is still checking", async () => {
mocks.state.user = baseUser({
app_entitled: true,
diff --git a/apps/screenpipe-app-tauri/components/app-entitlement-gate.tsx b/apps/screenpipe-app-tauri/components/app-entitlement-gate.tsx
index 764f56c62..5b5e44077 100644
--- a/apps/screenpipe-app-tauri/components/app-entitlement-gate.tsx
+++ b/apps/screenpipe-app-tauri/components/app-entitlement-gate.tsx
@@ -109,6 +109,7 @@ export function AppEntitlementGate({
const {
isManagedDeployment,
isManagedDeploymentResolved,
+ managedDeploymentResolutionError,
authenticationState,
authenticationError,
isManagedAuthenticated,
@@ -669,6 +670,22 @@ export function AppEntitlementGate({
}
if (!isManagedDeploymentResolved) {
+ if (managedDeploymentResolutionError) {
+ return (
+ <EntitlementShell
+ title="couldn't check access"
+ description="screenpipe could not confirm which build is installed. it will retry automatically."
+ >
+ <Button
+ onClick={() => window.location.reload()}
+ variant="secondary"
+ className="w-full"
+ >
+ reload and retry
+ </Button>
+ </EntitlementShell>
+ );
+ }
return (
<EntitlementShell
title="checking access"
diff --git a/apps/screenpipe-app-tauri/lib/hooks/__tests__/use-is-enterprise-build.test.tsx b/apps/screenpipe-app-tauri/lib/hooks/__tests__/use-is-enterprise-build.test.tsx
index 52bc01942..cf31f1037 100644
--- a/apps/screenpipe-app-tauri/lib/hooks/__tests__/use-is-enterprise-build.test.tsx
+++ b/apps/screenpipe-app-tauri/lib/hooks/__tests__/use-is-enterprise-build.test.tsx
@@ -15,12 +15,15 @@ vi.mock("@/lib/utils/tauri", () => ({
},
}));
-import { useEnterpriseBuildStatus } from "@/lib/hooks/use-is-enterprise-build";
+let useEnterpriseBuildStatus: (typeof import("@/lib/hooks/use-is-enterprise-build"))["useEnterpriseBuildStatus"];
describe("useEnterpriseBuildStatus", () => {
- beforeEach(() => {
+ beforeEach(async () => {
vi.useFakeTimers();
mocks.isEnterpriseBuildCmd.mockReset();
+ vi.resetModules();
+ ({ useEnterpriseBuildStatus } =
+ await import("@/lib/hooks/use-is-enterprise-build"));
});
afterEach(() => {
@@ -61,4 +64,31 @@ describe("useEnterpriseBuildStatus", () => {
});
expect(mocks.isEnterpriseBuildCmd).toHaveBeenCalledTimes(4);
});
+
+ it("abandons a hung startup IPC and recovers on a fresh invoke", async () => {
+ mocks.isEnterpriseBuildCmd
+ .mockImplementationOnce(() => new Promise<boolean>(() => {}))
+ .mockResolvedValueOnce(false);
+
+ const { result } = renderHook(() => useEnterpriseBuildStatus());
+
+ await act(async () => {
+ await vi.advanceTimersByTimeAsync(3_000);
+ });
+ expect(result.current).toEqual({
+ isEnterprise: false,
+ resolved: false,
+ error: false,
+ });
+
+ await act(async () => {
+ await vi.advanceTimersByTimeAsync(500);
+ });
+ expect(result.current).toEqual({
+ isEnterprise: false,
+ resolved: true,
+ error: false,
+ });
+ expect(mocks.isEnterpriseBuildCmd).toHaveBeenCalledTimes(2);
+ });
});
diff --git a/apps/screenpipe-app-tauri/lib/hooks/use-is-enterprise-build.ts b/apps/screenpipe-app-tauri/lib/hooks/use-is-enterprise-build.ts
index 43f3f8ed3..086418842 100644
--- a/apps/screenpipe-app-tauri/lib/hooks/use-is-enterprise-build.ts
+++ b/apps/screenpipe-app-tauri/lib/hooks/use-is-enterprise-build.ts
@@ -11,6 +11,31 @@ import { commands } from "@/lib/utils/tauri";
let cachedResult: boolean | null = null;
let pendingPromise: Promise<boolean> | null = null;
+// Tauri invokes can remain pending when WebKit's content process is replaced
+// during startup. A bounded attempt lets the shared promise clear so the next
+// invoke can reach the new content process instead of wedging every consumer.
+const ENTERPRISE_BUILD_IPC_TIMEOUT_MS = 3_000;
+
+async function withTimeout<T>(
+ promise: Promise<T>,
+ timeoutMs: number,
+): Promise<T> {
+ let timer: ReturnType<typeof setTimeout> | undefined;
+ try {
+ return await Promise.race([
+ promise,
+ new Promise<never>((_, reject) => {
+ timer = setTimeout(
+ () => reject(new Error("enterprise build policy check timed out")),
+ timeoutMs,
+ );
+ }),
+ ]);
+ } finally {
+ if (timer) clearTimeout(timer);
+ }
+}
+
export const E2E_FORCE_ENTERPRISE_BUILD_KEY =
"screenpipe_e2e_force_enterprise_build";
@@ -39,7 +64,10 @@ async function resolveEnterpriseBuild(): Promise<boolean> {
const attempt = (async () => {
for (let i = 0; i < 3; i++) {
try {
- const result = await commands.isEnterpriseBuildCmd();
+ const result = await withTimeout(
+ commands.isEnterpriseBuildCmd(),
+ ENTERPRISE_BUILD_IPC_TIMEOUT_MS,
+ );
cachedResult = result;
if (i === 0) {
console.log(`[enterprise] isEnterpriseBuild = ${result}`);