Skip to content

Commit 5ff188e

Browse files
Merge remote-tracking branch 'origin/main' into pr-32520
2 parents 256f768 + e5b0718 commit 5ff188e

13 files changed

Lines changed: 372 additions & 46 deletions

‎apps/server/src/orchestration-v2/Adapters/OpenCode2AdapterV2.test.ts‎

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4931,6 +4931,114 @@ it.layer(McpProviderSessions.layer)("OpenCode2 adapter", (it) => {
49314931
}).pipe(Effect.scoped, Effect.provide(IdAllocator.layer)),
49324932
);
49334933

4934+
it.effect("shows a question asked while OpenCode wakes for a background reply", () =>
4935+
Effect.gen(function* () {
4936+
const OTHER = "ses_other00000000000000000000";
4937+
const gate = makeProviderReplayGate(["continued"]);
4938+
const offered =
4939+
yield* Deferred.make<ProviderContinuationRequests.ProviderContinuationRequest>();
4940+
const { runtime, thread } = yield* resumed(
4941+
[
4942+
out("session.get", { sessionID: OTHER }),
4943+
replyData("session.get", sessionInfo({ id: OTHER })),
4944+
out("permission.list", { sessionID: OTHER }),
4945+
replyData("permission.list", []),
4946+
out("session.form.list", { sessionID: OTHER }),
4947+
replyData("session.form.list", []),
4948+
...backgroundLaunch(CHILD),
4949+
event("session.execution.succeeded", { sessionID: SESSION }),
4950+
event("session.execution.succeeded", { sessionID: CHILD }),
4951+
childReport("msg_report", "CHILD_OK"),
4952+
event("session.execution.started", { sessionID: SESSION }),
4953+
event("session.inbox.delivered", { sessionID: SESSION, inboxID: "msg_report" }),
4954+
event("form.created", { form: colorForm }),
4955+
// Handled after the form, so its update proves the form reached the adapter.
4956+
event("session.model.selected", {
4957+
sessionID: OTHER,
4958+
model: { providerID: "opencode", id: "big-pickle", variant: "none" },
4959+
}),
4960+
// Released once the continuation started, so its update follows the replay.
4961+
event(
4962+
"session.model.selected",
4963+
{
4964+
sessionID: OTHER,
4965+
model: { providerID: "opencode", id: "big-pickle", variant: "thinking" },
4966+
},
4967+
"continued",
4968+
),
4969+
out("session.form.reply", {
4970+
sessionID: SESSION,
4971+
formID: colorForm.id,
4972+
answer: { q0: "Red" },
4973+
}),
4974+
reply("session.form.reply", null),
4975+
event("session.execution.succeeded", { sessionID: SESSION }),
4976+
],
4977+
{ replayGate: gate },
4978+
).pipe(
4979+
Effect.provideService(ProviderContinuationRequests.ProviderContinuationRequests, {
4980+
offer: (request) => Deferred.succeed(offered, request).pipe(Effect.asVoid),
4981+
take: Effect.never,
4982+
}),
4983+
);
4984+
yield* runtime.resumeThread({
4985+
providerThread: {
4986+
...thread,
4987+
id: ProviderThreadId.make("provider-thread:opencode2-adapter:other"),
4988+
nativeThreadRef: { driver: OPENCODE_PROVIDER, nativeId: OTHER, strength: "strong" },
4989+
},
4990+
threadId,
4991+
modelSelection: bigPickle,
4992+
runtimePolicy: policy(),
4993+
});
4994+
const collected: Array<ProviderAdapter.ProviderAdapterV2Event> = [];
4995+
const formSeen = yield* Deferred.make<void>();
4996+
const replayed = yield* Deferred.make<void>();
4997+
const ended = yield* Deferred.make<void>();
4998+
const otherVariant = (event: ProviderAdapter.ProviderAdapterV2Event) =>
4999+
event.type === "provider_thread.updated" &&
5000+
event.providerThread.nativeThreadRef?.nativeId === OTHER
5001+
? event.providerThread.nativeMetadata?.modelSelection?.options?.[0]?.value
5002+
: undefined;
5003+
yield* runtime.events.pipe(
5004+
Stream.tap((event) =>
5005+
Effect.gen(function* () {
5006+
collected.push(event);
5007+
if (otherVariant(event) === "none") yield* Deferred.succeed(formSeen, undefined);
5008+
if (otherVariant(event) === "thinking") yield* Deferred.succeed(replayed, undefined);
5009+
if (collected.filter((entry) => entry.type === "turn.terminal").length === 2) {
5010+
yield* Deferred.succeed(ended, undefined);
5011+
}
5012+
}),
5013+
),
5014+
Stream.runDrain,
5015+
Effect.forkScoped,
5016+
);
5017+
yield* runtime.startTurn(withLineage(thread));
5018+
const offer = yield* Deferred.await(offered);
5019+
yield* Deferred.await(formSeen);
5020+
yield* runtime.startTurn(continuationTurn(thread, offer));
5021+
gate.release("continued");
5022+
yield* Deferred.await(replayed);
5023+
const requests = collected.flatMap((event) =>
5024+
event.type === "runtime_request.updated" && event.runtimeRequest.status === "pending"
5025+
? [event.runtimeRequest]
5026+
: [],
5027+
);
5028+
assert.deepEqual(
5029+
requests.map((request) => request.nativeRequestRef?.nativeId),
5030+
[colorForm.id],
5031+
);
5032+
yield* runtime.respondToRuntimeRequest({
5033+
requestId: requests[0]!.id,
5034+
answers: { q0: "Red" },
5035+
});
5036+
yield* Deferred.await(ended);
5037+
const last = collected.findLast((event) => event.type === "turn.terminal");
5038+
assert.equal(last?.type === "turn.terminal" ? last.status : undefined, "completed");
5039+
}).pipe(Effect.scoped),
5040+
);
5041+
49345042
it.effect("ends a follow-up turn a steer joined exactly once", () =>
49355043
Effect.gen(function* () {
49365044
const reportText = `<subagent sessionID="${CHILD}" state="completed" description="Sleep">\nCHILD_OK\n</subagent>`;

‎apps/server/src/provider/antigravityUsageLimits.test.ts‎

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ const fixture = Effect.fn("AntigravityUsageTest.fixture")(function* (
6565
userId?: string;
6666
userInfoAt?: number;
6767
missingToken?: boolean;
68-
authMethod?: "oauth-personal" | "gemini-api-key";
68+
authMethod?: "oauth-personal" | "oauth-business" | "gemini-api-key";
6969
} = {},
7070
) {
7171
const fs = yield* FileSystem.FileSystem;
@@ -330,11 +330,12 @@ describe("Antigravity subscription limits", () => {
330330
}).pipe(Effect.scoped, Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))),
331331
);
332332

333-
// Oracle: the existing endpoint merge keeps the most-used reading.
334-
it.effect("keeps the used endpoint reading and its reset over an untouched reading", () =>
333+
// Oracle: workspace sign-ins are metered on cloudcode-pa, so its reading wins even when less used.
334+
it.effect("reports a business account's quota from the endpoint it is metered on", () =>
335335
Effect.gen(function* () {
336336
yield* TestClock.setTime(DateTime.toEpochMillis(DateTime.makeUnsafe("2026-10-21T10:16:04Z")));
337337
const { probe } = yield* fixture({
338+
authMethod: "oauth-business",
338339
summaryByHost: {
339340
"daily-cloudcode-pa.googleapis.com": {
340341
buckets: [
@@ -383,9 +384,8 @@ describe("Antigravity subscription limits", () => {
383384
id: "3p-weekly",
384385
label: "Claude & GPT (shared) · Weekly",
385386
kind: "weekly",
386-
usedPercent: 50,
387+
usedPercent: 0,
387388
windowDurationMins: 10080,
388-
resetsAt: "2026-10-27T10:16:04.000Z",
389389
},
390390
]);
391391
}).pipe(Effect.scoped, Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))),
@@ -474,7 +474,43 @@ describe("Antigravity subscription limits", () => {
474474
const byId = new Map(limits.windows.map((window) => [window.id, window]));
475475
expect(byId.get("gemini-weekly")?.label).toBe("Gemini · Weekly");
476476
expect(byId.get("3p-5h")?.usedPercent).toBeCloseTo(70);
477-
expect(byId.get("3p-weekly")?.usedPercent).toBe(100);
477+
expect(byId.get("3p-weekly")?.usedPercent).toBe(50);
478+
}).pipe(Effect.scoped, Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))),
479+
);
480+
481+
// Oracle: reported payloads for a personal sign-in, whose runtime meters on the daily endpoint.
482+
it.effect("reports a personal account's quota from the daily endpoint it is metered on", () =>
483+
Effect.gen(function* () {
484+
yield* TestClock.setTime(DateTime.toEpochMillis(DateTime.makeUnsafe("2026-11-07T12:00:00Z")));
485+
const argon = (remainingFraction: number, resetTime: string) => ({
486+
groups: [
487+
{
488+
displayName: "Gemini 4 Argon",
489+
buckets: [
490+
{
491+
bucketId: "gemini-argon-wtu-weekly",
492+
window: "weekly",
493+
remainingFraction,
494+
resetTime,
495+
},
496+
],
497+
},
498+
],
499+
});
500+
const { probe } = yield* fixture({
501+
authMethod: "oauth-personal",
502+
summaryByHost: {
503+
"daily-cloudcode-pa.googleapis.com": argon(0.8623059, "2026-11-14T08:41:35Z"),
504+
"cloudcode-pa.googleapis.com": argon(0, "2026-11-08T18:27:14Z"),
505+
},
506+
});
507+
expect((yield* probe).windows).toEqual([
508+
expect.objectContaining({
509+
id: "gemini-argon-wtu-weekly",
510+
usedPercent: expect.closeTo(13.77, 2),
511+
resetsAt: "2026-11-14T08:41:35.000Z",
512+
}),
513+
]);
478514
}).pipe(Effect.scoped, Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))),
479515
);
480516

‎apps/server/src/provider/antigravityUsageLimits.ts‎

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,14 @@ import {
1515
makeUsageLimits,
1616
} from "@t3tools/provider-core/server/usageLimits";
1717

18-
const ENDPOINTS = [
19-
"https://daily-cloudcode-pa.googleapis.com",
20-
"https://cloudcode-pa.googleapis.com",
21-
];
18+
const DAILY_ENDPOINT = "https://daily-cloudcode-pa.googleapis.com";
19+
const PROD_ENDPOINT = "https://cloudcode-pa.googleapis.com";
20+
// The ACP runtime meters consumer tiers on the daily host and GCP-terms tiers on prod.
21+
// The sign-in method stands in for the tier.
22+
const ENDPOINTS = {
23+
"oauth-personal": [DAILY_ENDPOINT, PROD_ENDPOINT],
24+
"oauth-business": [PROD_ENDPOINT, DAILY_ENDPOINT],
25+
};
2226
const SUMMARY_WINDOW_MINS = new Map([
2327
["5h", 5 * 60],
2428
["weekly", 7 * 24 * 60],
@@ -269,7 +273,8 @@ export const makeAntigravityUsageProbe = Effect.fn("makeAntigravityUsageProbe")(
269273
accessToken = cached.accessToken;
270274
account = cached.account;
271275
}
272-
// Merge endpoints because quota groups differ; keep each bucket's most-used reading.
276+
const endpoints = ENDPOINTS[input.authMethod];
277+
// Merge endpoints because quota groups differ; the metered host's reading of a bucket wins.
273278
const fetchWindows = Effect.fn("AntigravityUsageProbe.fetchWindows")(function* <E>(
274279
operation: string,
275280
parse: (
@@ -278,7 +283,7 @@ export const makeAntigravityUsageProbe = Effect.fn("makeAntigravityUsageProbe")(
278283
) => Effect.Effect<ServerProviderUsageWindow[], E>,
279284
) {
280285
const responses = yield* Effect.forEach(
281-
ENDPOINTS,
286+
endpoints,
282287
(endpoint) =>
283288
Effect.gen(function* () {
284289
// Capture each request after auth, so refresh latency does not widen the tolerance.
@@ -302,8 +307,7 @@ export const makeAntigravityUsageProbe = Effect.fn("makeAntigravityUsageProbe")(
302307
);
303308
const windows = new Map<string, ServerProviderUsageWindow>();
304309
for (const window of responses.flat()) {
305-
const previous = windows.get(window.id);
306-
if (!previous || window.usedPercent > previous.usedPercent) windows.set(window.id, window);
310+
if (!windows.has(window.id)) windows.set(window.id, window);
307311
}
308312
return [...windows.values()];
309313
});

‎apps/server/src/vcs/GitVcsDriver.test.ts‎

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,33 @@ it.effect("checkpoint capture skips an ignored project while keeping its allowed
406406
}).pipe(Effect.scoped, Effect.provide(layerGitContract)),
407407
);
408408

409+
it.effect.each([
410+
{ workspace: "the repository root", subdirectory: "" },
411+
{ workspace: "a subdirectory", subdirectory: "sub" },
412+
])(
413+
"checkpoint capture keeps new files in $workspace when the root .gitignore has a blank CRLF line",
414+
({ subdirectory }) =>
415+
Effect.gen(function* () {
416+
const fs = yield* FileSystem.FileSystem;
417+
const path = yield* Path.Path;
418+
const driver = yield* GitVcsDriver.makeVcsDriverShape();
419+
const parent = yield* fs.makeTempDirectoryScoped({ prefix: "t3-checkpoint-crlf-ignore-" });
420+
const { git, checkpointRef } = yield* makeCheckpointFixture(driver, parent);
421+
yield* fs.writeFileString(path.join(parent, ".gitignore"), "a.txt\r\n\r\nb.txt\r\n");
422+
const cwd = path.join(parent, subdirectory);
423+
yield* fs.makeDirectory(cwd, { recursive: true });
424+
yield* fs.writeFileString(path.join(cwd, "notes.md"), "notes\n");
425+
const notesPath = subdirectory === "" ? "notes.md" : `${subdirectory}/notes.md`;
426+
427+
yield* driver.checkpoints.captureCheckpoint({ cwd, checkpointRef });
428+
429+
assert.include(
430+
(yield* git(["ls-tree", "-r", "--name-only", checkpointRef])).stdout.split("\n"),
431+
notesPath,
432+
);
433+
}).pipe(Effect.scoped, Effect.provide(layerGitContract)),
434+
);
435+
409436
it.effect.each([
410437
{ tracking: "committed-only", committed: ["committed.txt"], staged: [] },
411438
{ tracking: "staged-only", committed: [], staged: ["staged.txt"] },
@@ -1007,7 +1034,6 @@ it.effect.each(["committed", "unborn"] as const)(
10071034
"rev-parse",
10081035
"config",
10091036
...(head === "committed" ? ["read-tree", "ls-files"] : []),
1010-
"check-ignore",
10111037
"add",
10121038
"write-tree",
10131039
"commit-tree",
@@ -1060,13 +1086,13 @@ it.effect.skipIf(HostProcess.Platform.defaultValue() === "win32")(
10601086
const commands = yield* captureRecordingGitCommands(cwd, checkpointRef);
10611087

10621088
assert.deepStrictEqual(commands, [
1089+
"rev-parse",
10631090
"rev-parse",
10641091
"rev-parse",
10651092
"config",
10661093
"rev-parse",
10671094
"read-tree",
10681095
"ls-files",
1069-
"check-ignore",
10701096
"add",
10711097
"write-tree",
10721098
"commit-tree",

‎apps/server/src/vcs/GitVcsDriver.ts‎

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -872,6 +872,7 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* (
872872
"--git-common-dir",
873873
"--git-path",
874874
"index",
875+
"--show-prefix",
875876
"--verify",
876877
"--quiet",
877878
"HEAD",
@@ -881,19 +882,27 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* (
881882
const headExists = result.exitCode === 0;
882883
const headChecked = headExists || result.exitCode === 1;
883884
const lines = result.stdout.split("\n");
884-
const [gitCommonDir = "", indexPath = ""] = lines;
885-
if (headChecked && lines.length === (headExists ? 4 : 3) && lines.at(-1) === "") {
885+
const [gitCommonDir = "", indexPath = "", prefix = ""] = lines;
886+
if (headChecked && lines.length === (headExists ? 5 : 4) && lines.at(-1) === "") {
886887
return {
887888
gitCommonDir: gitCommonDir.trim(),
888889
indexPath: indexPath.trim(),
890+
prefix,
889891
headExists,
890892
};
891893
}
892894
// Git before 2.31 echoes --path-format, and a path containing a newline spans lines.
893895
// Separate commands read the paths as before and report a failure the same way.
896+
const fallbackCommonDir = yield* resolveGitCommonDir(cwd);
897+
const prefixResult = yield* execute({
898+
operation: VcsProcess.CHECKPOINT_CAPTURE_OPERATION,
899+
cwd,
900+
args: ["rev-parse", "--show-prefix"],
901+
});
894902
return {
895-
gitCommonDir: yield* resolveGitCommonDir(cwd),
903+
gitCommonDir: fallbackCommonDir,
896904
indexPath: undefined,
905+
prefix: prefixResult.stdout.replace(/\n$/, ""),
897906
headExists: headChecked ? headExists : yield* hasHeadCommit(cwd),
898907
};
899908
});
@@ -930,7 +939,9 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* (
930939
"-c",
931940
"splitIndex.sharedIndexExpire=never",
932941
];
933-
const { gitCommonDir, indexPath, headExists } = yield* resolveCaptureRepository(input.cwd);
942+
const { gitCommonDir, indexPath, prefix, headExists } = yield* resolveCaptureRepository(
943+
input.cwd,
944+
);
934945
const indexId = yield* random.uuidV4();
935946
const tempIndexPath = path.join(gitCommonDir, `t3-checkpoint-index-${indexId}`);
936947
const hostEnv = yield* HostProcess.Environment;
@@ -1123,7 +1134,12 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* (
11231134
}
11241135
}
11251136

1126-
const workspaceIgnored = (yield* filterIgnoredPaths(input.cwd, ["."])).length === 0;
1137+
// The working-tree root is never ignored. Probe a subdirectory without the trailing slash
1138+
// Git adds to ".", which a blank or whitespace-only ignore line matches as an empty pattern.
1139+
const workspaceIgnored =
1140+
prefix !== "" &&
1141+
(yield* filterIgnoredPaths(input.cwd, [`../${prefix.slice(0, -1).split("/").at(-1)}`]))
1142+
.length === 0;
11271143
if (workspaceIgnored) {
11281144
// HEAD omits staged-only paths. Seed just this workspace's additions, keeping
11291145
// unrelated staged changes and the scratch index's sparse flags untouched.

0 commit comments

Comments
 (0)