The best way to control Claude Code, Codex and more from any computer or phone
fix(bitbucket): page through pull requests that share a millisecond (#23635)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: maria-rcks <maria@kuuro.net>
Victor Vogel committed
Oct 31, 2026 at 03:39 UTC
2296a4aee8f5154b7403f2ab57bbbca04190a0b4
3 files changed
+38
-11
packages/source-control-bitbucket/src/server/BitbucketPullRequestApi.test.ts
+1
-1
@@ -148,7 +148,7 @@ layer("BitbucketPullRequestApi.layer", (it) => {
148
});
149
150
expect(filterOfCall(0)).toBe(
151
- '(title ~ "page" OR description ~ "page") AND updated_on <= 2026-07-02T00:00:00+00:00',
151
+ '(title ~ "page" OR description ~ "page") AND updated_on < 2026-07-02T00:00:00.001Z',
152
);
153
}),
154
);
packages/source-control-bitbucket/src/server/BitbucketPullRequestApi.ts
+13
-2
@@ -1,10 +1,12 @@
1
import { isCommitSha } from "@t3tools/source-control-core/server/pullRequestUtils";
2
import * as Cache from "effect/Cache";
3
import * as Context from "effect/Context";
4
+import * as DateTime from "effect/DateTime";
5
import * as Duration from "effect/Duration";
6
import * as Effect from "effect/Effect";
7
import * as Exit from "effect/Exit";
8
import * as Layer from "effect/Layer";
9
+import * as Option from "effect/Option";
10
import * as Result from "effect/Result";
11
import * as Schema from "effect/Schema";
12
import type {
@@ -326,6 +328,15 @@ function filterLiteral(value: string): string {
328
return value.replaceAll("\\", "\\\\").replaceAll('"', '\\"');
329
}
330
331
+// Bitbucket keeps microseconds; include the cursor's whole millisecond before excluding seen IDs.
332
+function updatedBeforeFilter(updatedBefore: string): string {
333
+ return Option.match(DateTime.make(updatedBefore), {
334
+ onNone: () => `updated_on <= ${updatedBefore}`,
335
+ onSome: (instant) =>
336
+ `updated_on < ${DateTime.formatIso(DateTime.add(instant, { milliseconds: 1 }))}`,
337
+ });
338
+}
339
+
340
function mergeStrategy(method: PullRequestMergeMethod | undefined): string {
341
switch (method) {
342
case "squash":
@@ -545,12 +556,12 @@ export const make = Effect.gen(function* () {
556
listPullRequests: Effect.fn("BitbucketPullRequestApi.listPullRequests")(function (input) {
557
return withRepository(input.repository, (path) => {
558
const search = input.query?.trim() ?? "";
548
- // Exclude already-sent IDs at the inclusive timestamp before applying the page limit.
559
+ // Exclude already-sent IDs in the boundary millisecond before applying the page limit.
560
const predicates = [
561
...(search.length === 0 ? [] : [searchFilter(search)]),
562
...(input.author === undefined ? [] : [authorFilter(input.author)]),
563
...(input.draft === undefined ? [] : [`draft = ${input.draft}`]),
553
- ...(input.cursor === undefined ? [] : [`updated_on <= ${input.cursor.updatedBefore}`]),
564
+ ...(input.cursor === undefined ? [] : [updatedBeforeFilter(input.cursor.updatedBefore)]),
565
...(input.cursor?.seenAt ?? []).map((number) => `id != ${number}`),
566
];
567
return listPage({
packages/source-control-bitbucket/src/server/BitbucketPullRequestProvider.listing.test.ts
+24
-8
@@ -8,14 +8,18 @@ import * as BitbucketPullRequestProvider from "./BitbucketPullRequestProvider.ts
8
9
it.effect("pages through rows that share an update instant by excluding those already sent", () =>
10
Effect.gen(function* () {
11
- const boundary = "2026-10-12T00:00:00.000Z";
12
- const older = "2026-10-11T00:00:00.000Z";
11
+ // Bitbucket stamps to the microsecond; 3 shares 1 and 2's millisecond but sorts after them.
12
+ const boundary = "2026-10-12T00:00:00.000500+00:00";
13
+ const sameMillisecond = "2026-10-12T00:00:00.000200+00:00";
14
+ const older = "2026-10-11T00:00:00.000000+00:00";
15
+ const micros = (stamp: string) =>
16
+ Date.parse(stamp) * 1000 + Number(/\.\d{3}(\d{3})/.exec(stamp)?.[1] ?? 0);
17
const rows = [1, 2, 3, 4, 5].map((id) => ({
18
id,
19
title: `Pull request ${id}`,
20
state: "OPEN",
21
created_on: older,
18
- updated_on: id <= 3 ? boundary : older,
22
+ updated_on: id <= 2 ? boundary : id === 3 ? sameMillisecond : older,
23
source: { branch: { name: `feat/${id}` } },
24
destination: { branch: { name: "main" } },
25
links: { html: { href: `https://bitbucket.org/acme/web/pull-requests/${id}` } },
@@ -30,13 +34,16 @@ it.effect("pages through rows that share an update instant by excluding those al
34
const filter =
35
new URL(url, "https://api.bitbucket.org").searchParams.get("q") ?? "";
36
filters.push(filter);
33
- const updatedBefore = /updated_on <= (\S+)/.exec(filter)?.[1];
37
+ const [, operator, bound] = /updated_on (<=?) (\S+)/.exec(filter) ?? [];
38
const excluded = new Set(
39
Array.from(filter.matchAll(/id != (\d+)/g), (match) => Number(match[1])),
40
);
41
const values = rows.filter(
42
(row) =>
39
- (updatedBefore === undefined || row.updated_on <= updatedBefore) &&
43
+ (bound === undefined ||
44
+ (operator === "<"
45
+ ? micros(row.updated_on) < micros(bound)
46
+ : micros(row.updated_on) <= micros(bound))) &&
47
!excluded.has(row.id),
48
);
49
return Effect.succeed({ body: JSON.stringify({ values }), truncated: false });
@@ -69,16 +76,25 @@ it.effect("pages through rows that share an update instant by excluding those al
76
);
77
assert.isTrue(first.truncated);
78
72
- const second = yield* list({ updatedBefore: boundary, delivered: 2, seenAt: [1, 2] });
79
+ // The cursor carries the instant cut to the millisecond, as the app normalizes it.
80
+ const second = yield* list({
81
+ updatedBefore: "2026-10-12T00:00:00.000Z",
82
+ delivered: 2,
83
+ seenAt: [1, 2],
84
+ });
85
assert.deepStrictEqual(
86
second.items.map((item) => item.number),
87
[3, 4],
88
);
77
- assert.include(filters.at(-1), `updated_on <= ${boundary}`);
89
+ assert.include(filters.at(-1), "updated_on < 2026-10-12T00:00:00.001Z");
90
assert.include(filters.at(-1), "id != 1");
91
assert.include(filters.at(-1), "id != 2");
92
81
- const last = yield* list({ updatedBefore: older, delivered: 4, seenAt: [4] });
93
+ const last = yield* list({
94
+ updatedBefore: "2026-10-11T00:00:00.000Z",
95
+ delivered: 4,
96
+ seenAt: [4],
97
+ });
98
assert.deepStrictEqual(
99
last.items.map((item) => item.number),
100
[5],