Skip to content

Commit 4c83427

Browse files
fix(server): blocked git files are read again after a retry interval
Memo entries for git files whose read timed out now expire after 5 minutes (bounded to 1024 paths), so a config that was fixed shows its remote again without a restart. The concurrency comment now states the real cost: one deadline per batch of 16 blocked files per phase. The concurrent-deadline test asserts on reads and TestClock instead of wall-clock time. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent b294833 commit 4c83427

2 files changed

Lines changed: 92 additions & 17 deletions

File tree

‎apps/server/src/project/AgentSessionScanner.test.ts‎

Lines changed: 73 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,17 @@ const awaitWithinDeadline = <A, E, R>(
279279
Effect.flatMap((fiber) => Fiber.join(fiber).pipe(Effect.timeoutOption(deadline))),
280280
);
281281

282+
/**
283+
* Resolves once a reader has opened the FIFO, so its read deadline is already
284+
* scheduled on the TestClock. The writer stays open until the scope closes, so
285+
* the reader sees no EOF and has to wait out that deadline.
286+
*/
287+
const awaitGateReader = (gatePath: string) =>
288+
Effect.acquireRelease(
289+
Effect.promise(() => NodeFS.promises.open(gatePath, NodeFS.constants.O_WRONLY)),
290+
(handle) => Effect.promise(() => handle.close()),
291+
);
292+
282293
const scanUntilDeadline = <E, R>(
283294
scan: Effect.Effect<{ readonly candidates: ReadonlyArray<{ readonly path: string }> }, E, R>,
284295
) =>
@@ -1757,7 +1768,7 @@ describe.skipIf(HostProcess.Platform.defaultValue() === "win32")(
17571768
}).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
17581769
);
17591770

1760-
it.live("waits about one read deadline when several git configs block in one scan", () =>
1771+
it.effect("reads every blocked git config of a scan under one deadline", () =>
17611772
Effect.gen(function* () {
17621773
const path = yield* Path.Path;
17631774
const fileSystem = yield* FileSystem.FileSystem;
@@ -1789,16 +1800,20 @@ describe.skipIf(HostProcess.Platform.defaultValue() === "win32")(
17891800
});
17901801
}
17911802

1792-
// Each blocked read costs one deadline; reading them one after another
1793-
// would take a deadline per config.
1794-
expect(
1795-
yield* awaitWithinDeadline(
1796-
runScan({ claudeHomePath, codexHomePath }).pipe(
1797-
Effect.map(({ candidates }) => candidates.map(({ path }) => path).toSorted()),
1798-
),
1799-
"4 seconds",
1803+
const scan = yield* Effect.forkChild(
1804+
runScan({ claudeHomePath, codexHomePath }).pipe(
1805+
Effect.map(({ candidates }) => candidates.map(({ path }) => path).toSorted()),
18001806
),
1801-
).toEqual(Option.some(repos));
1807+
);
1808+
// Every blocked config is open before any deadline passes; reading them
1809+
// one after another would leave the later ones unopened.
1810+
yield* Effect.forEach(
1811+
[...repos.map((repo) => path.join(repo, ".git")), bareGitDir],
1812+
(gitDir) => awaitGateReader(path.join(gitDir, "config")),
1813+
{ concurrency: "unbounded" },
1814+
);
1815+
yield* TestClock.adjust("2 seconds");
1816+
expect(yield* Fiber.join(scan)).toEqual(repos);
18021817
}).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
18031818
);
18041819

@@ -1847,6 +1862,54 @@ describe.skipIf(HostProcess.Platform.defaultValue() === "win32")(
18471862
).toBe(true);
18481863
}).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
18491864
);
1865+
1866+
it.effect("reads a once-blocked git config again after the retry interval", () =>
1867+
Effect.gen(function* () {
1868+
const path = yield* Path.Path;
1869+
const fileSystem = yield* FileSystem.FileSystem;
1870+
const claudeHomePath = yield* makeTempDir("t3code-claude-home-");
1871+
const codexHomePath = yield* makeTempDir("t3code-codex-home-");
1872+
const repo = yield* makeTempDir("t3code-workspace-unblocked-config-");
1873+
yield* fileSystem.makeDirectory(path.join(repo, ".git"));
1874+
const configPath = path.join(repo, ".git", "config");
1875+
yield* makeOpenGate(configPath);
1876+
yield* writeTranscript({
1877+
filePath: path.join(claudeHomePath, "projects", "-unblocked", "a.jsonl"),
1878+
contents: claudeSessionLine(repo),
1879+
mtimeMs: Date.parse("2026-05-03T00:00:00.000Z"),
1880+
});
1881+
const gitOfScan = (scan: AgentSessionScanner.AgentSessionScanner["Service"]["scan"]) =>
1882+
scan.pipe(Effect.map(({ candidates }) => candidates.map(({ git }) => git)));
1883+
1884+
yield* Effect.gen(function* () {
1885+
const scanner = yield* AgentSessionScanner.AgentSessionScanner;
1886+
const blockedScan = yield* Effect.forkChild(gitOfScan(scanner.scan));
1887+
yield* Effect.scoped(
1888+
Effect.gen(function* () {
1889+
yield* awaitGateReader(configPath);
1890+
yield* TestClock.adjust("2 seconds");
1891+
expect(yield* Fiber.join(blockedScan)).toEqual([
1892+
{ remoteKey: null, repository: null },
1893+
]);
1894+
}),
1895+
);
1896+
1897+
yield* fileSystem.remove(configPath);
1898+
yield* fileSystem.writeFileString(
1899+
configPath,
1900+
`[remote "origin"]\n\turl = [email protected]:pingdotgg/unblocked.git\n`,
1901+
);
1902+
expect(yield* gitOfScan(scanner.scan), "a blocked path is skipped for a while").toEqual([
1903+
{ remoteKey: null, repository: null },
1904+
]);
1905+
1906+
yield* TestClock.adjust("10 minutes");
1907+
expect(yield* gitOfScan(scanner.scan)).toEqual([
1908+
{ remoteKey: "github.com/pingdotgg/unblocked", repository: "pingdotgg/unblocked" },
1909+
]);
1910+
}).pipe(Effect.provide(layerScannerTest({ claudeHomePath, codexHomePath })));
1911+
}).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
1912+
);
18501913
},
18511914
);
18521915

‎apps/server/src/project/AgentSessionScanner.ts‎

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
type AgentSessionScanResult,
1414
type ProviderInstanceConfig,
1515
} from "@t3tools/contracts";
16+
import * as Clock from "effect/Clock";
1617
import * as Context from "effect/Context";
1718
import * as DateTime from "effect/DateTime";
1819
import * as Effect from "effect/Effect";
@@ -77,9 +78,12 @@ const MAX_IMPORT_RECORDS = 100_000;
7778
*/
7879
const GIT_FILE_READ_DEADLINE = "2 seconds";
7980
const MAX_GIT_FILE_BYTES = 1024 * 1024;
80-
// Reads run concurrently so a scan waits about one deadline per phase however
81-
// many files block, not one per blocked file.
81+
// Reads run concurrently, so each phase waits one deadline per batch of this
82+
// many blocked files rather than one per blocked file.
8283
const GIT_FILE_READ_CONCURRENCY = 16;
84+
// A blocked path is skipped for a while, then read again in case it was fixed.
85+
const BLOCKED_GIT_FILE_RETRY_MS = 5 * 60 * 1000;
86+
const MAX_BLOCKED_GIT_FILE_PATHS = 1024;
8387

8488
const TranscriptContentBlock = Schema.Struct({
8589
type: Schema.optional(Schema.String),
@@ -703,23 +707,26 @@ export const make = Effect.gen(function* () {
703707
return `path:${normalizeProjectPathForComparison(realPath)}`;
704708
});
705709

706-
// Paths whose own read outlived the deadline. Without this every later scan
707-
// would wait out the deadline again for each phase that touches them.
708-
const blockedGitFilePaths = new Set<string>();
710+
// Paths whose own read outlived the deadline, mapped to when they may be read
711+
// again. Without this every later scan would wait out the deadline again for
712+
// each phase that touches them.
713+
const blockedGitFilePaths = new Map<string, number>();
709714

710715
/** Reads small files without the libuv pool; "" when missing, unreadable or blocked. */
711716
const readGitFiles = Effect.fn("AgentSessionScanner.readGitFiles")(function* (
712717
filePaths: ReadonlyArray<string>,
713718
) {
714719
const unique = Array.from(new Set(filePaths));
720+
const now = yield* Clock.currentTimeMillis;
715721
const contents = yield* Effect.forEach(
716722
unique,
717723
(filePath) => {
718724
// No privacy prompts or FIFOs to block open() here.
719725
if (isWindows) {
720726
return fileSystem.readFileString(filePath).pipe(Effect.orElseSucceed(() => ""));
721727
}
722-
if (blockedGitFilePaths.has(filePath)) return Effect.succeed("");
728+
if ((blockedGitFilePaths.get(filePath) ?? 0) > now) return Effect.succeed("");
729+
blockedGitFilePaths.delete(filePath);
723730
return processRunner
724731
.run({
725732
command: "cat",
@@ -731,7 +738,12 @@ export const make = Effect.gen(function* () {
731738
})
732739
.pipe(
733740
Effect.map((result) => {
734-
if (result.timedOut) blockedGitFilePaths.add(filePath);
741+
if (result.timedOut) {
742+
if (blockedGitFilePaths.size >= MAX_BLOCKED_GIT_FILE_PATHS) {
743+
blockedGitFilePaths.delete(blockedGitFilePaths.keys().next().value!);
744+
}
745+
blockedGitFilePaths.set(filePath, now + BLOCKED_GIT_FILE_RETRY_MS);
746+
}
735747
return result.code === 0 ? result.stdout : "";
736748
}),
737749
Effect.orElseSucceed(() => ""),

0 commit comments

Comments
 (0)