Skip to content

Commit f8a30e1

Browse files
refactor(github): GraphQL hosts route through layerHttp's url on Effect 4.0.5
Effect 4.0.5 lets GraphQLProtocol.layerHttp take the URL as a function of the calling context (Effect-TS/effect#9150), and resolvers batch by that URL. The transport now reads each call's host from GitHubGraphQlTarget, so the private endpoint reference, the URL-rewriting HttpClient, and the host in batchKey are gone. 4.0.5 also types file stat dev/ino as bigint. The two inode checks that guarded with Number.isSafeInteger would have silently stopped matching, and the agent session import keeps them as numbers on the wire. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 0ffc509 commit f8a30e1

8 files changed

Lines changed: 529 additions & 500 deletions

File tree

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

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -592,8 +592,8 @@ function transcriptIdentity(filePath: string, stats: FileSystem.File.Info) {
592592
filePath,
593593
size: Number(stats.size),
594594
mtimeMs: Option.match(stats.mtime, { onNone: () => null, onSome: (date) => date.getTime() }),
595-
device: stats.dev,
596-
inode: Option.getOrNull(stats.ino),
595+
device: Number(stats.dev),
596+
inode: Option.match(stats.ino, { onNone: () => null, onSome: Number }),
597597
birthtimeMs: Option.match(stats.birthtime, {
598598
onNone: () => null,
599599
onSome: (date) => date.getTime(),
@@ -671,12 +671,7 @@ export const make = Effect.gen(function* () {
671671
) {
672672
const resolved = path.resolve(target);
673673
const stats = knownStats === undefined ? yield* statOption(resolved) : Option.some(knownStats);
674-
if (
675-
Option.isSome(stats) &&
676-
Option.isSome(stats.value.ino) &&
677-
Number.isSafeInteger(stats.value.ino.value) &&
678-
stats.value.ino.value > 0
679-
) {
674+
if (Option.isSome(stats) && Option.isSome(stats.value.ino) && stats.value.ino.value > 0n) {
680675
return `inode:${stats.value.dev}:${stats.value.ino.value}`;
681676
}
682677
const realPath = yield* fileSystem

‎packages/shared/src/nodeRuntime.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,7 @@ export const resolveNodeExecutable = Effect.fn("nodeRuntime.resolveNodeExecutabl
100100
hostInfo.value.dev === nodeInfo.value.dev &&
101101
Option.isSome(hostInfo.value.ino) &&
102102
Option.isSome(nodeInfo.value.ino) &&
103-
Number.isSafeInteger(hostInfo.value.ino.value) &&
104-
hostInfo.value.ino.value > 0 &&
103+
hostInfo.value.ino.value > 0n &&
105104
hostInfo.value.ino.value === nodeInfo.value.ino.value
106105
) {
107106
return yield* new NodeRuntimeUnavailableError({ feature });

‎packages/source-control-github/src/server/gitHubGraphQlClient.test.ts‎

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -74,21 +74,38 @@ const readStats = (host: string, number = 7) =>
7474
const stats = { additions: 3, deletions: 1 };
7575

7676
describe("GitHubGraphQlAuth", () => {
77-
it.effect("sends each host's request to its own endpoint with its token", () => {
78-
const { layer, requests } = harness(() =>
79-
json({ data: { _0_repository: { pullRequest: stats } } }),
80-
);
81-
return Effect.gen(function* () {
82-
yield* readStats("github.com");
83-
yield* readStats("github.acme.test");
84-
expect(requests.map((request) => request.url)).toEqual([
85-
"https://api.github.com/graphql",
86-
"https://github.acme.test/api/graphql",
87-
]);
88-
expect(requests[0]?.headers["authorization"]).toBe("Bearer secret");
89-
expect(requests[0]?.headers["x-github-api-version"]).toBe("2022-11-28");
90-
}).pipe(Effect.provide(layer));
91-
});
77+
it.effect(
78+
"sends each host's lookups to its own endpoint with its token, never in one batch",
79+
() => {
80+
const { layer, requests } = harness(() =>
81+
json({ data: { _0_repository: { pullRequest: stats } } }),
82+
);
83+
return Effect.gen(function* () {
84+
const client = yield* GraphQLClient.make(
85+
PullRequestBatchesGraphQLGroup.middleware(GitHubGraphQlClient.GitHubGraphQlAuth),
86+
).pipe(Effect.provide(GitHubGraphQlClient.layer));
87+
const resolver = GraphQLResolver.aliased(client.PullRequestStats, {
88+
batchKey: GitHubGraphQlClient.batchKey,
89+
});
90+
const lookup = (host: string) =>
91+
GraphQLResolver.request({ owner: "acme", name: "web", number: 7 }, resolver).pipe(
92+
Effect.provideService(GitHubGraphQlClient.GitHubGraphQlTarget, {
93+
host,
94+
operation: "stats",
95+
}),
96+
);
97+
yield* Effect.all([lookup("github.com"), lookup("github.acme.test")], {
98+
concurrency: "unbounded",
99+
});
100+
expect(requests.map((request) => request.url).toSorted()).toEqual([
101+
"https://api.github.com/graphql",
102+
"https://github.acme.test/api/graphql",
103+
]);
104+
expect(requests[0]?.headers["authorization"]).toBe("Bearer secret");
105+
expect(requests[0]?.headers["x-github-api-version"]).toBe("2022-11-28");
106+
}).pipe(Effect.provide(layer));
107+
},
108+
);
92109

93110
it.effect("pauses the host on a RATE_LIMITED answer sent with HTTP 200", () => {
94111
const reset = Math.floor(NOW / 1000) + 600;

‎packages/source-control-github/src/server/gitHubGraphQlClient.ts‎

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as Effect from "effect/Effect";
44
import * as Layer from "effect/Layer";
55
import * as Redacted from "effect/Redacted";
66
import * as Stream from "effect/Stream";
7-
import { HttpClient, HttpClientError, HttpClientRequest } from "effect/http";
7+
import { HttpClient, HttpClientError } from "effect/http";
88
import * as Headers from "effect/http/Headers";
99
import { GraphQLClientError, GraphQLMiddleware, GraphQLProtocol } from "effect/graphql";
1010
import { SourceControlProviderKind } from "@t3tools/contracts";
@@ -27,15 +27,6 @@ export class GitHubGraphQlTarget extends Context.Service<
2727
}
2828
>()("@t3tools/source-control-github/server/gitHubGraphQlClient/GitHubGraphQlTarget") {}
2929

30-
/**
31-
* The GraphQL endpoint the request in flight is sent to. `GitHubGraphQlAuth` sets it for `next`,
32-
* because `GraphQLProtocol.layerHttp` takes one URL and one client serves every GitHub host.
33-
*/
34-
const GraphQlEndpoint = Context.Reference<string | null>(
35-
"@t3tools/source-control-github/server/gitHubGraphQlClient/GraphQlEndpoint",
36-
{ defaultValue: () => null },
37-
);
38-
3930
/**
4031
* GitHub's auth and rate limits around a generated GraphQL call: the host's token, the quota
4132
* reserve and the host-wide pause before it is sent, and what GitHub's answer says about them after.
@@ -88,7 +79,6 @@ export class GitHubGraphQlAuth extends GraphQLMiddleware.Service<
8879
authorization: `Bearer ${Redacted.value(token)}`,
8980
}),
9081
}).pipe(
91-
Effect.provideService(GraphQlEndpoint, GitHubApi.gitHubApiUrls(host).graphql),
9282
Effect.timeout(GitHubApi.DEFAULT_TIMEOUT),
9383
Effect.catchTags({
9484
TimeoutError: (cause) =>
@@ -198,26 +188,23 @@ export class GitHubGraphQlAuth extends GraphQLMiddleware.Service<
198188
}
199189

200190
/**
201-
* The HTTP transport, sending each request to the endpoint `GitHubGraphQlAuth` chose for its host.
202-
* The middleware's span is the request's: the client's own would add `url.full`, which can carry
203-
* SHAs and branch names, so it is off, as for REST.
191+
* The HTTP transport, sending each request to its target host's endpoint. Resolvers batch by this
192+
* URL, so lookups for different hosts never share a request. `GitHubGraphQlAuth` requires the
193+
* target, so every call has one. The middleware's span is the request's: the client's own would add
194+
* `url.full`, which can carry SHAs and branch names, so it is off, as for REST.
204195
*/
205-
const layerProtocol = GraphQLProtocol.layerHttp({ url: "https://api.github.com/graphql" }).pipe(
196+
const layerProtocol = GraphQLProtocol.layerHttp({
197+
url: ({ context }) =>
198+
GitHubApi.gitHubApiUrls(Context.getUnsafe(context, GitHubGraphQlTarget).host).graphql,
199+
}).pipe(
206200
Layer.provide(
207201
Layer.effect(
208202
HttpClient.HttpClient,
209203
Effect.gen(function* () {
210204
const client = yield* HttpClient.HttpClient;
211-
return client.pipe(
212-
HttpClient.mapRequestEffect((request) =>
213-
Effect.gen(function* () {
214-
const endpoint = yield* GraphQlEndpoint;
215-
return endpoint === null ? request : HttpClientRequest.setUrl(request, endpoint);
216-
}),
217-
),
218-
HttpClient.transformResponse(
219-
Effect.provideService(HttpClient.TracerDisabledWhen, () => true),
220-
),
205+
return HttpClient.transformResponse(
206+
client,
207+
Effect.provideService(HttpClient.TracerDisabledWhen, () => true),
221208
);
222209
}),
223210
),
@@ -231,12 +218,12 @@ const layerProtocol = GraphQLProtocol.layerHttp({ url: "https://api.github.com/g
231218
export const layer = Layer.merge(GitHubGraphQlAuth.layer, layerProtocol);
232219

233220
/**
234-
* What decides which lookups may share one batched request: the host, and the credential and
235-
* rate-limit scope it will be sent under. Read from the context the lookup was made in.
221+
* What decides which lookups to one host may share a batched request: the credential and
222+
* rate-limit scope it will be sent under. Read from the context the lookup was made in. Resolvers
223+
* already keep hosts apart, since they batch by the transport's URL too.
236224
*/
237225
export const batchKey = (context: Context.Context<GitHubGraphQlTarget>) =>
238226
JSON.stringify([
239-
Context.get(context, GitHubGraphQlTarget).host.toLowerCase(),
240227
Context.getOrElse(context, GitHubApi.PinnedGitHubCredential, () => null)
241228
?.credentialFingerprint ?? null,
242229
Context.getOrElse(context, SourceControlRateLimit.CredentialScope, () => ""),

0 commit comments

Comments
 (0)