GeezerVison is showing github.com — fix(server): end deferred watch baselines when the head changes · pingdotgg/t3code@780c52f
File treeExpand file treeCollapse file tree Open diff view settings apps/server/src/orchestration-v2
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/Orchestrator.ts +10-12Lines changed: 10 additions & 12 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -3571,18 +3571,16 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio | 3571 | 3571 | passedChecks: [], | 3572 | 3572 | conflicting: false, | 3573 | 3573 | // Watching again must not repeat check or conflict news the last watch told. | 3574 | | - ...(existing.endedWatch | 3575 | | - ? { | 3576 | | - headSha: existing.endedWatch.headSha, | 3577 | | - failedChecks: existing.endedWatch.failedChecks, | 3578 | | - passed: existing.endedWatch.passed, | 3579 | | - passedChecks: existing.endedWatch.passedChecks, | 3580 | | - conflicting: existing.endedWatch.conflicting, | 3581 | | - ...(existing.endedWatch.awaitingBaseline && { | 3582 | | - awaitingBaseline: existing.endedWatch.awaitingBaseline, | 3583 | | - }), | 3584 | | - } | 3585 | | - : { awaitingBaseline: "all" as const }), | | 3574 | + ...(existing.endedWatch && { | | 3575 | + headSha: existing.endedWatch.headSha, | | 3576 | + failedChecks: existing.endedWatch.failedChecks, | | 3577 | + passed: existing.endedWatch.passed, | | 3578 | + passedChecks: existing.endedWatch.passedChecks, | | 3579 | + conflicting: existing.endedWatch.conflicting, | | 3580 | + }), | | 3581 | + awaitingBaseline: existing.endedWatch | | 3582 | + ? existing.endedWatch.awaitingBaseline | | 3583 | + : "all", | 3586 | 3584 | ...(existing.endedWatch?.owedChecks !== undefined && { | 3587 | 3585 | owedChecks: existing.endedWatch.owedChecks, | 3588 | 3586 | }), | |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/pullRequestWatch.test.ts +73Lines changed: 73 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -247,6 +247,72 @@ describe("evaluatePullRequestWatch", () => { | 247 | 247 | ); | 248 | 248 | }); | 249 | 249 |
| | 250 | + it.each(["success", "failure"] as const)( | | 251 | + "reports %s after a known head changes before checks were baselined", | | 252 | + (status) => { | | 253 | + const empty = evaluatePullRequestWatch( | | 254 | + watch({ awaitingBaseline: "all" }), | | 255 | + detail({ checks: [] }), | | 256 | + noRemarks, | | 257 | + ); | | 258 | + const pushed = evaluatePullRequestWatch( | | 259 | + empty.next, | | 260 | + detail({ headSha: "bbbbbbbbbb", checks: [] }), | | 261 | + noRemarks, | | 262 | + ); | | 263 | + assert.isUndefined(pushed.next.awaitingBaseline); | | 264 | + const result = evaluatePullRequestWatch( | | 265 | + pushed.next, | | 266 | + detail({ headSha: "bbbbbbbbbb", checks: [check("test", status)] }), | | 267 | + noRemarks, | | 268 | + ); | | 269 | + assert.deepEqual( | | 270 | + result.changes, | | 271 | + status === "success" | | 272 | + ? [{ kind: "checks-passed", count: 1, required: false }] | | 273 | + : [{ kind: "checks-failed", failed: [check("test", "failure")] }], | | 274 | + ); | | 275 | + const immediate = evaluatePullRequestWatch( | | 276 | + empty.next, | | 277 | + detail({ headSha: "bbbbbbbbbb", checks: [check("test", status)] }), | | 278 | + noRemarks, | | 279 | + ); | | 280 | + assert.deepEqual(immediate.changes, result.changes); | | 281 | + }, | | 282 | + ); | | 283 | + | | 284 | + it("reports pending advisory checks finishing after a required-check baseline", () => { | | 285 | + const initial = detail({ | | 286 | + checks: [{ ...check("test", "success"), required: true }, check("bot", "pending")], | | 287 | + }); | | 288 | + const baseline = evaluatePullRequestWatch( | | 289 | + watch({ awaitingBaseline: "all" }), | | 290 | + initial, | | 291 | + noRemarks, | | 292 | + ); | | 293 | + assert.deepEqual(baseline.changes, []); | | 294 | + const settled = evaluatePullRequestWatch( | | 295 | + baseline.next, | | 296 | + { | | 297 | + ...initial, | | 298 | + checks: [initial.checks[0]!, check("bot", "success")], | | 299 | + }, | | 300 | + noRemarks, | | 301 | + ); | | 302 | + assert.deepEqual(settled.changes, [{ kind: "checks-passed", count: 2, required: false }]); | | 303 | + assert.deepEqual( | | 304 | + evaluatePullRequestWatch( | | 305 | + settled.next, | | 306 | + { | | 307 | + ...initial, | | 308 | + checks: [initial.checks[0]!, check("bot", "success")], | | 309 | + }, | | 310 | + noRemarks, | | 311 | + ).changes, | | 312 | + [], | | 313 | + ); | | 314 | + }); | | 315 | + | 250 | 316 | it("reports each failure at once, even while another check never finishes", () => { | 251 | 317 | const bot = check("CodeRabbit", "pending"); | 252 | 318 | const first = detail({ checks: [check("lint", "failure"), check("test", "pending"), bot] }); | @@ -565,6 +631,13 @@ describe("evaluatePullRequestWatch", () => { | 565 | 631 | assert.deepEqual(pushed.flat(), ["no-checks"]); | 566 | 632 | }); | 567 | 633 |
| | 634 | + it("starts the no-checks clock while a fresh watch awaits its baseline", () => { | | 635 | + assert.deepEqual( | | 636 | + anHourLater(watch({ awaitingBaseline: "all" }), detail({ checks: [] })).flat(), | | 637 | + ["no-checks"], | | 638 | + ); | | 639 | + }); | | 640 | + | 568 | 641 | it("never reports missing checks on a host where an empty list says nothing", () => { | 569 | 642 | const silent = detail({ capabilities: capabilities(false), checks: [] }); | 570 | 643 | assert.isTrue(anHourLater(watch(), silent).every((kinds) => kinds.length === 0)); | |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/pullRequestWatch.ts +9-7Lines changed: 9 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -43,9 +43,8 @@ export function evaluatePullRequestWatch( | 43 | 43 | const changes: Array<PullRequestWatchChange> = []; | 44 | 44 | // A read without a head says nothing about pushes, so it keeps the last known one. | 45 | 45 | const headSha = detail.headSha ?? watch.headSha; | 46 | | - // Remarks already have their baseline in startedAt. | 47 | | - const checksBaseline = watch.awaitingBaseline !== undefined; | 48 | 46 | const headMoved = watch.headSha !== null && headSha !== watch.headSha; | | 47 | + const checksBaseline = watch.awaitingBaseline !== undefined && !headMoved; | 49 | 48 |
| 50 | 49 | // Hosts can return no checks on read failure; preserve prior state. | 51 | 50 | let failedChecks = headMoved ? [] : watch.failedChecks; | @@ -78,8 +77,10 @@ export function evaluatePullRequestWatch( | 78 | 77 | const settled = | 79 | 78 | failed.length === 0 && detail.checks.every((check) => check.status !== "pending"); | 80 | 79 | owedChecks = owed; | 81 | | - if (!checksBaseline && passedNow && (!passed || gateGrew)) { | 82 | | - changes.push({ kind: "checks-passed", count: gate.length, required: required.length > 0 }); | | 80 | + if (passedNow && (!passed || gateGrew)) { | | 81 | + if (!checksBaseline) { | | 82 | + changes.push({ kind: "checks-passed", count: gate.length, required: required.length > 0 }); | | 83 | + } | 83 | 84 | owedChecks = | 84 | 85 | required.length > 0 | 85 | 86 | ? detail.checks | @@ -100,9 +101,10 @@ export function evaluatePullRequestWatch( | 100 | 101 | // repository runs no checks at all, nothing waits. | 101 | 102 | let checksAwaitedSince = watch.checksAwaitedSince; | 102 | 103 | if (detail.capabilities.checksAlwaysReport === true) { | 103 | | - const awaitedBefore = headMoved | 104 | | - ? DateTime.formatIso(DateTime.makeUnsafe(now)) | 105 | | - : (watch.checksAwaitedSince ?? null); | | 104 | + const awaitedBefore = | | 105 | + headMoved || watch.awaitingBaseline === "all" | | 106 | + ? DateTime.formatIso(DateTime.makeUnsafe(now)) | | 107 | + : (watch.checksAwaitedSince ?? null); | 106 | 108 | checksAwaitedSince = detail.checks.length > 0 ? null : awaitedBefore; | 107 | 109 | const awaitedMs = checksAwaitedSince === null ? 0 : now - Date.parse(checksAwaitedSince); | 108 | 110 | if (awaitedMs >= PULL_REQUEST_WATCH_NO_CHECKS_MS) { | |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/runtimeLayer.test.ts +32-6Lines changed: 32 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -2673,6 +2673,7 @@ it.layer(layerTest)("OrchestrationV2LayerLive lifecycle", (it) => { | 2673 | 2673 | it.effect("baselines a new watch across restarts and reports later changes", () => | 2674 | 2674 | Effect.gen(function* () { | 2675 | 2675 | const orchestrator = yield* Orchestrator.OrchestratorV2; | | 2676 | + const worker = yield* EffectWorker.OrchestrationEffectWorkerV2; | 2676 | 2677 | const threadId = ThreadId.make("runtime-pull-request-watch-told"); | 2677 | 2678 | const projectId = ProjectId.make("pr-watch-told-project"); | 2678 | 2679 | yield* seedProject({ | @@ -2710,6 +2711,7 @@ it.layer(layerTest)("OrchestrationV2LayerLive lifecycle", (it) => { | 2710 | 2711 | yield* watch(true, "start"); | 2711 | 2712 |
| 2712 | 2713 | let headSha = "ad70160aaa"; | | 2714 | + let hasChecks = false; | 2713 | 2715 | const host = Layer.mergeAll( | 2714 | 2716 | NodeServices.layer, | 2715 | 2717 | Layer.mock(PullRequestService.PullRequestService)({ | @@ -2721,7 +2723,7 @@ it.layer(layerTest)("OrchestrationV2LayerLive lifecycle", (it) => { | 2721 | 2723 | at: "2026-10-02T12:00:00.000Z", | 2722 | 2724 | }), | 2723 | 2725 | headSha, | 2724 | | - checks: ["lint", "test"].map((name) => ({ | | 2726 | + checks: (hasChecks ? ["lint", "test"] : []).map((name) => ({ | 2725 | 2727 | name, | 2726 | 2728 | status: "success" as const, | 2727 | 2729 | description: null, | @@ -2746,32 +2748,56 @@ it.layer(layerTest)("OrchestrationV2LayerLive lifecycle", (it) => { | 2746 | 2748 |
| 2747 | 2749 | const reactor = yield* PullRequestWatchReactor.make.pipe(Effect.provide(host)); | 2748 | 2750 | yield* reactor.sweep; | | 2751 | + yield* worker.drain(); | | 2752 | + assert.deepEqual(yield* summaries, []); | | 2753 | + assert.equal( | | 2754 | + (yield* orchestrator.getThreadShell(threadId))?.pullRequests?.[0]?.watch?.awaitingBaseline, | | 2755 | + "checks", | | 2756 | + ); | | 2757 | + yield* watch(false, "stop-before-baseline"); | | 2758 | + yield* watch(true, "resume-before-baseline"); | | 2759 | + const waitingRestart = yield* PullRequestWatchReactor.make.pipe(Effect.provide(host)); | | 2760 | + yield* waitingRestart.sweep; | | 2761 | + yield* worker.drain(); | | 2762 | + assert.equal( | | 2763 | + (yield* orchestrator.getThreadShell(threadId))?.pullRequests?.[0]?.watch?.awaitingBaseline, | | 2764 | + "checks", | | 2765 | + ); | | 2766 | + hasChecks = true; | | 2767 | + yield* TestClock.adjust("10 minutes"); | | 2768 | + yield* waitingRestart.sweep; | | 2769 | + yield* worker.drain(); | 2749 | 2770 | assert.deepEqual(yield* summaries, []); | 2750 | 2771 | const baseline = (yield* orchestrator.getThreadShell(threadId))?.pullRequests?.[0]?.watch; | 2751 | 2772 | assert.equal(baseline?.headSha, headSha); | 2752 | 2773 | assert.isTrue(baseline?.passed); | 2753 | 2774 | assert.deepEqual(baseline?.passedChecks, ["lint", "test"]); | 2754 | 2775 | yield* TestClock.adjust("10 minutes"); | 2755 | 2776 | yield* reactor.sweep; | | 2777 | + yield* worker.drain(); | 2756 | 2778 | assert.deepEqual(yield* summaries, []); | 2757 | 2779 |
| 2758 | 2780 | const restarted = yield* PullRequestWatchReactor.make.pipe(Effect.provide(host)); | 2759 | 2781 | yield* restarted.sweep; | | 2782 | + yield* worker.drain(); | 2760 | 2783 | assert.deepEqual(yield* summaries, []); | 2761 | 2784 |
| 2762 | 2785 | headSha = "bbbbbbbbbb"; | 2763 | 2786 | yield* TestClock.adjust("10 minutes"); | 2764 | 2787 | yield* restarted.sweep; | | 2788 | + yield* worker.drain(); | 2765 | 2789 | assert.deepEqual(yield* summaries, ["#12: checks passed"]); | 2766 | 2790 |
| 2767 | 2791 | yield* watch(false, "stop"); | 2768 | 2792 | yield* watch(true, "again"); | 2769 | 2793 | yield* restarted.sweep; | | 2794 | + yield* worker.drain(); | 2770 | 2795 | assert.deepEqual(yield* summaries, ["#12: checks passed"]); | 2771 | 2796 |
| 2772 | 2797 | headSha = "cccccccccc"; | 2773 | 2798 | yield* TestClock.adjust("10 minutes"); | 2774 | 2799 | yield* restarted.sweep; | | 2800 | + yield* worker.drain(); | 2775 | 2801 | assert.deepEqual(yield* summaries, ["#12: checks passed", "#12: checks passed"]); | 2776 | 2802 | yield* watch(false, "end"); | 2777 | 2803 | }), | @@ -2858,7 +2884,7 @@ it.layer(layerTest)("OrchestrationV2LayerLive lifecycle", (it) => { | 2858 | 2884 | yield* TestClock.adjust("10 minutes"); | 2859 | 2885 | yield* reactor.sweep; | 2860 | 2886 | yield* worker.drain(); | 2861 | | - assert.deepEqual(yield* summaries, ["#12: checks passed"]); | | 2887 | + assert.deepEqual(yield* summaries, []); | 2862 | 2888 |
| 2863 | 2889 | assert.deepEqual( | 2864 | 2890 | (yield* orchestrator.getThreadShell(threadId))?.pullRequests?.[0]?.watch?.owedChecks, | @@ -2868,14 +2894,14 @@ it.layer(layerTest)("OrchestrationV2LayerLive lifecycle", (it) => { | 2868 | 2894 | const restarted = yield* PullRequestWatchReactor.make.pipe(Effect.provide(host)); | 2869 | 2895 | yield* restarted.sweep; | 2870 | 2896 | yield* worker.drain(); | 2871 | | - assert.deepEqual(yield* summaries, ["#12: checks passed"]); | | 2897 | + assert.deepEqual(yield* summaries, []); | 2872 | 2898 |
| 2873 | 2899 | // A new watch on the same pull request knows what the last one told. | 2874 | 2900 | yield* watch(false, "stop"); | 2875 | 2901 | yield* watch(true, "again"); | 2876 | 2902 | yield* restarted.sweep; | 2877 | 2903 | yield* worker.drain(); | 2878 | | - assert.deepEqual(yield* summaries, ["#12: checks passed"]); | | 2904 | + assert.deepEqual(yield* summaries, []); | 2879 | 2905 |
| 2880 | 2906 | assert.deepEqual( | 2881 | 2907 | (yield* orchestrator.getThreadShell(threadId))?.pullRequests?.[0]?.watch?.owedChecks, | @@ -2885,11 +2911,11 @@ it.layer(layerTest)("OrchestrationV2LayerLive lifecycle", (it) => { | 2885 | 2911 | yield* TestClock.adjust("10 minutes"); | 2886 | 2912 | yield* restarted.sweep; | 2887 | 2913 | yield* worker.drain(); | 2888 | | - assert.deepEqual(yield* summaries, ["#12: checks passed", "#12: checks passed"]); | | 2914 | + assert.deepEqual(yield* summaries, ["#12: checks passed"]); | 2889 | 2915 | yield* TestClock.adjust("10 minutes"); | 2890 | 2916 | yield* restarted.sweep; | 2891 | 2917 | yield* worker.drain(); | 2892 | | - assert.deepEqual(yield* summaries, ["#12: checks passed", "#12: checks passed"]); | | 2918 | + assert.deepEqual(yield* summaries, ["#12: checks passed"]); | 2893 | 2919 | assert.deepEqual( | 2894 | 2920 | (yield* orchestrator.getThreadShell(threadId))?.pullRequests?.[0]?.watch?.owedChecks, | 2895 | 2921 | [], | |
|