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
Rust agentsagiaiai-memoryaudio-recordingcomputer-visionhermeshermes-agentllmlocal-ailocal-firstmachine-learningmcpmultimodalopenclawprivacyrewindscreen-recordingspeech-to-textycombinator
fix(enterprise): preserve recording during account handoff (#6841)
Ezra Ellette666dd855cd1e
diff --git a/apps/screenpipe-app-tauri/lib/hooks/__tests__/use-enterprise-policy.test.tsx b/apps/screenpipe-app-tauri/lib/hooks/__tests__/use-enterprise-policy.test.tsxindex 4f5b309d8..5ae0805cc 100644--- a/apps/screenpipe-app-tauri/lib/hooks/__tests__/use-enterprise-policy.test.tsx+++ b/apps/screenpipe-app-tauri/lib/hooks/__tests__/use-enterprise-policy.test.tsx@@ -815,6 +815,59 @@ describe("enterprise policy runtime manual activation", () => {);});+ it("preserves recording while handing an account-required key off to a saved account", async () => {+ mocks.commands.getEnterpriseLicenseKey.mockResolvedValue(KEY);+ Object.assign(mocks.settings, { user: { token: "account-token" } });++ let releaseAccountPolicy!: () => void;+ const accountPolicyPending = new Promise<void>((resolve) => {+ releaseAccountPolicy = resolve;+ });+ mocks.tauriFetch.mockImplementation(async (+ url: string,+ init?: { headers?: Record<string, string> },+ ) => {+ if (url.includes("/api/enterprise/policy")) {+ if (init?.headers?.Authorization === "Bearer account-token") {+ await accountPolicyPending;+ }+ return policyResponse({ requireAccountLogin: true });+ }+ if (url.includes("/api/enterprise/heartbeat")) return heartbeatResponse();+ throw new Error(`unexpected fetch ${url}`);+ });++ const { result } = await renderEnterprisePolicy();++ await waitFor(() =>+ expect(mocks.tauriFetch).toHaveBeenCalledWith(+ expect.stringContaining("/api/enterprise/policy"),+ expect.objectContaining({+ headers: expect.objectContaining({ Authorization: "Bearer account-token" }),+ }),+ ),+ );+ expect(result.current.authenticationState).toBe("checking");+ expect(mocks.commands.setEnterpriseRecordingAuthorized).not.toHaveBeenCalledWith(+ false,+ null,+ null,+ );++ releaseAccountPolicy();+ await waitFor(() => expect(result.current.isEnterpriseAuthenticated).toBe(true));+ expect(mocks.commands.setEnterpriseRecordingAuthorized).toHaveBeenCalledWith(+ true,+ "account",+ "account-token",+ );+ expect(mocks.commands.setEnterpriseRecordingAuthorized).not.toHaveBeenCalledWith(+ false,+ null,+ null,+ );+ });+it("recovers a rotated saved key through the signed-in account", async () => {mocks.commands.getEnterpriseLicenseKey.mockResolvedValue(KEY);Object.assign(mocks.settings, { user: { token: "account-token" } });diff --git a/apps/screenpipe-app-tauri/lib/hooks/use-enterprise-policy.ts b/apps/screenpipe-app-tauri/lib/hooks/use-enterprise-policy.tsindex 5d24c3178..ac9e7c27d 100644--- a/apps/screenpipe-app-tauri/lib/hooks/use-enterprise-policy.ts+++ b/apps/screenpipe-app-tauri/lib/hooks/use-enterprise-policy.ts@@ -1161,8 +1161,19 @@ export function useEnterprisePolicyRuntime() {// employee to sign in with their screenpipe account. Device policy was// already applied by fetchPolicy; only authentication is refused.if (credential.type === "license_key" && result.policy.requireAccountLogin) {- await setNativeRecordingAuthorized(false);setPolicy(result.policy);+ // A saved account is the next credential in this same startup check.+ // Keep the existing process-local grant while that viable credential is+ // still being verified; revoking here stops capture between two successful+ // checks and races the account grant against the in-flight teardown. The+ // account attempt below still revokes on an explicit denial, and a key-only+ // device still fails closed immediately.+ if (accountTokenRef.current) {+ setAuthenticationState("checking");+ setAuthenticationError(null);+ return { authenticated: false, retryable: false };+ }+ await setNativeRecordingAuthorized(false);setAuthenticationState("account");setAuthenticationError(ACCOUNT_LOGIN_REQUIRED_ERROR);return { authenticated: false, retryable: false };