From 4953711d4118c90508bdc456cbc4170cc38ff23f Mon Sep 17 00:00:00 2001 From: superset-home <338338640+superset-home@users.noreply.github.com> Date: Sat, 24 Oct 2026 15:10:46 +0000 Subject: [PATCH] fix(host-service): classify any file its storage cannot map as environmental git's xmmap() reports 'mmap failed: ' for packfiles, pack indexes and worktree files it hashes. ETIMEDOUT/ECANCELED there come from the storage layer (an evicted cloud-synced file or a stalled network volume), the same condition already classified for the index. Refs HOST-SERVICE-X --- .../router/git/utils/classify-git-error.test.ts | 16 ++++++++++++++++ .../trpc/router/git/utils/classify-git-error.ts | 7 ++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/packages/host-service/src/trpc/router/git/utils/classify-git-error.test.ts b/packages/host-service/src/trpc/router/git/utils/classify-git-error.test.ts index c2312f80b47..be136b8a10c 100644 --- a/packages/host-service/src/trpc/router/git/utils/classify-git-error.test.ts +++ b/packages/host-service/src/trpc/router/git/utils/classify-git-error.test.ts @@ -596,6 +596,19 @@ describe("rethrowEnvironmentalGitError", () => { ).toBe("GIT_ENVIRONMENT"); }); + test("object or worktree file its storage cannot deliver → PRECONDITION_FAILED / GIT_ENVIRONMENT", () => { + const canceled = "fatal: mmap failed: Operation canceled\n"; + const thrown = capture(new Error(canceled)); + expect(thrown?.code).toBe("PRECONDITION_FAILED"); + expect(causeKind(thrown)).toBe("GIT_ENVIRONMENT"); + expect(thrown?.message).toBe(canceled); + expect( + causeKind( + capture(new Error("fatal: mmap failed: Operation timed out\n")), + ), + ).toBe("GIT_ENVIRONMENT"); + }); + test("does not claim other index mapping failures or network timeouts", () => { expect( capture( @@ -604,6 +617,9 @@ describe("rethrowEnvironmentalGitError", () => { ), ), ).toBeNull(); + expect( + capture(new Error("fatal: mmap failed: Cannot allocate memory\n")), + ).toBeNull(); expect( capture( new Error( diff --git a/packages/host-service/src/trpc/router/git/utils/classify-git-error.ts b/packages/host-service/src/trpc/router/git/utils/classify-git-error.ts index d655eac768b..67117e494e4 100644 --- a/packages/host-service/src/trpc/router/git/utils/classify-git-error.ts +++ b/packages/host-service/src/trpc/router/git/utils/classify-git-error.ts @@ -20,6 +20,10 @@ const NOT_GIT_REPO_PATTERN = // such as running out of memory, stay unclassified. const INDEX_STORAGE_UNAVAILABLE_PATTERN = /unable to map index file: Operation (?:timed out|canceled)$/m; +// The same storage failure on any other file git maps (packfiles, pack +// indexes, worktree files it hashes), reported by git's xmmap() wrapper. +const MAPPED_FILE_STORAGE_UNAVAILABLE_PATTERN = + /^fatal: mmap failed: Operation (?:timed out|canceled)$/m; // Git's text when the directory resolves to a repository but has no work tree // attached: the repo is bare, or the linked worktree's admin data was removed // or pruned. Distinct from CWD_GONE_PATTERN, where the directory itself is @@ -147,7 +151,8 @@ export function rethrowEnvironmentalGitError(error: unknown): void { } if ( CWD_UNREADABLE_PATTERN.test(error.message) || - INDEX_STORAGE_UNAVAILABLE_PATTERN.test(error.message) + INDEX_STORAGE_UNAVAILABLE_PATTERN.test(error.message) || + MAPPED_FILE_STORAGE_UNAVAILABLE_PATTERN.test(error.message) ) { throw new TRPCError({ code: "PRECONDITION_FAILED",