Skip to content

Commit c1b0cee

Browse files
chickenputtyclaude
andcommitted
Merge pingdotgg#12602: answer cheap git metadata from repository files
SkiTee3000's open upstream PR (issues pingdotgg#8949, pingdotgg#11220, pingdotgg#12498): read-only git questions the idle server asks every tick (rev-parse, symbolic-ref, remote, config --get, show-ref, for-each-ref, rev-list counts) are answered from the files under .git, byte for byte, or fall back to spawning git. T3CODE_GIT_FAST_PATH=0 turns it off. Checked on this PC before merging: 114 commands across pet-simulator-99, two of its agent worktrees, t3code, agent-kit and a non-repository folder; 101 answered from files, 0 differ from git's output, 0.86 s against 5.7 s for git on a warm pass. The git suites fail the same 7 Windows tests as fork main. Merged as its branch, not squashed: if upstream lands it, the sync merge sees the same changes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
2 parents 3b9a0db + b866579 commit c1b0cee

7 files changed

Lines changed: 2647 additions & 46 deletions

File tree

‎apps/server/src/observability/Metrics.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ export interface WithMetricsOptions {
110110
) => Readonly<Record<string, unknown>>;
111111
}
112112

113-
const recordMetrics = (
113+
export const recordMetrics = (
114114
options: WithMetricsOptions,
115115
startedAt: bigint,
116116
exit: Exit.Exit<unknown, unknown>,

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

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ import * as Duration from "effect/Duration";
99
import * as Effect from "effect/Effect";
1010
import * as Exit from "effect/Exit";
1111
import * as Layer from "effect/Layer";
12+
import * as Option from "effect/Option";
1213

1314
import * as ProcessRunner from "../processRunner.ts";
15+
import * as GitMetadataFastPath from "../vcs/GitMetadataFastPath.ts";
1416

1517
const DEFAULT_REPOSITORY_IDENTITY_CACHE_CAPACITY = 512;
1618
// Background sweeps resolve every project each minute. A long TTL keeps them
@@ -115,19 +117,26 @@ function buildRepositoryIdentity(input: {
115117
};
116118
}
117119

118-
const resolveRepositoryIdentityCacheKey = Effect.fn("RepositoryIdentityResolver.resolveCacheKey")(
119-
function* (cwd: string) {
120-
const processRunner = yield* ProcessRunner.ProcessRunner;
120+
/** Reads the answer from the repository files when possible, otherwise spawns git. */
121+
const runGitMetadataCommand = Effect.fn("RepositoryIdentityResolver.runGitMetadataCommand")(
122+
function* (cwd: string, args: ReadonlyArray<string>) {
123+
const answer = yield* Effect.promise(() =>
124+
GitMetadataFastPath.tryAnswerGitCommand({ cwd, args }),
125+
);
126+
if (answer !== null) return Option.some({ code: answer.exitCode, stdout: answer.stdout });
121127

128+
const processRunner = yield* ProcessRunner.ProcessRunner;
122129
// git is a real executable on every platform — no cmd.exe shell mode, which
123130
// would split paths containing spaces during cmd's re-tokenization.
124-
const topLevelResult = yield* processRunner
125-
.run({
126-
command: "git",
127-
args: ["-C", cwd, "rev-parse", "--show-toplevel"],
128-
timeoutBehavior: "timedOutResult",
129-
})
131+
return yield* processRunner
132+
.run({ command: "git", args: ["-C", cwd, ...args], timeoutBehavior: "timedOutResult" })
130133
.pipe(Effect.option);
134+
},
135+
);
136+
137+
const resolveRepositoryIdentityCacheKey = Effect.fn("RepositoryIdentityResolver.resolveCacheKey")(
138+
function* (cwd: string) {
139+
const topLevelResult = yield* runGitMetadataCommand(cwd, ["rev-parse", "--show-toplevel"]);
131140
if (topLevelResult._tag === "None" || topLevelResult.value.code !== 0) {
132141
return null;
133142
}
@@ -142,14 +151,7 @@ const resolveRepositoryIdentityFromCacheKey = Effect.fn(
142151
)(function* (
143152
cacheKey: string,
144153
): Effect.fn.Return<RepositoryIdentity | null, never, ProcessRunner.ProcessRunner> {
145-
const processRunner = yield* ProcessRunner.ProcessRunner;
146-
const remoteResult = yield* processRunner
147-
.run({
148-
command: "git",
149-
args: ["-C", cacheKey, "remote", "-v"],
150-
timeoutBehavior: "timedOutResult",
151-
})
152-
.pipe(Effect.option);
154+
const remoteResult = yield* runGitMetadataCommand(cacheKey, ["remote", "-v"]);
153155
if (remoteResult._tag === "None" || remoteResult.value.code !== 0) {
154156
return null;
155157
}

0 commit comments

Comments
 (0)