GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(cursor): start page timeout after acquiring request slot · pingdotgg/t3code@f53dbf2

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • packages/provider-cursor/src/server
    • accountUsage.test.ts
    • accountUsage.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎packages/provider-cursor/src/server/accountUsage.test.ts‎

Copy file name to clipboardExpand all lines: packages/provider-cursor/src/server/accountUsage.test.ts
+71-31Lines changed: 71 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as NodeServices from "@effect/platform-node/NodeServices";
33
import * as Layer from "effect/Layer";
44
import { assert, describe, it } from "@effect/vitest";
55
import * as Deferred from "effect/Deferred";
6+
import * as Queue from "effect/Queue";
67
import * as Context from "effect/Context";
78
import * as Effect from "effect/Effect";
89
import * as Fiber from "effect/Fiber";
@@ -510,37 +511,76 @@ describe("readCursorAccountUsage", () => {
510511
}).pipe(Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))),
511512
);
512513

513-
it.effect("reads the pages behind the first together and keeps them in page order", () =>
514-
Effect.gen(function* () {
515-
const accessToken = `header.${Buffer.from(JSON.stringify({ sub: "auth|demo" })).toString("base64url")}.signature`;
516-
let inFlight = 0;
517-
let mostInFlight = 0;
518-
const result = yield* readAccountUsage(
519-
{ kind: "apiKey", apiKey: accessToken },
520-
0,
521-
1781000000000,
522-
async ({ page }) => {
523-
inFlight++;
524-
mostInFlight = Math.max(mostInFlight, inFlight);
525-
for (let turn = page; turn < 9; turn++) await Promise.resolve();
526-
inFlight--;
527-
return Response.json({
528-
totalUsageEventsCount: 8001,
529-
usageEventsDisplay: Array.from({ length: page === 9 ? 1 : 1000 }, (_, index) => ({
530-
timestamp: String(1780000000000 + (page - 1) * 1000 + index),
531-
model: "gpt-5",
532-
tokenUsage: { inputTokens: 1 },
533-
})),
534-
});
535-
},
536-
);
537-
assert.isNull(result.error);
538-
assert.strictEqual(mostInFlight, 6);
539-
assert.deepStrictEqual(
540-
result.records.map((record) => record.timestampMs),
541-
Array.from({ length: 8001 }, (_, index) => 1780000000000 + index),
542-
);
543-
}).pipe(Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))),
514+
it.effect.each([{ queued: false }, { queued: true }])(
515+
"reads concurrent pages in order with a full request deadline after queuing: $queued",
516+
({ queued }) =>
517+
Effect.gen(function* () {
518+
const accessToken = `header.${Buffer.from(JSON.stringify({ sub: "auth|demo" })).toString("base64url")}.signature`;
519+
const started = yield* Queue.unbounded<void>();
520+
const firstBatch = yield* Deferred.make<void>();
521+
const secondBatch = yield* Deferred.make<void>();
522+
let delayedRequests = 0;
523+
let inFlight = 0;
524+
let mostInFlight = 0;
525+
const client = dashboard(
526+
async ({ page }) => {
527+
inFlight++;
528+
mostInFlight = Math.max(mostInFlight, inFlight);
529+
for (let turn = page; turn < 9; turn++) await Promise.resolve();
530+
inFlight--;
531+
return Response.json({
532+
totalUsageEventsCount: 8001,
533+
usageEventsDisplay: Array.from({ length: page === 9 ? 1 : 1000 }, (_, index) => ({
534+
timestamp: String(1780000000000 + (page - 1) * 1000 + index),
535+
model: "gpt-5",
536+
tokenUsage: { inputTokens: 1 },
537+
})),
538+
});
539+
},
540+
{ userId: 42, teamIds: queued ? [7] : [] },
541+
).pipe(
542+
HttpClient.transform((response, request) => {
543+
if (!queued || !request.url.endsWith("/GetFilteredUsageEvents")) return response;
544+
const body =
545+
request.body._tag === "Uint8Array"
546+
? JSON.parse(new TextDecoder().decode(request.body.body))
547+
: {};
548+
if (body.page === 1) return response;
549+
return Effect.gen(function* () {
550+
const batch = delayedRequests++ < 6 ? firstBatch : secondBatch;
551+
yield* Queue.offer(started, undefined);
552+
yield* Deferred.await(batch);
553+
return yield* response;
554+
});
555+
}),
556+
);
557+
const read = yield* Effect.forkChild(
558+
makeCursorAccountUsageReader.pipe(
559+
Effect.flatMap((reader) =>
560+
reader({ kind: "apiKey", apiKey: accessToken }, 0, 1781000000000),
561+
),
562+
Effect.provideService(HttpClient.HttpClient, client),
563+
),
564+
);
565+
if (queued) {
566+
yield* Effect.all(Array.from({ length: 6 }, () => Queue.take(started)));
567+
yield* TestClock.adjust("6 seconds");
568+
yield* Deferred.succeed(firstBatch, undefined);
569+
yield* Effect.all(Array.from({ length: 6 }, () => Queue.take(started)));
570+
yield* TestClock.adjust("6 seconds");
571+
yield* Deferred.succeed(secondBatch, undefined);
572+
}
573+
const result = yield* Fiber.join(read);
574+
assert.isNull(result.error);
575+
assert.strictEqual(mostInFlight, 6);
576+
assert.deepStrictEqual(
577+
result.records.map((record) => record.timestampMs),
578+
Array.from(
579+
{ length: queued ? 16002 : 8001 },
580+
(_, index) => 1780000000000 + (index % 8001),
581+
),
582+
);
583+
}).pipe(Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))),
544584
);
545585

546586
it.effect("ends like a page-by-page read when a page fails, leaving no request open", () =>
Collapse file

‎packages/provider-cursor/src/server/accountUsage.ts‎

Copy file name to clipboardExpand all lines: packages/provider-cursor/src/server/accountUsage.ts
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,11 +266,11 @@ export const makeCursorAccountUsageReader = Effect.gen(function* () {
266266
if (typeof count === "number") total = count;
267267
return events as unknown[];
268268
},
269-
pageSlots.withPermit,
270269
Effect.timeoutOrElse({
271270
duration: Duration.seconds(10),
272271
orElse: () => invalid("Account usage request timed out"),
273272
}),
273+
pageSlots.withPermit,
274274
);
275275
// Cursor caps a page at 1,000 events and takes about a second to answer one, so the pages
276276
// the first one's count implies are requested up to six ahead and consumed in page order.

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.