From 45367ac05a56c07dd74f1d5b7709e6e4d1112dc2 Mon Sep 17 00:00:00 2001 From: Wout Stiens <71498452+StiensWout@users.noreply.github.com> Date: Wed, 18 Nov 2026 15:54:19 +0100 Subject: [PATCH 01/11] test(azure-devops): a refreshed issue list reads the project's current finished states Co-authored-by: Claude Opus 5.5 --- .../server/AzureDevOpsIssueTracker.test.ts | 25 +++- ...ssues-refresh-reads-new-azure-state.e2e.ts | 124 ++++++++++++++++++ 2 files changed, 148 insertions(+), 1 deletion(-) create mode 100644 scripts/scenarios/issues-refresh-reads-new-azure-state.e2e.ts diff --git a/packages/source-control-azure-devops/src/server/AzureDevOpsIssueTracker.test.ts b/packages/source-control-azure-devops/src/server/AzureDevOpsIssueTracker.test.ts index cc6a1d18cd28f..efbe2ecff4193 100644 --- a/packages/source-control-azure-devops/src/server/AzureDevOpsIssueTracker.test.ts +++ b/packages/source-control-azure-devops/src/server/AzureDevOpsIssueTracker.test.ts @@ -220,6 +220,7 @@ describe("AzureDevOpsIssueTracker", () => { const bodies: string[] = []; const hydrated: string[] = []; let typeReads = 0; + let finished = "Shipped"; const api = yield* AzureDevOpsIssueTracker.make.pipe( Effect.provide( Layer.mock(AzureDevOpsCli.AzureDevOpsCli)({ @@ -238,8 +239,17 @@ describe("AzureDevOpsIssueTracker", () => { }), ); } + if (resource === "workitemtypes") { + typeReads += 1; + return Effect.succeed( + TestSourceControlHost.processOutput( + encode({ + value: [{ name: "Bug", states: [{ name: finished, category: "Completed" }] }], + }), + ), + ); + } if (resource !== "wiql" && resource !== "workitemsbatch") { - if (resource === "workitemtypes") typeReads += 1; return Effect.succeed(TestSourceControlHost.processOutput(answer(args))); } return fs.readFileString(args[args.indexOf("--in-file") + 1]!).pipe( @@ -286,6 +296,19 @@ describe("AzureDevOpsIssueTracker", () => { expect(bodies).toHaveLength(2); expect(bodies[1]).toBe(bodies[0]); expect(bodies[0]).toContain("AND [System.State] NOT IN ('shipped')"); + // A first page is a fresh list, so it sees a finished state added since. + finished = "Released"; + yield* api.listIssues({ + cwd: "/w", + host: "dev.azure.com", + scope: "acme/Web App", + state: "open", + involvement: "all", + sort: "updated", + limit: 2, + }); + expect(typeReads).toBe(2); + expect(bodies[2]).toContain("AND [System.State] NOT IN ('released')"); const { query } = JSON.parse(bodies[0]!) as { query: string }; // Mentions cannot be asked for over REST, so the filter sends no clause for them. expect(query).not.toContain("@RecentMentions"); diff --git a/scripts/scenarios/issues-refresh-reads-new-azure-state.e2e.ts b/scripts/scenarios/issues-refresh-reads-new-azure-state.e2e.ts new file mode 100644 index 0000000000000..d8b7173938b1e --- /dev/null +++ b/scripts/scenarios/issues-refresh-reads-new-azure-state.e2e.ts @@ -0,0 +1,124 @@ +import { expect } from "e2e"; +import * as Effect from "effect/Effect"; +import * as FileSystem from "effect/FileSystem"; +import * as Path from "effect/Path"; + +import { T3_HOME } from "../e2e.config.ts"; +import { run } from "./shell.ts"; +import { makeState, runPromise, test, WEB } from "./t3.ts"; + +// Stand in for the Azure CLI upstream. The real tracker builds WIQL and decodes its rows. +const azureCli = String.raw`#!/usr/bin/env node +import { existsSync, readFileSync } from "node:fs"; + +const args = process.argv.slice(2); +const argument = (name) => args[args.indexOf(name) + 1]; +const changed = existsSync(new URL("./workflow-changed", import.meta.url)); +const bugFinished = changed ? "Released" : "Done"; +const item = (id, type, title, state) => ({ + id, + url: "https://dev.azure.com/scenario/_apis/wit/workItems/" + id, + fields: { + "System.Title": title, + "System.State": state, + "System.TeamProject": "Release", + "System.WorkItemType": type, + "System.CreatedDate": "2026-10-01T00:00:00Z", + "System.ChangedDate": "2026-10-02T00:00:00Z", + }, +}); +const items = [ + item(7, "Bug", "Verify the release package", changed ? "Released" : "Active"), + item(6, "Task", changed ? "Release notes checked" : "Release notes drafted", "Closed"), +]; +let output; +switch (argument("--resource")) { + case "workitemtypes": + output = { value: [ + { name: "Bug", states: [ + { name: "Active", category: "InProgress" }, + { name: bugFinished, category: "Completed" }, + ] }, + { name: "Task", states: [{ name: "Closed", category: "Completed" }] }, + ] }; + break; + case "wiql": { + const { query } = JSON.parse(readFileSync(argument("--in-file"), "utf8")); + const clause = /\[System\.State\] (NOT )?IN \(([^)]+)\)/.exec(query); + const names = clause?.[2].match(/'[^']*'/g) ?? []; + output = { workItems: items.filter((item) => { + if (!clause) return true; + const listed = names.includes("'" + item.fields["System.State"].toLowerCase() + "'"); + return clause[1] ? !listed : listed; + }).map(({ id }) => ({ id })) }; + break; + } + case "workitemsbatch": { + const { ids } = JSON.parse(readFileSync(argument("--in-file"), "utf8")); + output = { value: items.filter(({ id }) => ids.includes(id)) }; + break; + } + default: + if (args[0] === "repos" && args[1] === "show") { + output = { + name: "release", + project: { name: "Release" }, + webUrl: "https://dev.azure.com/scenario/Release/_git/release", + remoteUrl: "https://dev.azure.com/scenario/Release/_git/release", + sshUrl: "git@ssh.dev.azure.com:v3/scenario/Release/release", + }; + break; + } + process.exit(1); +} +console.log(JSON.stringify(output)); +`; + +test( + "Refreshing Closed issues picks up a new Azure DevOps finished state", + WEB, + async ({ t3, app, screen }) => { + const workspace = await t3.project("demo"); + const { repository, changed } = await runPromise( + Effect.gen(function* () { + const path = yield* Path.Path; + const fs = yield* FileSystem.FileSystem; + const shim = path.join(T3_HOME, "bin", "az"); + yield* fs.writeFileString(shim, azureCli); + yield* fs.chmod(shim, 0o755); + return { + repository: path.join(T3_HOME, "release"), + changed: path.join(T3_HOME, "bin", "workflow-changed"), + }; + }), + ); + await runPromise(run("git", ["clone", "--quiet", workspace, repository])); + await runPromise( + run( + "git", + ["remote", "set-url", "origin", "https://dev.azure.com/scenario/Release/_git/release"], + { + cwd: repository, + }, + ), + ); + const primary = makeState(T3_HOME); + await runPromise(primary.cli(["project", "add", repository, "--title", "Release"])); + try { + await t3.open("/issues?status=closed"); + // The initial Closed list warms the workflow cache. + await screen.getByText("Release notes drafted", { exact: true }).waitFor({ timeout: 60_000 }); + await runPromise( + Effect.flatMap(FileSystem.FileSystem, (fs) => fs.writeFileString(changed, "")), + ); + + await screen.getByRole("button", "Refresh issues", { exact: true }).tap(); + // This title changes with the workflow, so the next assertion sees the completed refresh. + await screen.getByText("Release notes checked", { exact: true }).waitFor(); + await app.screenshot("closed-issues-after-workflow-change"); + await expect(screen.getByText("Verify the release package", { exact: true })).toBeVisible(); + } finally { + await runPromise(primary.cli(["project", "remove", repository, "--force"])); + } + }, +); From c38056eb51b755bd61ecc5a1bcfb1af8cabc6ed1 Mon Sep 17 00:00:00 2001 From: Wout Stiens <71498452+StiensWout@users.noreply.github.com> Date: Wed, 18 Nov 2026 15:55:45 +0100 Subject: [PATCH 02/11] fix(azure-devops): refreshing Issues reads each project's current finished states Co-authored-by: Claude Opus 5.5 --- .../src/server/AzureDevOpsIssueTracker.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/source-control-azure-devops/src/server/AzureDevOpsIssueTracker.ts b/packages/source-control-azure-devops/src/server/AzureDevOpsIssueTracker.ts index 84212c9ff0ecd..eec174b024858 100644 --- a/packages/source-control-azure-devops/src/server/AzureDevOpsIssueTracker.ts +++ b/packages/source-control-azure-devops/src/server/AzureDevOpsIssueTracker.ts @@ -360,7 +360,8 @@ export const make: Effect.Effect< decode: decodeAs(decodeTypes), }).pipe(Effect.map((types) => types.value)); - // Each `az` call costs seconds of startup, and a project's states rarely change. + // Each `az` call costs seconds of startup, so the pages after a list's first reuse the states it + // read. A first page reads them again, which is how a refresh sees a workflow changed since. const listClosedStates = yield* Cache.makeWith( (key: string) => { const [cwd, organization, project] = JSON.parse(key) as [string, string, string]; @@ -614,7 +615,7 @@ export const make: Effect.Effect< const dateField = created ? "[System.CreatedDate]" : "[System.ChangedDate]"; return yield* scoped("listIssues", input).pipe( Effect.flatMap((scope) => - Cache.get( + (cursor === undefined ? Cache.refresh : Cache.get)( listClosedStates, JSON.stringify([input.cwd, scope.organization, scope.project]), ).pipe(Effect.map((closed) => ({ scope, closed }))), From f33977cabee124b0b8f39887acb0c00a2d145f8d Mon Sep 17 00:00:00 2001 From: Wout Stiens <71498452+StiensWout@users.noreply.github.com> Date: Wed, 18 Nov 2026 16:21:50 +0100 Subject: [PATCH 03/11] fix(issues): reserve workflow reloads for explicit refresh Co-authored-by: GPT 6.2 Sol --- .../src/features/issues/IssuesScreen.tsx | 2 +- apps/mobile/src/state/issues.ts | 6 +- apps/server/src/issue/IssueService.ts | 1 + apps/web/src/components/issue/IssuesPage.tsx | 2 +- apps/web/src/state/issues.ts | 7 +- packages/client-runtime/src/state/issues.ts | 34 ++++++++-- packages/client-runtime/src/state/runtime.ts | 5 ++ packages/contracts/src/issue.ts | 2 + .../server/AzureDevOpsIssueTracker.test.ts | 68 +++++++++++++++++++ .../src/server/AzureDevOpsIssueTracker.ts | 39 +++++++---- .../src/server/IssueTracker.ts | 2 + 11 files changed, 147 insertions(+), 21 deletions(-) diff --git a/apps/mobile/src/features/issues/IssuesScreen.tsx b/apps/mobile/src/features/issues/IssuesScreen.tsx index 361d17ac79b05..ab6d516555b7d 100644 --- a/apps/mobile/src/features/issues/IssuesScreen.tsx +++ b/apps/mobile/src/features/issues/IssuesScreen.tsx @@ -310,7 +310,7 @@ export function IssuesScreen( refreshControl={ 0} - onRefresh={list.refresh} + onRefresh={list.refreshWorkflow} // The list already accounts for the navigation header in its content inset. progressViewOffset={Platform.OS === "ios" ? 60 : undefined} /> diff --git a/apps/mobile/src/state/issues.ts b/apps/mobile/src/state/issues.ts index 9f47acf847520..4a563fcdcf8a8 100644 --- a/apps/mobile/src/state/issues.ts +++ b/apps/mobile/src/state/issues.ts @@ -22,7 +22,11 @@ const mergedIssueLists = createMergedIssueListAtoms( /** One listing read across every environment asked. */ export function useIssueList(targets: ReadonlyArray) { const view = useAtomValue(mergedIssueLists.atom(targets)); - return { ...view, refresh: () => mergedIssueLists.refresh(appAtomRegistry, targets) }; + return { + ...view, + refresh: () => mergedIssueLists.refresh(appAtomRegistry, targets), + refreshWorkflow: () => issueEnvironment.refreshWorkflow(appAtomRegistry, targets), + }; } /** After a write the list cannot see, such as a new issue filed from a sheet. */ diff --git a/apps/server/src/issue/IssueService.ts b/apps/server/src/issue/IssueService.ts index fbf869e562001..00d71cd067751 100644 --- a/apps/server/src/issue/IssueService.ts +++ b/apps/server/src/issue/IssueService.ts @@ -408,6 +408,7 @@ const make = Effect.gen(function* () { assignee: input.assignee, sort: input.sort ?? "updated", cursor, + refresh: input.refresh === true, }), ), Effect.result, diff --git a/apps/web/src/components/issue/IssuesPage.tsx b/apps/web/src/components/issue/IssuesPage.tsx index 5181a897a1a17..2e1605de867f5 100644 --- a/apps/web/src/components/issue/IssuesPage.tsx +++ b/apps/web/src/components/issue/IssuesPage.tsx @@ -729,7 +729,7 @@ export function IssuesPage() { size="icon" variant="outline" aria-label={gt("Refresh issues")} - onClick={list.refresh} + onClick={list.refreshWorkflow} disabled={list.isPending} > diff --git a/apps/web/src/state/issues.ts b/apps/web/src/state/issues.ts index c92bf81154a12..f8300018aea0e 100644 --- a/apps/web/src/state/issues.ts +++ b/apps/web/src/state/issues.ts @@ -46,12 +46,17 @@ const mergedIssueLists = createMergedIssueListAtoms( /** The same listing read across every connected environment, as the pull-request page does. */ export function useIssueList( targets: ReadonlyArray, -): MergedIssueList & { readonly refresh: () => void; readonly retry: () => void } { +): MergedIssueList & { + readonly refresh: () => void; + readonly retry: () => void; + readonly refreshWorkflow: () => void; +} { const view = useAtomValue(mergedIssueLists.atom(targets)); return { ...view, refresh: () => mergedIssueLists.refresh(appAtomRegistry, targets), retry: () => mergedIssueLists.retry(appAtomRegistry, targets), + refreshWorkflow: () => issueEnvironment.refreshWorkflow(appAtomRegistry, targets), }; } diff --git a/packages/client-runtime/src/state/issues.ts b/packages/client-runtime/src/state/issues.ts index b48ec184a7c7e..cd6282e583d81 100644 --- a/packages/client-runtime/src/state/issues.ts +++ b/packages/client-runtime/src/state/issues.ts @@ -24,8 +24,10 @@ import { createEnvironmentRpcCommand, createEnvironmentRpcQueryAtomFamily, createEnvironmentRpcSubscriptionAtomFamily, + createEnvironmentQueryAtomFamily, } from "./runtime.ts"; import type { EnvironmentRegistry } from "../connection/registry.ts"; +import { request } from "../rpc/client.ts"; /** One row's identity across list pages and detail reads; hosts compare case-insensitively. */ export function issueEntryKey( @@ -179,6 +181,20 @@ export function createIssueEnvironmentAtoms( label: "environment-data:issues:linked-thread-refreshes", tag: WS_METHODS.pullRequestsSubscribeLinkedThreadRefreshes, }); + const explicitRefreshes = new WeakMap>>(); + const list = createEnvironmentQueryAtomFamily(runtime, { + label: "environment-data:issues:list", + staleTimeMs: 30_000, + execute: ( + input: IssueListInput, + _emit, + _previous, + { environmentId, registry }, + ): ReturnType> => { + const refresh = explicitRefreshes.get(registry)?.delete(list({ environmentId, input })); + return request(WS_METHODS.issuesList, refresh ? { ...input, refresh: true } : input); + }, + }); return { /** The threads an issue is linked to, reread when the server signals a link changed. */ linkedThreads: createEnvironmentRpcQueryAtomFamily(runtime, { @@ -187,11 +203,19 @@ export function createIssueEnvironmentAtoms( staleTimeMs: 0, refreshTrigger: ({ environmentId }) => linkedThreadSignals({ environmentId, input: {} }), }), - list: createEnvironmentRpcQueryAtomFamily(runtime, { - label: "environment-data:issues:list", - tag: WS_METHODS.issuesList, - staleTimeMs: 30_000, - }), + list, + refreshWorkflow(registry: AtomRegistry.AtomRegistry, targets: ReadonlyArray) { + let pending = explicitRefreshes.get(registry); + if (pending === undefined) { + pending = new WeakSet(); + explicitRefreshes.set(registry, pending); + } + for (const target of targets) { + const atom = list(target); + pending.add(atom); + registry.refresh(atom); + } + }, /** * A continuation of the listing, run as a command rather than read as a query: a page is * asked for once and laid over the rows held, and a refresh of the first page forgets it. diff --git a/packages/client-runtime/src/state/runtime.ts b/packages/client-runtime/src/state/runtime.ts index ac55aba2da28c..82c5240458b3c 100644 --- a/packages/client-runtime/src/state/runtime.ts +++ b/packages/client-runtime/src/state/runtime.ts @@ -94,6 +94,10 @@ interface EnvironmentQueryAtomOptions extends Omit< input: Input, emit: (value: A) => Effect.Effect, previous: Option.Option, + context: { + readonly environmentId: EnvironmentIdType; + readonly registry: AtomRegistry.AtomRegistry; + }, ) => Effect.Effect; readonly persistence?: QueryPersistence; readonly staleTimeMs?: number; @@ -777,6 +781,7 @@ export function createEnvironmentQueryAtomFamily( get.self>(), AsyncResult.value, ), + { environmentId: target.environmentId, registry: get.registry }, ) .pipe(pendingOnceSessionReplaced(session.value)), ) diff --git a/packages/contracts/src/issue.ts b/packages/contracts/src/issue.ts index d542eef2b1eed..07f2eab6e6a42 100644 --- a/packages/contracts/src/issue.ts +++ b/packages/contracts/src/issue.ts @@ -266,6 +266,8 @@ export const IssueListInput = Schema.Struct({ limit: Schema.optional(Schema.Int.check(Schema.isBetween({ minimum: 1, maximum: 200 }))), /** Carry on from an earlier answer: only the scopes named here are read, one slice each. */ cursors: Schema.optional(IssueListCursors), + /** An explicit refresh of the first page may also refresh tracker metadata. */ + refresh: Schema.optional(Schema.Boolean), /** Free text the trackers themselves are asked to match. */ query: Schema.optional(TrimmedNonEmptyString.check(Schema.isMaxLength(200))), /** Label names an issue must carry, every one of them. */ diff --git a/packages/source-control-azure-devops/src/server/AzureDevOpsIssueTracker.test.ts b/packages/source-control-azure-devops/src/server/AzureDevOpsIssueTracker.test.ts index efbe2ecff4193..313335dfb0224 100644 --- a/packages/source-control-azure-devops/src/server/AzureDevOpsIssueTracker.test.ts +++ b/packages/source-control-azure-devops/src/server/AzureDevOpsIssueTracker.test.ts @@ -1,6 +1,8 @@ import { describe, expect, it } from "@effect/vitest"; import * as NodeFileSystem from "@effect/platform-node/NodeFileSystem"; +import * as Deferred from "effect/Deferred"; import * as Effect from "effect/Effect"; +import * as Fiber from "effect/Fiber"; import * as FileSystem from "effect/FileSystem"; import * as PlatformError from "effect/PlatformError"; import * as Layer from "effect/Layer"; @@ -221,6 +223,9 @@ describe("AzureDevOpsIssueTracker", () => { const hydrated: string[] = []; let typeReads = 0; let finished = "Shipped"; + let beforeWorkflowRead: + | Effect.Effect + | undefined; const api = yield* AzureDevOpsIssueTracker.make.pipe( Effect.provide( Layer.mock(AzureDevOpsCli.AzureDevOpsCli)({ @@ -241,6 +246,19 @@ describe("AzureDevOpsIssueTracker", () => { } if (resource === "workitemtypes") { typeReads += 1; + if (beforeWorkflowRead !== undefined) { + return beforeWorkflowRead.pipe( + Effect.as( + TestSourceControlHost.processOutput( + encode({ + value: [ + { name: "Bug", states: [{ name: finished, category: "Completed" }] }, + ], + }), + ), + ), + ); + } return Effect.succeed( TestSourceControlHost.processOutput( encode({ @@ -317,6 +335,56 @@ describe("AzureDevOpsIssueTracker", () => { " AND ([System.CreatedDate] < '2026-07-01T00:00:00Z' OR ([System.CreatedDate] = '2026-07-01T00:00:00Z' AND [System.Id] < 7))" + " ORDER BY [System.CreatedDate] DESC, [System.Id] DESC", ); + + const firstPage = { + cwd: "/w", + host: "dev.azure.com", + scope: "acme/Web App", + state: "open", + involvement: "all", + sort: "updated", + limit: 2, + } as const; + finished = "Done"; + yield* api.listIssues({ ...firstPage, refresh: false, query: "composer" }); + yield* api.listIssues({ ...firstPage, refresh: true, state: "all" }); + expect(typeReads).toBe(2); + expect(bodies[3]).toContain("AND [System.State] NOT IN ('released')"); + expect(bodies[4]).not.toContain("[System.State]"); + + beforeWorkflowRead = Effect.fail( + new AzureDevOpsCli.AzureDevOpsCommandFailedError({ + operation: "execute", + command: "az", + cwd: "/w", + argumentCount: 0, + cause: "workflow metadata unavailable", + }), + ); + yield* api.listIssues({ ...firstPage, refresh: true }); + yield* api.listIssues({ ...firstPage, refresh: false }); + expect(typeReads).toBe(3); + expect(bodies.slice(5, 7).every((body) => body.includes("NOT IN ('released')"))).toBe(true); + + const started = yield* Deferred.make(); + const release = yield* Deferred.make(); + beforeWorkflowRead = Deferred.succeed(started, undefined).pipe( + Effect.andThen(Deferred.await(release)), + ); + const first = yield* Effect.forkChild(api.listIssues({ ...firstPage, refresh: true }), { + startImmediately: true, + }); + yield* Deferred.await(started); + const second = yield* Effect.forkChild(api.listIssues({ ...firstPage, refresh: true }), { + startImmediately: true, + }); + yield* Deferred.succeed(release, undefined); + yield* Fiber.join(first); + const refreshed = yield* Fiber.join(second); + expect(refreshed.nextCursor).not.toBeNull(); + yield* api.listIssues({ ...firstPage, cursor: refreshed.nextCursor ?? undefined }); + expect(typeReads).toBe(4); + expect(bodies.slice(7).every((body) => body.includes("NOT IN ('done')"))).toBe(true); }).pipe(Effect.provide(NodeFileSystem.layer)), ); diff --git a/packages/source-control-azure-devops/src/server/AzureDevOpsIssueTracker.ts b/packages/source-control-azure-devops/src/server/AzureDevOpsIssueTracker.ts index eec174b024858..e28714a1aa2fc 100644 --- a/packages/source-control-azure-devops/src/server/AzureDevOpsIssueTracker.ts +++ b/packages/source-control-azure-devops/src/server/AzureDevOpsIssueTracker.ts @@ -7,6 +7,7 @@ import * as Cache from "effect/Cache"; import * as Duration from "effect/Duration"; import * as Effect from "effect/Effect"; import * as Exit from "effect/Exit"; +import * as Option from "effect/Option"; import * as FileSystem from "effect/FileSystem"; import * as Result from "effect/Result"; import * as Schema from "effect/Schema"; @@ -360,20 +361,23 @@ export const make: Effect.Effect< decode: decodeAs(decodeTypes), }).pipe(Effect.map((types) => types.value)); - // Each `az` call costs seconds of startup, so the pages after a list's first reuse the states it - // read. A first page reads them again, which is how a refresh sees a workflow changed since. - const listClosedStates = yield* Cache.makeWith( + // A warm list can use the last good workflow while an explicit refresh is in flight. + const workflowReads = yield* Cache.makeWith( (key: string) => { const [cwd, organization, project] = JSON.parse(key) as [string, string, string]; return workItemTypes({ cwd, organization, project, operation: "listIssues" }).pipe( Effect.map(closedStateNames), + Effect.tap((closed) => Cache.set(listClosedStates, key, closed)), ); }, - { + { capacity: Infinity, timeToLive: () => Duration.zero }, + ); + // Cache misses and explicit refreshes share the same in-flight read and publication. + const listClosedStates: Cache.Cache = + yield* Cache.makeWith((key) => Cache.get(workflowReads, key), { capacity: 256, timeToLive: (exit) => (Exit.isSuccess(exit) ? CLOSED_STATES_TTL : Duration.zero), - }, - ); + }); const workItem = (input: { readonly cwd: string; @@ -614,12 +618,23 @@ export const make: Effect.Effect< const created = input.sort === "created"; const dateField = created ? "[System.CreatedDate]" : "[System.ChangedDate]"; return yield* scoped("listIssues", input).pipe( - Effect.flatMap((scope) => - (cursor === undefined ? Cache.refresh : Cache.get)( - listClosedStates, - JSON.stringify([input.cwd, scope.organization, scope.project]), - ).pipe(Effect.map((closed) => ({ scope, closed }))), - ), + Effect.flatMap((scope) => { + const key = JSON.stringify([input.cwd, scope.organization, scope.project]); + // The service always specifies refresh intent; direct tracker calls default to fresh. + const refresh = cursor === undefined && input.state !== "all" && input.refresh !== false; + const closed = refresh + ? Cache.getSuccess(listClosedStates, key).pipe( + Effect.flatMap((previous) => + Cache.get(workflowReads, key).pipe( + Effect.catch((error) => + Option.isSome(previous) ? Effect.succeed(previous.value) : Effect.fail(error), + ), + ), + ), + ) + : Cache.get(listClosedStates, key); + return closed.pipe(Effect.map((closed) => ({ scope, closed }))); + }), Effect.flatMap(({ scope, closed }) => invokeWithBody({ cwd: input.cwd, diff --git a/packages/source-control-core/src/server/IssueTracker.ts b/packages/source-control-core/src/server/IssueTracker.ts index de1656d22a2f4..057604a66340e 100644 --- a/packages/source-control-core/src/server/IssueTracker.ts +++ b/packages/source-control-core/src/server/IssueTracker.ts @@ -126,6 +126,8 @@ export interface IssueTrackerApi { readonly sort: IssueListSort; /** A cursor this tracker handed back from an earlier page. Absent asks for the first. */ readonly cursor?: string | undefined; + /** Whether to re-read tracker metadata for a first page. */ + readonly refresh?: boolean; }, ) => Effect.Effect; From 058fdc8059c8bc9e9d221fdd37c9e391f81d1008 Mon Sep 17 00:00:00 2001 From: Wout Stiens <71498452+StiensWout@users.noreply.github.com> Date: Wed, 18 Nov 2026 16:27:03 +0100 Subject: [PATCH 04/11] fix(azure-devops): specify the workflow cache key type Co-authored-by: GPT 6.2 Sol --- .../src/server/AzureDevOpsIssueTracker.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/source-control-azure-devops/src/server/AzureDevOpsIssueTracker.ts b/packages/source-control-azure-devops/src/server/AzureDevOpsIssueTracker.ts index e28714a1aa2fc..5e3790fd96732 100644 --- a/packages/source-control-azure-devops/src/server/AzureDevOpsIssueTracker.ts +++ b/packages/source-control-azure-devops/src/server/AzureDevOpsIssueTracker.ts @@ -374,7 +374,7 @@ export const make: Effect.Effect< ); // Cache misses and explicit refreshes share the same in-flight read and publication. const listClosedStates: Cache.Cache = - yield* Cache.makeWith((key) => Cache.get(workflowReads, key), { + yield* Cache.makeWith((key: string) => Cache.get(workflowReads, key), { capacity: 256, timeToLive: (exit) => (Exit.isSuccess(exit) ? CLOSED_STATES_TTL : Duration.zero), }); From 891b6fa3d103306a97124e6b7aff7a45d240b217 Mon Sep 17 00:00:00 2001 From: Wout Stiens <71498452+StiensWout@users.noreply.github.com> Date: Wed, 18 Nov 2026 16:27:28 +0100 Subject: [PATCH 05/11] fix(azure-devops): use Effect for the cached workflow fallback Co-authored-by: GPT 6.2 Sol --- .../src/server/AzureDevOpsIssueTracker.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/source-control-azure-devops/src/server/AzureDevOpsIssueTracker.ts b/packages/source-control-azure-devops/src/server/AzureDevOpsIssueTracker.ts index 5e3790fd96732..65c2e044373b8 100644 --- a/packages/source-control-azure-devops/src/server/AzureDevOpsIssueTracker.ts +++ b/packages/source-control-azure-devops/src/server/AzureDevOpsIssueTracker.ts @@ -7,7 +7,6 @@ import * as Cache from "effect/Cache"; import * as Duration from "effect/Duration"; import * as Effect from "effect/Effect"; import * as Exit from "effect/Exit"; -import * as Option from "effect/Option"; import * as FileSystem from "effect/FileSystem"; import * as Result from "effect/Result"; import * as Schema from "effect/Schema"; @@ -627,7 +626,7 @@ export const make: Effect.Effect< Effect.flatMap((previous) => Cache.get(workflowReads, key).pipe( Effect.catch((error) => - Option.isSome(previous) ? Effect.succeed(previous.value) : Effect.fail(error), + Effect.fromOption(previous).pipe(Effect.mapError(() => error)), ), ), ), From 0968131c1cbf8c438e6f6d070505f701537d29f0 Mon Sep 17 00:00:00 2001 From: Wout Stiens <71498452+StiensWout@users.noreply.github.com> Date: Wed, 18 Nov 2026 16:38:02 +0100 Subject: [PATCH 06/11] fix(issues): carry explicit refresh through list invalidation Co-authored-by: GPT 6.2 Sol --- .../src/features/issues/IssuesScreen.tsx | 2 +- apps/mobile/src/state/issues.ts | 3 +- apps/server/src/issue/IssueService.ts | 2 +- apps/web/src/components/issue/IssuesPage.tsx | 4 +- apps/web/src/state/issues.ts | 6 +-- packages/client-runtime/src/state/issues.ts | 47 ++++++++++++------- .../client-runtime/src/state/runtime.test.ts | 47 +++++++++++++++++++ .../server/AzureDevOpsIssueTracker.test.ts | 30 ++++++++---- .../src/server/AzureDevOpsIssueTracker.ts | 3 +- .../src/server/IssueTracker.ts | 2 +- 10 files changed, 109 insertions(+), 37 deletions(-) diff --git a/apps/mobile/src/features/issues/IssuesScreen.tsx b/apps/mobile/src/features/issues/IssuesScreen.tsx index ab6d516555b7d..361d17ac79b05 100644 --- a/apps/mobile/src/features/issues/IssuesScreen.tsx +++ b/apps/mobile/src/features/issues/IssuesScreen.tsx @@ -310,7 +310,7 @@ export function IssuesScreen( refreshControl={ 0} - onRefresh={list.refreshWorkflow} + onRefresh={list.refresh} // The list already accounts for the navigation header in its content inset. progressViewOffset={Platform.OS === "ios" ? 60 : undefined} /> diff --git a/apps/mobile/src/state/issues.ts b/apps/mobile/src/state/issues.ts index 4a563fcdcf8a8..bbfd50ac4b013 100644 --- a/apps/mobile/src/state/issues.ts +++ b/apps/mobile/src/state/issues.ts @@ -24,8 +24,7 @@ export function useIssueList(targets: ReadonlyArray) { const view = useAtomValue(mergedIssueLists.atom(targets)); return { ...view, - refresh: () => mergedIssueLists.refresh(appAtomRegistry, targets), - refreshWorkflow: () => issueEnvironment.refreshWorkflow(appAtomRegistry, targets), + refresh: () => mergedIssueLists.refresh(appAtomRegistry, targets, "manual"), }; } diff --git a/apps/server/src/issue/IssueService.ts b/apps/server/src/issue/IssueService.ts index 00d71cd067751..239de06ce546d 100644 --- a/apps/server/src/issue/IssueService.ts +++ b/apps/server/src/issue/IssueService.ts @@ -408,7 +408,7 @@ const make = Effect.gen(function* () { assignee: input.assignee, sort: input.sort ?? "updated", cursor, - refresh: input.refresh === true, + refresh: input.refresh, }), ), Effect.result, diff --git a/apps/web/src/components/issue/IssuesPage.tsx b/apps/web/src/components/issue/IssuesPage.tsx index 2e1605de867f5..39fd8a0ec60ed 100644 --- a/apps/web/src/components/issue/IssuesPage.tsx +++ b/apps/web/src/components/issue/IssuesPage.tsx @@ -230,7 +230,7 @@ export function IssuesPage() { // Refreshing a list still loading would cancel it and start over, losing the scopes already read. useLiveRefresh( () => { - if (!list.isPending) list.refresh(); + if (!list.isPending) list.reload(); }, { key: JSON.stringify(targets) }, ); @@ -729,7 +729,7 @@ export function IssuesPage() { size="icon" variant="outline" aria-label={gt("Refresh issues")} - onClick={list.refreshWorkflow} + onClick={list.refresh} disabled={list.isPending} > diff --git a/apps/web/src/state/issues.ts b/apps/web/src/state/issues.ts index f8300018aea0e..60b0d879ccc6f 100644 --- a/apps/web/src/state/issues.ts +++ b/apps/web/src/state/issues.ts @@ -48,15 +48,15 @@ export function useIssueList( targets: ReadonlyArray, ): MergedIssueList & { readonly refresh: () => void; + readonly reload: () => void; readonly retry: () => void; - readonly refreshWorkflow: () => void; } { const view = useAtomValue(mergedIssueLists.atom(targets)); return { ...view, - refresh: () => mergedIssueLists.refresh(appAtomRegistry, targets), + refresh: () => mergedIssueLists.refresh(appAtomRegistry, targets, "manual"), + reload: () => mergedIssueLists.refresh(appAtomRegistry, targets, "background"), retry: () => mergedIssueLists.retry(appAtomRegistry, targets), - refreshWorkflow: () => issueEnvironment.refreshWorkflow(appAtomRegistry, targets), }; } diff --git a/packages/client-runtime/src/state/issues.ts b/packages/client-runtime/src/state/issues.ts index cd6282e583d81..b0ff32a46fe0d 100644 --- a/packages/client-runtime/src/state/issues.ts +++ b/packages/client-runtime/src/state/issues.ts @@ -15,6 +15,7 @@ import { } from "@t3tools/contracts"; import type * as Cause from "effect/Cause"; import * as Effect from "effect/Effect"; +import * as Exit from "effect/Exit"; import * as Option from "effect/Option"; import { AsyncResult, Atom, type AtomRegistry } from "effect/reactivity"; @@ -147,6 +148,11 @@ export function createIssueCommentPager( }; } +const pendingListRefreshes = new WeakMap< + AtomRegistry.AtomRegistry, + WeakMap, symbol> +>(); + /** * Every read goes to a tracker API over the environment, so results are reused for a short while * and refreshed explicitly. Mutations run serially per environment: changes to one issue are @@ -181,7 +187,6 @@ export function createIssueEnvironmentAtoms( label: "environment-data:issues:linked-thread-refreshes", tag: WS_METHODS.pullRequestsSubscribeLinkedThreadRefreshes, }); - const explicitRefreshes = new WeakMap>>(); const list = createEnvironmentQueryAtomFamily(runtime, { label: "environment-data:issues:list", staleTimeMs: 30_000, @@ -191,8 +196,19 @@ export function createIssueEnvironmentAtoms( _previous, { environmentId, registry }, ): ReturnType> => { - const refresh = explicitRefreshes.get(registry)?.delete(list({ environmentId, input })); - return request(WS_METHODS.issuesList, refresh ? { ...input, refresh: true } : input); + const atom = list({ environmentId, input }); + const pending = pendingListRefreshes.get(registry); + const intent = pending?.get(atom); + if (pending === undefined || intent === undefined) + return request(WS_METHODS.issuesList, input); + return request(WS_METHODS.issuesList, { ...input, refresh: true }).pipe( + // Invalidation interrupts the read; its replacement still owes the explicit refresh. + Effect.onExit((exit) => + Effect.sync(() => { + if (!Exit.hasInterrupts(exit) && pending.get(atom) === intent) pending.delete(atom); + }), + ), + ); }, }); return { @@ -204,18 +220,6 @@ export function createIssueEnvironmentAtoms( refreshTrigger: ({ environmentId }) => linkedThreadSignals({ environmentId, input: {} }), }), list, - refreshWorkflow(registry: AtomRegistry.AtomRegistry, targets: ReadonlyArray) { - let pending = explicitRefreshes.get(registry); - if (pending === undefined) { - pending = new WeakSet(); - explicitRefreshes.set(registry, pending); - } - for (const target of targets) { - const atom = list(target); - pending.add(atom); - registry.refresh(atom); - } - }, /** * A continuation of the listing, run as a command rather than read as a query: a page is * asked for once and laid over the rows held, and a refresh of the first page forgets it. @@ -346,8 +350,18 @@ export function createMergedIssueListAtoms( const refresh = ( registry: AtomRegistry.AtomRegistry, targets: ReadonlyArray, + mode: "manual" | "background", ) => { - for (const target of targets) registry.refresh(list(target)); + let pending = pendingListRefreshes.get(registry); + if (mode === "manual" && pending === undefined) { + pending = new WeakMap(); + pendingListRefreshes.set(registry, pending); + } + for (const target of targets) { + const atom = list(target); + if (mode === "manual") pending?.set(atom, Symbol()); + registry.refresh(atom); + } }; // The targets behind each listing atom, so a write made elsewhere can refresh the ones still // shown. Weak, so a closed search goes with its atom once the registry drops it. @@ -370,6 +384,7 @@ export function createMergedIssueListAtoms( refresh( registry, targets.filter((target) => target.environmentId === environmentId), + "background", ); } }, diff --git a/packages/client-runtime/src/state/runtime.test.ts b/packages/client-runtime/src/state/runtime.test.ts index 59093d2d9dbdc..3ce4f39d651e6 100644 --- a/packages/client-runtime/src/state/runtime.test.ts +++ b/packages/client-runtime/src/state/runtime.test.ts @@ -6,6 +6,8 @@ import { DEFAULT_MAX_TERMINAL_BUFFER_BYTES, EnvironmentId, type FilesystemBrowseEntry, + type IssueListInput, + type IssueListResult, ORCHESTRATION_V2_WS_METHODS, type OrchestrationV2ArchivedShellSnapshot, ThreadId, @@ -52,6 +54,7 @@ import { createOrchestrationEnvironmentAtoms } from "./orchestration.ts"; import { createReviewEnvironmentAtoms } from "./review.ts"; import { createPreviewEnvironmentAtoms } from "./preview.ts"; import { createFilesystemEnvironmentAtoms } from "./filesystem.ts"; +import { createIssueEnvironmentAtoms, createMergedIssueListAtoms } from "./issues.ts"; import type { QueryPersistence } from "./queryPersistence.ts"; import type { EnvironmentShellState } from "./shell.ts"; import { v2Now, v2Project, v2ThreadId, v2ThreadShell } from "./orchestrationV2TestFixtures.ts"; @@ -263,6 +266,50 @@ it.effect("keeps complete review metadata visible while a refresh is held", () = }), ); +it.effect("keeps manual Issues refresh intent through an overlapping write", () => + Effect.gen(function* () { + const requests = yield* Queue.unbounded(); + const release = yield* Deferred.make(); + const answer: IssueListResult = { + viewers: {}, + trackers: [], + entries: [], + errors: [], + nextCursors: {}, + }; + const rpcSession = { + client: { + [WS_METHODS.issuesList]: (input: IssueListInput) => + Queue.offer(requests, input).pipe( + Effect.andThen(input.refresh ? Deferred.await(release) : Effect.void), + Effect.as(answer), + ), + }, + } as unknown as RpcSession.RpcSession; + const { runtime } = yield* makeEnvironmentQueryHarness(Effect.void, { rpcSession }); + const issues = createIssueEnvironmentAtoms(runtime); + const listings = createMergedIssueListAtoms(issues.list, String); + const target = { + environmentId: QUERY_ENVIRONMENT.environmentId, + input: { state: "all" }, + } as const; + const registry = yield* mountEnvironmentQuery(listings.atom([target])); + expect(yield* Queue.take(requests)).toEqual({ state: "all" }); + yield* readEnvironmentQuery(registry, issues.list(target)); + + listings.refresh(registry, [target], "manual"); + expect(yield* Queue.take(requests)).toEqual({ state: "all", refresh: true }); + + listings.refreshEnvironment(registry, target.environmentId); + expect(yield* Queue.take(requests)).toEqual({ state: "all", refresh: true }); + + yield* Deferred.succeed(release, undefined); + yield* readEnvironmentQuery(registry, issues.list(target)); + listings.refreshEnvironment(registry, target.environmentId); + expect(yield* Queue.take(requests)).toEqual({ state: "all" }); + }), +); + describe("preview event subscriptions", () => { it.effect("delivers every open and close when RPC events arrive in batches", () => Effect.gen(function* () { diff --git a/packages/source-control-azure-devops/src/server/AzureDevOpsIssueTracker.test.ts b/packages/source-control-azure-devops/src/server/AzureDevOpsIssueTracker.test.ts index 313335dfb0224..4458e3d1dd1ae 100644 --- a/packages/source-control-azure-devops/src/server/AzureDevOpsIssueTracker.test.ts +++ b/packages/source-control-azure-devops/src/server/AzureDevOpsIssueTracker.test.ts @@ -223,6 +223,7 @@ describe("AzureDevOpsIssueTracker", () => { const hydrated: string[] = []; let typeReads = 0; let finished = "Shipped"; + let itemState = "Shipped"; let beforeWorkflowRead: | Effect.Effect | undefined; @@ -281,8 +282,12 @@ describe("AzureDevOpsIssueTracker", () => { } hydrated.push((JSON.parse(body) as { ids: number[] }).ids.join(",")); // The page as REST answers it: an envelope, in an order of its own. + const item = { + ...WORK_ITEM, + fields: { ...WORK_ITEM.fields, "System.State": itemState }, + }; return TestSourceControlHost.processOutput( - encode({ count: 2, value: [WORK_ITEM, { ...WORK_ITEM, id: 9 }] }), + encode({ count: 2, value: [item, { ...item, id: 9 }] }), ); }), ); @@ -324,6 +329,7 @@ describe("AzureDevOpsIssueTracker", () => { involvement: "all", sort: "updated", limit: 2, + refresh: true, }); expect(typeReads).toBe(2); expect(bodies[2]).toContain("AND [System.State] NOT IN ('released')"); @@ -345,13 +351,19 @@ describe("AzureDevOpsIssueTracker", () => { sort: "updated", limit: 2, } as const; - finished = "Done"; - yield* api.listIssues({ ...firstPage, refresh: false, query: "composer" }); - yield* api.listIssues({ ...firstPage, refresh: true, state: "all" }); + finished = itemState = "Done"; + yield* api.listIssues({ ...firstPage, query: "composer" }); + const all = { ...firstPage, state: "all" } as const; + const cachedAll = yield* api.listIssues(all); expect(typeReads).toBe(2); expect(bodies[3]).toContain("AND [System.State] NOT IN ('released')"); - expect(bodies[4]).not.toContain("[System.State]"); + expect(cachedAll.items.map((item) => item.state.category)).toEqual(["open", "open"]); + const refreshedAll = yield* api.listIssues({ ...all, refresh: true }); + expect(typeReads).toBe(3); + expect(bodies[5]).not.toContain("[System.State]"); + expect(refreshedAll.items.map((item) => item.state.category)).toEqual(["closed", "closed"]); + finished = "Delivered"; beforeWorkflowRead = Effect.fail( new AzureDevOpsCli.AzureDevOpsCommandFailedError({ operation: "execute", @@ -363,8 +375,8 @@ describe("AzureDevOpsIssueTracker", () => { ); yield* api.listIssues({ ...firstPage, refresh: true }); yield* api.listIssues({ ...firstPage, refresh: false }); - expect(typeReads).toBe(3); - expect(bodies.slice(5, 7).every((body) => body.includes("NOT IN ('released')"))).toBe(true); + expect(typeReads).toBe(4); + expect(bodies.slice(6, 8).every((body) => body.includes("NOT IN ('done')"))).toBe(true); const started = yield* Deferred.make(); const release = yield* Deferred.make(); @@ -383,8 +395,8 @@ describe("AzureDevOpsIssueTracker", () => { const refreshed = yield* Fiber.join(second); expect(refreshed.nextCursor).not.toBeNull(); yield* api.listIssues({ ...firstPage, cursor: refreshed.nextCursor ?? undefined }); - expect(typeReads).toBe(4); - expect(bodies.slice(7).every((body) => body.includes("NOT IN ('done')"))).toBe(true); + expect(typeReads).toBe(5); + expect(bodies.slice(8).every((body) => body.includes("NOT IN ('delivered')"))).toBe(true); }).pipe(Effect.provide(NodeFileSystem.layer)), ); diff --git a/packages/source-control-azure-devops/src/server/AzureDevOpsIssueTracker.ts b/packages/source-control-azure-devops/src/server/AzureDevOpsIssueTracker.ts index 65c2e044373b8..94089949d47fd 100644 --- a/packages/source-control-azure-devops/src/server/AzureDevOpsIssueTracker.ts +++ b/packages/source-control-azure-devops/src/server/AzureDevOpsIssueTracker.ts @@ -619,8 +619,7 @@ export const make: Effect.Effect< return yield* scoped("listIssues", input).pipe( Effect.flatMap((scope) => { const key = JSON.stringify([input.cwd, scope.organization, scope.project]); - // The service always specifies refresh intent; direct tracker calls default to fresh. - const refresh = cursor === undefined && input.state !== "all" && input.refresh !== false; + const refresh = cursor === undefined && input.refresh === true; const closed = refresh ? Cache.getSuccess(listClosedStates, key).pipe( Effect.flatMap((previous) => diff --git a/packages/source-control-core/src/server/IssueTracker.ts b/packages/source-control-core/src/server/IssueTracker.ts index 057604a66340e..b5894ed806363 100644 --- a/packages/source-control-core/src/server/IssueTracker.ts +++ b/packages/source-control-core/src/server/IssueTracker.ts @@ -127,7 +127,7 @@ export interface IssueTrackerApi { /** A cursor this tracker handed back from an earlier page. Absent asks for the first. */ readonly cursor?: string | undefined; /** Whether to re-read tracker metadata for a first page. */ - readonly refresh?: boolean; + readonly refresh?: boolean | undefined; }, ) => Effect.Effect; From 1910f35e646cbc7693d5e171d318b1f7661b9252 Mon Sep 17 00:00:00 2001 From: Wout Stiens <71498452+StiensWout@users.noreply.github.com> Date: Wed, 18 Nov 2026 16:39:31 +0100 Subject: [PATCH 07/11] test(issues): mount the merged list in the refresh test Co-authored-by: GPT 6.2 Sol --- packages/client-runtime/src/state/runtime.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/client-runtime/src/state/runtime.test.ts b/packages/client-runtime/src/state/runtime.test.ts index 3ce4f39d651e6..0eb9257cd88df 100644 --- a/packages/client-runtime/src/state/runtime.test.ts +++ b/packages/client-runtime/src/state/runtime.test.ts @@ -197,8 +197,8 @@ const readEnvironmentQuery = ( Effect.tap(() => Effect.yieldNow), ); -const mountEnvironmentQuery = Effect.fn("TestEnvironmentQuery.mount")(function* ( - atom: Atom.Atom>, +const mountEnvironmentQuery = Effect.fn("TestEnvironmentQuery.mount")(function* ( + atom: Atom.Atom, ) { const registry = AtomRegistry.make(); const unmount = registry.mount(atom); From 5cbef685362537b49164915a6e91479e0a3e5f70 Mon Sep 17 00:00:00 2001 From: Wout Stiens <71498452+StiensWout@users.noreply.github.com> Date: Thu, 19 Nov 2026 07:10:00 +0100 Subject: [PATCH 08/11] style(web): format the merged Issues list hook Co-authored-by: Claude Opus 5.5 --- apps/web/src/state/issues.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/apps/web/src/state/issues.ts b/apps/web/src/state/issues.ts index 60b0d879ccc6f..db3a993b179d1 100644 --- a/apps/web/src/state/issues.ts +++ b/apps/web/src/state/issues.ts @@ -44,9 +44,7 @@ const mergedIssueLists = createMergedIssueListAtoms( ); /** The same listing read across every connected environment, as the pull-request page does. */ -export function useIssueList( - targets: ReadonlyArray, -): MergedIssueList & { +export function useIssueList(targets: ReadonlyArray): MergedIssueList & { readonly refresh: () => void; readonly reload: () => void; readonly retry: () => void; From e53c3da2d28c6fce040605e8615b0d49f195b99e Mon Sep 17 00:00:00 2001 From: Wout Stiens <71498452+StiensWout@users.noreply.github.com> Date: Thu, 19 Nov 2026 07:25:31 +0100 Subject: [PATCH 09/11] fix(issues): own manual refresh in the list query and surface Azure errors Co-authored-by: GPT 6.2 Sol --- apps/mobile/src/state/issues.ts | 5 +- apps/web/src/state/issues.ts | 5 +- packages/client-runtime/src/state/issues.ts | 83 ++++++++++++------- .../client-runtime/src/state/runtime.test.ts | 2 +- packages/client-runtime/src/state/runtime.ts | 43 ++-------- .../server/AzureDevOpsIssueTracker.test.ts | 9 +- .../src/server/AzureDevOpsIssueTracker.ts | 12 +-- 7 files changed, 74 insertions(+), 85 deletions(-) diff --git a/apps/mobile/src/state/issues.ts b/apps/mobile/src/state/issues.ts index bbfd50ac4b013..0d7558979f916 100644 --- a/apps/mobile/src/state/issues.ts +++ b/apps/mobile/src/state/issues.ts @@ -14,10 +14,7 @@ import { formatEnvironmentQueryError } from "./query"; export const issueEnvironment = createIssueEnvironmentAtoms(connectionAtomRuntime); -const mergedIssueLists = createMergedIssueListAtoms( - issueEnvironment.list, - formatEnvironmentQueryError, -); +const mergedIssueLists = createMergedIssueListAtoms(issueEnvironment, formatEnvironmentQueryError); /** One listing read across every environment asked. */ export function useIssueList(targets: ReadonlyArray) { diff --git a/apps/web/src/state/issues.ts b/apps/web/src/state/issues.ts index db3a993b179d1..e1d91bfcb3b53 100644 --- a/apps/web/src/state/issues.ts +++ b/apps/web/src/state/issues.ts @@ -38,10 +38,7 @@ export function useLinkedIssueDetail( ).data; } -const mergedIssueLists = createMergedIssueListAtoms( - issueEnvironment.list, - formatEnvironmentQueryError, -); +const mergedIssueLists = createMergedIssueListAtoms(issueEnvironment, formatEnvironmentQueryError); /** The same listing read across every connected environment, as the pull-request page does. */ export function useIssueList(targets: ReadonlyArray): MergedIssueList & { diff --git a/packages/client-runtime/src/state/issues.ts b/packages/client-runtime/src/state/issues.ts index b0ff32a46fe0d..043a91e564f77 100644 --- a/packages/client-runtime/src/state/issues.ts +++ b/packages/client-runtime/src/state/issues.ts @@ -17,7 +17,7 @@ import type * as Cause from "effect/Cause"; import * as Effect from "effect/Effect"; import * as Exit from "effect/Exit"; import * as Option from "effect/Option"; -import { AsyncResult, Atom, type AtomRegistry } from "effect/reactivity"; +import { AsyncResult, Atom, AtomRegistry } from "effect/reactivity"; import { type AtomCommandResult, @@ -28,6 +28,7 @@ import { createEnvironmentQueryAtomFamily, } from "./runtime.ts"; import type { EnvironmentRegistry } from "../connection/registry.ts"; +import * as EnvironmentSupervisor from "../connection/supervisor.ts"; import { request } from "../rpc/client.ts"; /** One row's identity across list pages and detail reads; hosts compare case-insensitively. */ @@ -148,10 +149,7 @@ export function createIssueCommentPager( }; } -const pendingListRefreshes = new WeakMap< - AtomRegistry.AtomRegistry, - WeakMap, symbol> ->(); +type IssueListRefreshMode = "manual" | "background"; /** * Every read goes to a tracker API over the environment, so results are reused for a short while @@ -187,21 +185,31 @@ export function createIssueEnvironmentAtoms( label: "environment-data:issues:linked-thread-refreshes", tag: WS_METHODS.pullRequestsSubscribeLinkedThreadRefreshes, }); + const pendingListRefreshes = new WeakMap< + AtomRegistry.AtomRegistry, + WeakMap, symbol> + >(); + type ListRequest = ReturnType>; const list = createEnvironmentQueryAtomFamily(runtime, { label: "environment-data:issues:list", staleTimeMs: 30_000, - execute: ( + execute: Effect.fnUntraced(function* ( input: IssueListInput, - _emit, - _previous, - { environmentId, registry }, - ): ReturnType> => { - const atom = list({ environmentId, input }); + ): Effect.fn.Return< + IssueListResult, + Effect.Error, + Effect.Services | AtomRegistry.AtomRegistry + > { + const registry = yield* AtomRegistry.AtomRegistry; + const { + target: { environmentId }, + } = yield* EnvironmentSupervisor.EnvironmentSupervisor; const pending = pendingListRefreshes.get(registry); - const intent = pending?.get(atom); - if (pending === undefined || intent === undefined) - return request(WS_METHODS.issuesList, input); - return request(WS_METHODS.issuesList, { ...input, refresh: true }).pipe( + if (pending === undefined) return yield* request(WS_METHODS.issuesList, input); + const atom = list({ environmentId, input }); + const intent = pending.get(atom); + if (intent === undefined) return yield* request(WS_METHODS.issuesList, input); + return yield* request(WS_METHODS.issuesList, { ...input, refresh: true }).pipe( // Invalidation interrupts the read; its replacement still owes the explicit refresh. Effect.onExit((exit) => Effect.sync(() => { @@ -209,7 +217,7 @@ export function createIssueEnvironmentAtoms( }), ), ); - }, + }), }); return { /** The threads an issue is linked to, reread when the server signals a link changed. */ @@ -220,6 +228,22 @@ export function createIssueEnvironmentAtoms( refreshTrigger: ({ environmentId }) => linkedThreadSignals({ environmentId, input: {} }), }), list, + refreshList( + registry: AtomRegistry.AtomRegistry, + target: IssueListTarget, + mode: IssueListRefreshMode, + ) { + const atom = list(target); + if (mode === "manual") { + let pending = pendingListRefreshes.get(registry); + if (pending === undefined) { + pending = new WeakMap(); + pendingListRefreshes.set(registry, pending); + } + pending.set(atom, Symbol()); + } + registry.refresh(atom); + }, /** * A continuation of the listing, run as a command rather than read as a query: a page is * asked for once and laid over the rows held, and a refresh of the first page forgets it. @@ -328,7 +352,19 @@ function refreshFailed( * the environments that failed, so a read still in flight elsewhere is not restarted. */ export function createMergedIssueListAtoms( - list: (target: IssueListTarget) => Atom.Atom>, + { + list, + refreshList, + }: { + readonly list: ( + target: IssueListTarget, + ) => Atom.Atom>; + readonly refreshList: ( + registry: AtomRegistry.AtomRegistry, + target: IssueListTarget, + mode: IssueListRefreshMode, + ) => void; + }, formatError: (cause: Cause.Cause) => string, ) { const empty = Atom.make(NO_ISSUE_LISTS).pipe(Atom.withLabel("issues:merged-list:empty")); @@ -350,18 +386,9 @@ export function createMergedIssueListAtoms( const refresh = ( registry: AtomRegistry.AtomRegistry, targets: ReadonlyArray, - mode: "manual" | "background", + mode: IssueListRefreshMode, ) => { - let pending = pendingListRefreshes.get(registry); - if (mode === "manual" && pending === undefined) { - pending = new WeakMap(); - pendingListRefreshes.set(registry, pending); - } - for (const target of targets) { - const atom = list(target); - if (mode === "manual") pending?.set(atom, Symbol()); - registry.refresh(atom); - } + for (const target of targets) refreshList(registry, target, mode); }; // The targets behind each listing atom, so a write made elsewhere can refresh the ones still // shown. Weak, so a closed search goes with its atom once the registry drops it. diff --git a/packages/client-runtime/src/state/runtime.test.ts b/packages/client-runtime/src/state/runtime.test.ts index 0eb9257cd88df..0265aa5266a6f 100644 --- a/packages/client-runtime/src/state/runtime.test.ts +++ b/packages/client-runtime/src/state/runtime.test.ts @@ -288,7 +288,7 @@ it.effect("keeps manual Issues refresh intent through an overlapping write", () } as unknown as RpcSession.RpcSession; const { runtime } = yield* makeEnvironmentQueryHarness(Effect.void, { rpcSession }); const issues = createIssueEnvironmentAtoms(runtime); - const listings = createMergedIssueListAtoms(issues.list, String); + const listings = createMergedIssueListAtoms(issues, String); const target = { environmentId: QUERY_ENVIRONMENT.environmentId, input: { state: "all" }, diff --git a/packages/client-runtime/src/state/runtime.ts b/packages/client-runtime/src/state/runtime.ts index 82c5240458b3c..01b51b9a88761 100644 --- a/packages/client-runtime/src/state/runtime.ts +++ b/packages/client-runtime/src/state/runtime.ts @@ -94,10 +94,6 @@ interface EnvironmentQueryAtomOptions extends Omit< input: Input, emit: (value: A) => Effect.Effect, previous: Option.Option, - context: { - readonly environmentId: EnvironmentIdType; - readonly registry: AtomRegistry.AtomRegistry; - }, ) => Effect.Effect; readonly persistence?: QueryPersistence; readonly staleTimeMs?: number; @@ -739,15 +735,11 @@ export function createEnvironmentQueryAtomFamily( get(connectionAtom(target.environmentId)), () => null, ); + const previous = () => + Option.flatMap(get.self>(), AsyncResult.value); // A refetch that returns equal content keeps the previous value's // references, so readers of the data skip re-rendering on idle polls. - const share = (value: A): A => - reuseUnchanged( - Option.getOrUndefined( - Option.flatMap(get.self>(), AsyncResult.value), - ), - value, - ); + const share = (value: A): A => reuseUnchanged(Option.getOrUndefined(previous()), value); const emit = (value: A) => Effect.sync(() => get.setSelf(AsyncResult.success(share(value), { waiting: true }))).pipe( // A value set while the atom builds wins over the build's own @@ -774,15 +766,7 @@ export function createEnvironmentQueryAtomFamily( ? runInEnvironment( target.environmentId, options - .execute( - target.input, - emit, - Option.flatMap( - get.self>(), - AsyncResult.value, - ), - { environmentId: target.environmentId, registry: get.registry }, - ) + .execute(target.input, emit, previous()) .pipe(pendingOnceSessionReplaced(session.value)), ) : Effect.never; @@ -791,13 +775,7 @@ export function createEnvironmentQueryAtomFamily( // A retry can take minutes. A query with an answer keeps showing it while it // waits; one with nothing to show reports the failure the retry is recovering // from, so its reader stops loading, and re-runs when the connection settles. - return connectionState.lastFailure !== null && - Option.isNone( - Option.flatMap( - get.self>(), - AsyncResult.value, - ), - ) + return connectionState.lastFailure !== null && Option.isNone(previous()) ? Effect.fail(connectionState.lastFailure) : Effect.never; case "available": @@ -837,13 +815,10 @@ export function createEnvironmentQueryAtomFamily( if (!options.persistence) return answer(); const persistence = options.persistence; const cacheKey = queryPersistenceKey(options.label, target.input); - const previous = Option.flatMap( - get.self>(), - AsyncResult.value, - ); + const beforeLoad = previous(); return Effect.gen(function* () { - const cached = Option.isSome(previous) - ? previous + const cached = Option.isSome(beforeLoad) + ? beforeLoad : yield* persistence.load(target.environmentId, cacheKey); if ( Option.isSome(cached) && @@ -851,7 +826,7 @@ export function createEnvironmentQueryAtomFamily( ) { return cached.value; } - if (Option.isNone(previous) && Option.isSome(cached)) yield* emit(cached.value); + if (Option.isNone(beforeLoad) && Option.isSome(cached)) yield* emit(cached.value); // Readers must not wait on the disk: web saves one IndexedDB row per listed PR's stats. // The save ends with the query, so a removed environment's cache stays cleared. return yield* answer().pipe( diff --git a/packages/source-control-azure-devops/src/server/AzureDevOpsIssueTracker.test.ts b/packages/source-control-azure-devops/src/server/AzureDevOpsIssueTracker.test.ts index 4458e3d1dd1ae..f88ee59bf6837 100644 --- a/packages/source-control-azure-devops/src/server/AzureDevOpsIssueTracker.test.ts +++ b/packages/source-control-azure-devops/src/server/AzureDevOpsIssueTracker.test.ts @@ -373,10 +373,12 @@ describe("AzureDevOpsIssueTracker", () => { cause: "workflow metadata unavailable", }), ); - yield* api.listIssues({ ...firstPage, refresh: true }); + const refreshError = yield* Effect.flip(api.listIssues({ ...firstPage, refresh: true })); + expect(refreshError).toMatchObject({ operation: "listIssues", reason: "failed" }); + expect(bodies).toHaveLength(6); yield* api.listIssues({ ...firstPage, refresh: false }); expect(typeReads).toBe(4); - expect(bodies.slice(6, 8).every((body) => body.includes("NOT IN ('done')"))).toBe(true); + expect(bodies[6]).toContain("NOT IN ('done')"); const started = yield* Deferred.make(); const release = yield* Deferred.make(); @@ -396,7 +398,8 @@ describe("AzureDevOpsIssueTracker", () => { expect(refreshed.nextCursor).not.toBeNull(); yield* api.listIssues({ ...firstPage, cursor: refreshed.nextCursor ?? undefined }); expect(typeReads).toBe(5); - expect(bodies.slice(8).every((body) => body.includes("NOT IN ('delivered')"))).toBe(true); + expect(bodies.slice(7)).toHaveLength(3); + expect(bodies.slice(7).every((body) => body.includes("NOT IN ('delivered')"))).toBe(true); }).pipe(Effect.provide(NodeFileSystem.layer)), ); diff --git a/packages/source-control-azure-devops/src/server/AzureDevOpsIssueTracker.ts b/packages/source-control-azure-devops/src/server/AzureDevOpsIssueTracker.ts index 94089949d47fd..30bc0f09475f1 100644 --- a/packages/source-control-azure-devops/src/server/AzureDevOpsIssueTracker.ts +++ b/packages/source-control-azure-devops/src/server/AzureDevOpsIssueTracker.ts @@ -620,17 +620,7 @@ export const make: Effect.Effect< Effect.flatMap((scope) => { const key = JSON.stringify([input.cwd, scope.organization, scope.project]); const refresh = cursor === undefined && input.refresh === true; - const closed = refresh - ? Cache.getSuccess(listClosedStates, key).pipe( - Effect.flatMap((previous) => - Cache.get(workflowReads, key).pipe( - Effect.catch((error) => - Effect.fromOption(previous).pipe(Effect.mapError(() => error)), - ), - ), - ), - ) - : Cache.get(listClosedStates, key); + const closed = refresh ? Cache.get(workflowReads, key) : Cache.get(listClosedStates, key); return closed.pipe(Effect.map((closed) => ({ scope, closed }))); }), Effect.flatMap(({ scope, closed }) => From e72e5a0b6441360191f824220040f4dbac281b05 Mon Sep 17 00:00:00 2001 From: Wout Stiens <71498452+StiensWout@users.noreply.github.com> Date: Thu, 19 Nov 2026 07:27:14 +0100 Subject: [PATCH 10/11] test(issues): pass explicit refresh to merged list fixtures Co-authored-by: GPT 6.2 Sol --- packages/client-runtime/src/state/issues.test.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/client-runtime/src/state/issues.test.ts b/packages/client-runtime/src/state/issues.test.ts index 587280be65912..6c80d8faf82ba 100644 --- a/packages/client-runtime/src/state/issues.test.ts +++ b/packages/client-runtime/src/state/issues.test.ts @@ -189,7 +189,7 @@ describe("createMergedIssueListAtoms", () => { it("refreshes the open listings of the environment written to", () => { const reads = new Map(); const lists = new Map>>(); - const listings = createMergedIssueListAtoms((target) => { + const list = (target: IssueListTarget) => { const key = `${target.environmentId}:${target.input.query}`; const existing = lists.get(key); if (existing !== undefined) return existing; @@ -199,7 +199,11 @@ describe("createMergedIssueListAtoms", () => { }); lists.set(key, atom); return atom; - }, String); + }; + const listings = createMergedIssueListAtoms( + { list, refreshList: (registry, target) => registry.refresh(list(target)) }, + String, + ); const registry = AtomRegistry.make(); const written = EnvironmentId.make("written"); const other = EnvironmentId.make("other"); @@ -234,7 +238,7 @@ describe("createMergedIssueListAtoms", () => { ), ); const listings = createMergedIssueListAtoms( - (target) => lists(target.environmentId), + { list: (target) => lists(target.environmentId), refreshList: () => {} }, () => "Tracker unavailable", ); const view = listings.atom(targets); @@ -255,7 +259,7 @@ describe("createMergedIssueListAtoms", () => { NodeV8.setFlagsFromString("--expose-gc"); const gc = NodeVM.runInNewContext("gc") as () => void; const listings = createMergedIssueListAtoms( - () => Atom.make(AsyncResult.success(answer)), + { list: () => Atom.make(AsyncResult.success(answer)), refreshList: () => {} }, String, ); const registry = AtomRegistry.make(); From 81c7fffebd9179256ca17d20dad8e855e617013c Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Thu, 19 Nov 2026 06:49:43 +0000 Subject: [PATCH 11/11] refactor(issues): trim the Azure refresh change to the fix Drop an unrelated helper extraction in the query runtime and cut the Azure tracker test down to the refresh and failed-refresh cases. Co-Authored-By: Claude Opus 5.5 --- packages/client-runtime/src/state/runtime.ts | 38 +++++-- .../server/AzureDevOpsIssueTracker.test.ts | 101 ++++-------------- .../src/server/AzureDevOpsIssueTracker.ts | 4 +- 3 files changed, 50 insertions(+), 93 deletions(-) diff --git a/packages/client-runtime/src/state/runtime.ts b/packages/client-runtime/src/state/runtime.ts index 01b51b9a88761..ac55aba2da28c 100644 --- a/packages/client-runtime/src/state/runtime.ts +++ b/packages/client-runtime/src/state/runtime.ts @@ -735,11 +735,15 @@ export function createEnvironmentQueryAtomFamily( get(connectionAtom(target.environmentId)), () => null, ); - const previous = () => - Option.flatMap(get.self>(), AsyncResult.value); // A refetch that returns equal content keeps the previous value's // references, so readers of the data skip re-rendering on idle polls. - const share = (value: A): A => reuseUnchanged(Option.getOrUndefined(previous()), value); + const share = (value: A): A => + reuseUnchanged( + Option.getOrUndefined( + Option.flatMap(get.self>(), AsyncResult.value), + ), + value, + ); const emit = (value: A) => Effect.sync(() => get.setSelf(AsyncResult.success(share(value), { waiting: true }))).pipe( // A value set while the atom builds wins over the build's own @@ -766,7 +770,14 @@ export function createEnvironmentQueryAtomFamily( ? runInEnvironment( target.environmentId, options - .execute(target.input, emit, previous()) + .execute( + target.input, + emit, + Option.flatMap( + get.self>(), + AsyncResult.value, + ), + ) .pipe(pendingOnceSessionReplaced(session.value)), ) : Effect.never; @@ -775,7 +786,13 @@ export function createEnvironmentQueryAtomFamily( // A retry can take minutes. A query with an answer keeps showing it while it // waits; one with nothing to show reports the failure the retry is recovering // from, so its reader stops loading, and re-runs when the connection settles. - return connectionState.lastFailure !== null && Option.isNone(previous()) + return connectionState.lastFailure !== null && + Option.isNone( + Option.flatMap( + get.self>(), + AsyncResult.value, + ), + ) ? Effect.fail(connectionState.lastFailure) : Effect.never; case "available": @@ -815,10 +832,13 @@ export function createEnvironmentQueryAtomFamily( if (!options.persistence) return answer(); const persistence = options.persistence; const cacheKey = queryPersistenceKey(options.label, target.input); - const beforeLoad = previous(); + const previous = Option.flatMap( + get.self>(), + AsyncResult.value, + ); return Effect.gen(function* () { - const cached = Option.isSome(beforeLoad) - ? beforeLoad + const cached = Option.isSome(previous) + ? previous : yield* persistence.load(target.environmentId, cacheKey); if ( Option.isSome(cached) && @@ -826,7 +846,7 @@ export function createEnvironmentQueryAtomFamily( ) { return cached.value; } - if (Option.isNone(beforeLoad) && Option.isSome(cached)) yield* emit(cached.value); + if (Option.isNone(previous) && Option.isSome(cached)) yield* emit(cached.value); // Readers must not wait on the disk: web saves one IndexedDB row per listed PR's stats. // The save ends with the query, so a removed environment's cache stays cleared. return yield* answer().pipe( diff --git a/packages/source-control-azure-devops/src/server/AzureDevOpsIssueTracker.test.ts b/packages/source-control-azure-devops/src/server/AzureDevOpsIssueTracker.test.ts index f88ee59bf6837..4177b9a720d81 100644 --- a/packages/source-control-azure-devops/src/server/AzureDevOpsIssueTracker.test.ts +++ b/packages/source-control-azure-devops/src/server/AzureDevOpsIssueTracker.test.ts @@ -1,8 +1,6 @@ import { describe, expect, it } from "@effect/vitest"; import * as NodeFileSystem from "@effect/platform-node/NodeFileSystem"; -import * as Deferred from "effect/Deferred"; import * as Effect from "effect/Effect"; -import * as Fiber from "effect/Fiber"; import * as FileSystem from "effect/FileSystem"; import * as PlatformError from "effect/PlatformError"; import * as Layer from "effect/Layer"; @@ -223,10 +221,7 @@ describe("AzureDevOpsIssueTracker", () => { const hydrated: string[] = []; let typeReads = 0; let finished = "Shipped"; - let itemState = "Shipped"; - let beforeWorkflowRead: - | Effect.Effect - | undefined; + let workflowUnavailable = false; const api = yield* AzureDevOpsIssueTracker.make.pipe( Effect.provide( Layer.mock(AzureDevOpsCli.AzureDevOpsCli)({ @@ -247,17 +242,15 @@ describe("AzureDevOpsIssueTracker", () => { } if (resource === "workitemtypes") { typeReads += 1; - if (beforeWorkflowRead !== undefined) { - return beforeWorkflowRead.pipe( - Effect.as( - TestSourceControlHost.processOutput( - encode({ - value: [ - { name: "Bug", states: [{ name: finished, category: "Completed" }] }, - ], - }), - ), - ), + if (workflowUnavailable) { + return Effect.fail( + new AzureDevOpsCli.AzureDevOpsCommandFailedError({ + operation: "execute", + command: "az", + cwd: "/w", + argumentCount: args.length, + cause: "workflow metadata unavailable", + }), ); } return Effect.succeed( @@ -282,12 +275,8 @@ describe("AzureDevOpsIssueTracker", () => { } hydrated.push((JSON.parse(body) as { ids: number[] }).ids.join(",")); // The page as REST answers it: an envelope, in an order of its own. - const item = { - ...WORK_ITEM, - fields: { ...WORK_ITEM.fields, "System.State": itemState }, - }; return TestSourceControlHost.processOutput( - encode({ count: 2, value: [item, { ...item, id: 9 }] }), + encode({ count: 2, value: [WORK_ITEM, { ...WORK_ITEM, id: 9 }] }), ); }), ); @@ -319,20 +308,6 @@ describe("AzureDevOpsIssueTracker", () => { expect(bodies).toHaveLength(2); expect(bodies[1]).toBe(bodies[0]); expect(bodies[0]).toContain("AND [System.State] NOT IN ('shipped')"); - // A first page is a fresh list, so it sees a finished state added since. - finished = "Released"; - yield* api.listIssues({ - cwd: "/w", - host: "dev.azure.com", - scope: "acme/Web App", - state: "open", - involvement: "all", - sort: "updated", - limit: 2, - refresh: true, - }); - expect(typeReads).toBe(2); - expect(bodies[2]).toContain("AND [System.State] NOT IN ('released')"); const { query } = JSON.parse(bodies[0]!) as { query: string }; // Mentions cannot be asked for over REST, so the filter sends no clause for them. expect(query).not.toContain("@RecentMentions"); @@ -342,6 +317,7 @@ describe("AzureDevOpsIssueTracker", () => { " ORDER BY [System.CreatedDate] DESC, [System.Id] DESC", ); + // An explicit refresh rereads the workflow; a failed one keeps the last good states. const firstPage = { cwd: "/w", host: "dev.azure.com", @@ -351,55 +327,16 @@ describe("AzureDevOpsIssueTracker", () => { sort: "updated", limit: 2, } as const; - finished = itemState = "Done"; - yield* api.listIssues({ ...firstPage, query: "composer" }); - const all = { ...firstPage, state: "all" } as const; - const cachedAll = yield* api.listIssues(all); + finished = "Released"; + yield* api.listIssues({ ...firstPage, refresh: true }); expect(typeReads).toBe(2); - expect(bodies[3]).toContain("AND [System.State] NOT IN ('released')"); - expect(cachedAll.items.map((item) => item.state.category)).toEqual(["open", "open"]); - const refreshedAll = yield* api.listIssues({ ...all, refresh: true }); - expect(typeReads).toBe(3); - expect(bodies[5]).not.toContain("[System.State]"); - expect(refreshedAll.items.map((item) => item.state.category)).toEqual(["closed", "closed"]); - - finished = "Delivered"; - beforeWorkflowRead = Effect.fail( - new AzureDevOpsCli.AzureDevOpsCommandFailedError({ - operation: "execute", - command: "az", - cwd: "/w", - argumentCount: 0, - cause: "workflow metadata unavailable", - }), - ); + expect(bodies[2]).toContain("AND [System.State] NOT IN ('released')"); + workflowUnavailable = true; const refreshError = yield* Effect.flip(api.listIssues({ ...firstPage, refresh: true })); expect(refreshError).toMatchObject({ operation: "listIssues", reason: "failed" }); - expect(bodies).toHaveLength(6); - yield* api.listIssues({ ...firstPage, refresh: false }); - expect(typeReads).toBe(4); - expect(bodies[6]).toContain("NOT IN ('done')"); - - const started = yield* Deferred.make(); - const release = yield* Deferred.make(); - beforeWorkflowRead = Deferred.succeed(started, undefined).pipe( - Effect.andThen(Deferred.await(release)), - ); - const first = yield* Effect.forkChild(api.listIssues({ ...firstPage, refresh: true }), { - startImmediately: true, - }); - yield* Deferred.await(started); - const second = yield* Effect.forkChild(api.listIssues({ ...firstPage, refresh: true }), { - startImmediately: true, - }); - yield* Deferred.succeed(release, undefined); - yield* Fiber.join(first); - const refreshed = yield* Fiber.join(second); - expect(refreshed.nextCursor).not.toBeNull(); - yield* api.listIssues({ ...firstPage, cursor: refreshed.nextCursor ?? undefined }); - expect(typeReads).toBe(5); - expect(bodies.slice(7)).toHaveLength(3); - expect(bodies.slice(7).every((body) => body.includes("NOT IN ('delivered')"))).toBe(true); + yield* api.listIssues(firstPage); + expect(typeReads).toBe(3); + expect(bodies[3]).toContain("AND [System.State] NOT IN ('released')"); }).pipe(Effect.provide(NodeFileSystem.layer)), ); diff --git a/packages/source-control-azure-devops/src/server/AzureDevOpsIssueTracker.ts b/packages/source-control-azure-devops/src/server/AzureDevOpsIssueTracker.ts index 30bc0f09475f1..8fbd08feeadd7 100644 --- a/packages/source-control-azure-devops/src/server/AzureDevOpsIssueTracker.ts +++ b/packages/source-control-azure-devops/src/server/AzureDevOpsIssueTracker.ts @@ -360,7 +360,7 @@ export const make: Effect.Effect< decode: decodeAs(decodeTypes), }).pipe(Effect.map((types) => types.value)); - // A warm list can use the last good workflow while an explicit refresh is in flight. + // Shares one in-flight workflow read per project; only a success replaces the cached states. const workflowReads = yield* Cache.makeWith( (key: string) => { const [cwd, organization, project] = JSON.parse(key) as [string, string, string]; @@ -371,7 +371,7 @@ export const make: Effect.Effect< }, { capacity: Infinity, timeToLive: () => Duration.zero }, ); - // Cache misses and explicit refreshes share the same in-flight read and publication. + // Each `az` call costs seconds of startup, and a project's states rarely change. const listClosedStates: Cache.Cache = yield* Cache.makeWith((key: string) => Cache.get(workflowReads, key), { capacity: 256,