Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 27 additions & 5 deletions apps/server/src/orchestration-v2/Orchestrator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -534,8 +534,10 @@ function withPullRequestWatch(
link: ThreadPullRequestLink,
watch: ThreadPullRequestWatch | undefined,
): ThreadPullRequestLink {
const { watch: _previous, ...rest } = link;
return watch === undefined ? rest : { ...rest, watch };
const { watch: previous, endedWatch, ...rest } = link;
if (watch !== undefined) return { ...rest, watch };
const ended = previous ?? endedWatch;
return ended === undefined ? rest : { ...rest, endedWatch: ended };
}

function legacyPullRequestLink(
Expand All @@ -544,6 +546,9 @@ function legacyPullRequestLink(
now: DateTime.Utc,
): ThreadPullRequestLink {
const key = legacyThreadPullRequestKey(linked);
const existing = threadPullRequestsOf(thread).find((link) =>
threadPullRequestKeysEqual(link, key),
);
return withPullRequestWatch(
{
...key,
Expand All @@ -552,8 +557,9 @@ function legacyPullRequestLink(
linkedAt: DateTime.formatIso(now),
snapshot: null,
stack: null,
...(existing?.endedWatch && { endedWatch: existing.endedWatch }),
},
threadPullRequestsOf(thread).find((link) => threadPullRequestKeysEqual(link, key))?.watch,
existing?.watch,
);
}

Expand Down Expand Up @@ -3104,6 +3110,7 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
const linked = threadPullRequestsOf(thread);
const visible = (link: ThreadPullRequestLink) =>
link.source !== "stack-dismissed" && threadPullRequestKeysEqual(link, key);
const dismissed = linked.find((link) => threadPullRequestKeysEqual(link, key));
const links =
command.type === "thread.pull-request.watch" &&
command.watching &&
Expand All @@ -3118,6 +3125,7 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
linkedAt: startedAt,
snapshot: null,
stack: null,
...(dismissed?.endedWatch && { endedWatch: dismissed.endedWatch }),
},
]
: linked;
Expand All @@ -3136,16 +3144,30 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
failedChecks: [],
passed: false,
passedChecks: [],
conflicting: false,
// Watching again must not repeat check or conflict news the last watch told.
...(existing.endedWatch && {
headSha: existing.endedWatch.headSha,
failedChecks: existing.endedWatch.failedChecks,
passed: existing.endedWatch.passed,
passedChecks: existing.endedWatch.passedChecks,
conflicting: existing.endedWatch.conflicting,
}),
remarksThrough: startedAt,
remarkIds: [],
conflicting: false,
wakes: 0,
});
if (watch === existing.watch && links === linked) return thread;
const final =
command.type === "thread.pull-request-watch.sync" && watch === undefined
? command.endedWatch
: undefined;
return {
...thread,
pullRequests: links.map((link) =>
link === existing ? withPullRequestWatch(link, watch) : link,
link === existing
? withPullRequestWatch(final ? { ...link, watch: final } : link, watch)
: link,
),
updatedAt: command.type === "thread.pull-request.watch" ? now : thread.updatedAt,
};
Expand Down
24 changes: 14 additions & 10 deletions apps/server/src/orchestration-v2/PullRequestWatchReactor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ export const make = Effect.gen(function* () {
target: WatchTarget,
next: ThreadPullRequestWatch | null,
wake?: { readonly text: string; readonly notification: OrchestrationV2Notification },
endedWatch?: ThreadPullRequestWatch,
) =>
Effect.gen(function* () {
const uuid = yield* crypto.randomUUIDv4();
Expand All @@ -269,6 +270,7 @@ export const make = Effect.gen(function* () {
...identityOf(target.link),
startedAt: target.watch.startedAt,
watch: next,
...(endedWatch === undefined ? {} : { endedWatch }),
...(wake === undefined
? {}
: { wake: { ...wake, messageId: MessageId.make(`message:pr-watch:${uuid}`) } }),
Expand Down Expand Up @@ -477,16 +479,18 @@ export const make = Effect.gen(function* () {
yield* eachTarget(group, (target) => {
const report = evaluatePullRequestWatch(target.watch, detail, remarks);
if (report.changes.length > 0) {
return record(
target,
report.exhausted ? null : report.next,
pullRequestWatchMessage({
number: target.link.number,
url: target.link.url,
baseBranch: detail.baseBranch,
headSha: report.next.headSha,
report,
}),
const wake = pullRequestWatchMessage({
number: target.link.number,
url: target.link.url,
baseBranch: detail.baseBranch,
headSha: report.next.headSha,
report,
});
// An ending watch keeps what this pass saw, so watching again starts from it.
return (
report.exhausted
? record(target, null, wake, report.next)
: record(target, report.next, wake)
).pipe(
Effect.tap(() => woke(target)),
Effect.tap(() => (report.exhausted ? ended(target, "comment-limit") : Effect.void)),
Expand Down
Loading
Loading