mirror of
https://github.com/getpaseo/paseo.git
synced 2026-11-18 22:35:22 +00:00
Compare commits
5
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bcf52f93b1 | ||
|
|
d8c98400fb | ||
|
|
77392d3c1b | ||
|
|
8edccf0503 | ||
|
|
ac633eb096 |
@@ -56,11 +56,20 @@ function inFlightTurn(page: Page) {
|
||||
return page.getByTestId("turn-working-indicator");
|
||||
}
|
||||
|
||||
/**
|
||||
* Presses a fork trigger until its menu shows.
|
||||
*
|
||||
* The in-flight turn's trigger sits below text that is still streaming in. While the chat is
|
||||
* shorter than the viewport, each new line moves the trigger down. A line that arrives between
|
||||
* the press and the release moves the trigger away from the pointer, so the press opens nothing,
|
||||
* and the next press lands on the trigger where it is now.
|
||||
*/
|
||||
async function openForkMenu(page: Page, trigger: ReturnType<Page["getByRole"]>): Promise<void> {
|
||||
await trigger.click();
|
||||
await expect(page.getByRole("menuitem", { name: "Fork in a new tab" })).toBeVisible({
|
||||
timeout: 10_000,
|
||||
});
|
||||
const forkInNewTab = page.getByRole("menuitem", { name: "Fork in a new tab" });
|
||||
await expect(async () => {
|
||||
await trigger.click({ timeout: 5_000 });
|
||||
await expect(forkInNewTab).toBeVisible({ timeout: 5_000 });
|
||||
}).toPass({ timeout: 30_000 });
|
||||
}
|
||||
|
||||
export async function openMostRecentAssistantForkMenu(page: Page): Promise<void> {
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -215,6 +215,32 @@ describe("Mermaid sandbox runtime", () => {
|
||||
expect(widths).toEqual([240, 350, 900]);
|
||||
});
|
||||
|
||||
/**
|
||||
* Agents often write a label that starts with a mention or holds an email address. Mermaid 11
|
||||
* read the text up to the "@" as an edge id, so these diagrams failed to parse.
|
||||
*/
|
||||
it.each([
|
||||
"flowchart LR\n F[@mention in any workspace] --> G[Look up token]",
|
||||
"flowchart LR\n A[ops@example.com] --> B",
|
||||
"flowchart LR\n A -->|@user approves| B",
|
||||
"graph TD\n A(@x) --> B{@x?}",
|
||||
])("renders a flowchart whose label contains an @: %s", async (source) => {
|
||||
const frame = await mountRuntime();
|
||||
|
||||
const result = await render(frame, { revision: 1, source });
|
||||
|
||||
expect(result).toMatchObject({ type: "rendered", revision: 1, source });
|
||||
});
|
||||
|
||||
it("still renders a flowchart edge id", async () => {
|
||||
const frame = await mountRuntime();
|
||||
const source = "flowchart LR\n A[Start] e1@--> B[End]";
|
||||
|
||||
const result = await render(frame, { revision: 1, source });
|
||||
|
||||
expect(result).toMatchObject({ type: "rendered", revision: 1, source });
|
||||
});
|
||||
|
||||
it("coalesces queued input and never reports an obsolete result", async () => {
|
||||
const frame = await mountRuntime();
|
||||
const obsoleteSource = `flowchart TD\n${Array.from({ length: 250 }, (_, index) => `A${index} --> A${index + 1}`).join("\n")}`;
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
// @vitest-environment jsdom
|
||||
import type { ReactNode } from "react";
|
||||
import { cleanup, renderHook, waitFor } from "@testing-library/react";
|
||||
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
||||
import { afterEach, beforeEach, expect, it } from "vitest";
|
||||
import type { FileReadResult } from "@getpaseo/client/internal/daemon-client";
|
||||
import { __setAttachmentStoreForTests } from "@/attachments/store";
|
||||
import type { AttachmentStore } from "@/attachments/types";
|
||||
import { useMarkdownSource, type MarkdownImageContext } from "./images";
|
||||
import { PENDING_MARKDOWN_IMAGE } from "./source";
|
||||
|
||||
const memoryStore: AttachmentStore = {
|
||||
storageType: "web-indexeddb",
|
||||
async save(input) {
|
||||
return {
|
||||
id: input.id ?? "att_chart",
|
||||
mimeType: input.mimeType ?? "image/png",
|
||||
storageType: "web-indexeddb",
|
||||
storageKey: input.id ?? "att_chart",
|
||||
fileName: input.fileName,
|
||||
createdAt: 1,
|
||||
};
|
||||
},
|
||||
async encodeBase64() {
|
||||
return "";
|
||||
},
|
||||
async resolvePreviewUrl() {
|
||||
return "blob:chart";
|
||||
},
|
||||
async releasePreviewUrl() {},
|
||||
async delete() {},
|
||||
async garbageCollect() {},
|
||||
};
|
||||
|
||||
function createHostFiles() {
|
||||
const reads: { cwd: string; path: string }[] = [];
|
||||
return {
|
||||
reads,
|
||||
async readFile(cwd: string, path: string): Promise<FileReadResult> {
|
||||
reads.push({ cwd, path });
|
||||
return {
|
||||
kind: "image",
|
||||
path,
|
||||
mime: "image/png",
|
||||
size: 4,
|
||||
modifiedAt: "2026-11-18T00:00:00.000Z",
|
||||
bytes: new Uint8Array([1, 2, 3, 4]),
|
||||
};
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
__setAttachmentStoreForTests(memoryStore);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
cleanup();
|
||||
__setAttachmentStoreForTests(null);
|
||||
});
|
||||
|
||||
function renderMarkdownSource(text: string, initialProps: MarkdownImageContext) {
|
||||
// No retries: a failed read settles at once. For a host's Markdown this is the state once the
|
||||
// retries have run out on a host that is slow to connect.
|
||||
const queryClient = new QueryClient({ defaultOptions: { queries: { retry: false } } });
|
||||
const wrapper = ({ children }: { children: ReactNode }) => (
|
||||
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
|
||||
);
|
||||
const rendered = renderHook((props: MarkdownImageContext) => useMarkdownSource(text, props), {
|
||||
wrapper,
|
||||
initialProps,
|
||||
});
|
||||
return { ...rendered, queryClient };
|
||||
}
|
||||
|
||||
it("waits for the host's client before reading a workspace image", async () => {
|
||||
const context = { serverId: "srv_test", workspaceRoot: "/repo" };
|
||||
const { result, rerender, queryClient } = renderMarkdownSource("", {
|
||||
...context,
|
||||
client: null,
|
||||
});
|
||||
|
||||
await waitFor(() => {
|
||||
expect(queryClient.isFetching()).toBe(0);
|
||||
expect(result.current.markdown.replace(PENDING_MARKDOWN_IMAGE, "pending")).toBe(
|
||||
"",
|
||||
);
|
||||
});
|
||||
|
||||
const files = createHostFiles();
|
||||
rerender({ ...context, client: files });
|
||||
|
||||
await waitFor(() => expect(result.current.imageSources).toEqual({ "blob:chart": "chart.png" }));
|
||||
expect(files.reads).toEqual([{ cwd: "/repo", path: "chart.png" }]);
|
||||
});
|
||||
|
||||
it("shows the alt text of a file image in Markdown that belongs to no host", async () => {
|
||||
const { result } = renderMarkdownSource("", {});
|
||||
|
||||
await waitFor(() =>
|
||||
expect(result.current.markdown.replace(PENDING_MARKDOWN_IMAGE, "pending")).toBe("Chart"),
|
||||
);
|
||||
});
|
||||
@@ -81,7 +81,10 @@ export function useMarkdownSource(
|
||||
const results = useFetchQueries(
|
||||
acquisitions.map((acquisition, index) => ({
|
||||
queryKey: ["markdownImage", acquisition?.key ?? sources[index]],
|
||||
enabled: acquisition !== null,
|
||||
// A host that hasn't connected yet has no client. Its images stay pending until it does: the
|
||||
// key doesn't change when the client arrives, so a read that already failed would not run
|
||||
// again. Markdown with no host has no client to wait for and falls back to its alt text.
|
||||
enabled: acquisition !== null && (context.client != null || !context.serverId),
|
||||
immutableWhen: () => true,
|
||||
dataShape: "value",
|
||||
gcTime: 0,
|
||||
|
||||
@@ -605,6 +605,8 @@ class ProviderRuntimeSession {
|
||||
>();
|
||||
private readonly activeTurnIds = new Set<string>();
|
||||
private terminal = false;
|
||||
// The provider ended this session with session.closed, so it has nothing left to close.
|
||||
private closedByProvider = false;
|
||||
private closePromise: Promise<void> | null = null;
|
||||
config: ProviderConfigState = { models: [], modes: [], thinkingOptions: [] };
|
||||
commands: Array<{ name: string; description: string; argumentHint?: string }> = [];
|
||||
@@ -723,7 +725,7 @@ class ProviderRuntimeSession {
|
||||
|
||||
async close(): Promise<void> {
|
||||
this.history.length = 0;
|
||||
if (this.restoration === "parent") {
|
||||
if (this.restoration === "parent" || this.closedByProvider) {
|
||||
this.runtime.removeSession(this.id, this.providerSessionId);
|
||||
return;
|
||||
}
|
||||
@@ -788,6 +790,7 @@ class ProviderRuntimeSession {
|
||||
return;
|
||||
}
|
||||
if (event.type === "session.runtime_failed" || event.type === "session.closed") {
|
||||
if (event.type === "session.closed") this.closedByProvider = true;
|
||||
if (this.terminal) return;
|
||||
this.terminal = true;
|
||||
this.publish(event);
|
||||
|
||||
@@ -0,0 +1,193 @@
|
||||
import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import path from "node:path";
|
||||
import { expect, onTestFinished, test } from "vitest";
|
||||
import { DaemonClient } from "../test-utils/daemon-client.js";
|
||||
import { createTestPaseoDaemon } from "../test-utils/paseo-daemon.js";
|
||||
import { resolveDaemonVersion } from "../daemon-version.js";
|
||||
|
||||
const PROVIDER_ID = "closing-provider";
|
||||
const PLUGIN_ID = "closing-provider-plugin";
|
||||
|
||||
// How the provider ends the session that ran the first turn.
|
||||
type CloseMode =
|
||||
// The first turn completes, then the provider closes the session on its own.
|
||||
| "after-turn"
|
||||
// The first turn fails and the provider closes the session with the failure.
|
||||
| "after-failed-turn"
|
||||
// The provider answers the second prompt by closing the session.
|
||||
| "on-next-prompt";
|
||||
|
||||
async function createClosingProviderPlugin(root: string, mode: CloseMode): Promise<string> {
|
||||
const directory = path.join(root, "plugin");
|
||||
await mkdir(directory, { recursive: true });
|
||||
await writeFile(
|
||||
path.join(directory, "paseo-plugin.json"),
|
||||
JSON.stringify({
|
||||
id: PLUGIN_ID,
|
||||
requirements: { paseo: `>=${resolveDaemonVersion(import.meta.url)}` },
|
||||
}),
|
||||
);
|
||||
await writeFile(
|
||||
path.join(directory, "index.server.ts"),
|
||||
`import type {
|
||||
ProviderEvent,
|
||||
ProviderInput,
|
||||
ProviderRegistration,
|
||||
} from "@getpaseo/plugin/server/provider";
|
||||
|
||||
const CAPABILITIES = ["prompt.message", "session.persistence"];
|
||||
const MODE = ${JSON.stringify(mode)};
|
||||
|
||||
const provider: ProviderRegistration = {
|
||||
id: ${JSON.stringify(PROVIDER_ID)},
|
||||
label: "Closing provider",
|
||||
async connect() {
|
||||
let listener: ((event: ProviderEvent) => void) | null = null;
|
||||
const emit = (event: ProviderEvent) => listener?.(event);
|
||||
let turn = 0;
|
||||
const closed = new Set<string>();
|
||||
return {
|
||||
version: 1,
|
||||
capabilities: CAPABILITIES,
|
||||
async send(input: ProviderInput) {
|
||||
if (input.type === "catalog") {
|
||||
emit({
|
||||
type: "catalog",
|
||||
requestId: input.requestId,
|
||||
catalog: {
|
||||
models: [{ id: "closing-model", label: "Closing model" }],
|
||||
modes: [],
|
||||
thinkingOptions: [],
|
||||
defaultModel: "closing-model",
|
||||
},
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (input.type === "session.open") {
|
||||
emit({
|
||||
type: "session.opened",
|
||||
requestId: input.requestId,
|
||||
sessionId: input.sessionId,
|
||||
capabilities: CAPABILITIES,
|
||||
restoration: "core",
|
||||
persistence: { version: 1, data: { token: "root" } },
|
||||
cwd: input.config.cwd,
|
||||
});
|
||||
emit({ type: "session.ready", requestId: input.requestId, sessionId: input.sessionId });
|
||||
return;
|
||||
}
|
||||
if (input.type === "session.prompt") {
|
||||
turn += 1;
|
||||
if (MODE === "on-next-prompt" && turn === 2) {
|
||||
closed.add(input.sessionId);
|
||||
emit({ type: "session.closed", sessionId: input.sessionId });
|
||||
return;
|
||||
}
|
||||
const turnId = "turn-" + turn;
|
||||
emit({
|
||||
type: "session.prompt_result",
|
||||
sessionId: input.sessionId,
|
||||
clientMessageId: input.prompt.clientMessageId,
|
||||
result: { type: "turn", turnId },
|
||||
});
|
||||
emit({ type: "session.turn", sessionId: input.sessionId, turnId, state: "started" });
|
||||
if (MODE === "after-failed-turn" && turn === 1) {
|
||||
emit({ type: "session.turn", sessionId: input.sessionId, turnId, state: "failed", error: { message: "Provider turn failed" } });
|
||||
emit({ type: "session.closed", sessionId: input.sessionId, error: { message: "Provider turn failed" } });
|
||||
return;
|
||||
}
|
||||
emit({
|
||||
type: "timeline.item",
|
||||
sessionId: input.sessionId,
|
||||
item: { type: "assistant_message", id: "answer-" + turn, text: "Done " + turn },
|
||||
});
|
||||
emit({ type: "session.turn", sessionId: input.sessionId, turnId, state: "completed" });
|
||||
if (MODE === "after-turn" && turn === 1) {
|
||||
emit({ type: "session.closed", sessionId: input.sessionId });
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (input.type === "session.close") {
|
||||
if (!closed.has(input.sessionId)) emit({ type: "session.closed", sessionId: input.sessionId });
|
||||
}
|
||||
if ("requestId" in input) {
|
||||
emit({ type: "request.completed", requestId: input.requestId });
|
||||
}
|
||||
},
|
||||
onEvent(next: (event: ProviderEvent) => void) {
|
||||
listener = next;
|
||||
return () => {
|
||||
if (listener === next) listener = null;
|
||||
};
|
||||
},
|
||||
async close() {},
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
export default function contribute(server: { registerProvider(p: ProviderRegistration): void }) {
|
||||
server.registerProvider(provider);
|
||||
return () => undefined;
|
||||
}`,
|
||||
);
|
||||
return directory;
|
||||
}
|
||||
|
||||
test.each<CloseMode>(["after-turn", "after-failed-turn", "on-next-prompt"])(
|
||||
"an agent whose provider session closed (%s) runs its next prompt",
|
||||
async (mode) => {
|
||||
const root = await mkdtemp(path.join(tmpdir(), "plugin-provider-closed-session-"));
|
||||
onTestFinished(() =>
|
||||
rm(root, { recursive: true, force: true, maxRetries: 10, retryDelay: 100 }),
|
||||
);
|
||||
const pluginDirectory = await createClosingProviderPlugin(root, mode);
|
||||
const workspace = path.join(root, "workspace");
|
||||
await mkdir(workspace, { recursive: true });
|
||||
|
||||
const daemon = await createTestPaseoDaemon({
|
||||
paseoHomeRoot: path.join(root, "daemon"),
|
||||
staticDir: path.join(root, "static"),
|
||||
pluginsEnabled: true,
|
||||
plugins: {
|
||||
[PLUGIN_ID]: { source: "directory", path: pluginDirectory, enabled: true },
|
||||
},
|
||||
});
|
||||
const client = new DaemonClient({
|
||||
url: `ws://127.0.0.1:${daemon.port}/ws`,
|
||||
appVersion: "0.9.1",
|
||||
});
|
||||
onTestFinished(async () => {
|
||||
await client.close();
|
||||
await daemon.close();
|
||||
});
|
||||
await client.connect();
|
||||
await client.fetchAgents({ subscribe: {} });
|
||||
|
||||
const agent = await client.createAgent({
|
||||
provider: PROVIDER_ID,
|
||||
model: "closing-model",
|
||||
cwd: workspace,
|
||||
title: "Closing provider agent",
|
||||
});
|
||||
await client.sendMessage(agent.id, "first");
|
||||
await client.waitForFinish(agent.id, 30_000);
|
||||
|
||||
// Before the fix, reopening tried to close the session the provider had already
|
||||
// closed, failed, and rejected this send with "Provider session <id> is stale".
|
||||
await client.sendMessage(agent.id, "second");
|
||||
expect((await client.waitForFinish(agent.id, 30_000)).status).toBe("idle");
|
||||
|
||||
const timeline = await client.fetchAgentTimeline(agent.id, {
|
||||
direction: "tail",
|
||||
limit: 0,
|
||||
projection: "canonical",
|
||||
});
|
||||
const text = JSON.stringify(timeline.entries);
|
||||
// In on-next-prompt the provider closed the session on prompt 2, so the reopened
|
||||
// session answers the retried prompt as its third.
|
||||
expect(text).toContain(mode === "on-next-prompt" ? "Done 3" : "Done 2");
|
||||
expect(text).not.toMatch(/Provider session \S+ (closed|is stale)/);
|
||||
},
|
||||
60_000,
|
||||
);
|
||||
@@ -587,6 +587,29 @@ describe("WorkspaceGitServiceImpl", () => {
|
||||
await service.dispose();
|
||||
});
|
||||
|
||||
test("a client reconnecting within the release grace reuses the warm target", async () => {
|
||||
const getCheckoutStatus = vi.fn(buildDefaultTestServiceDeps().getCheckoutStatus);
|
||||
const service = createService({ getCheckoutStatus });
|
||||
try {
|
||||
const first = service.registerWorkspace({ cwd: REPO_CWD }, () => {});
|
||||
const snapshot = await service.getSnapshot(REPO_CWD);
|
||||
await waitForObservationToSettle(service, 1);
|
||||
first.unsubscribe();
|
||||
expect(service.getMetrics().workspaceTargetCount).toBe(1);
|
||||
const reads = getCheckoutStatus.mock.calls.length;
|
||||
|
||||
const second = service.registerWorkspace({ cwd: REPO_CWD }, () => {});
|
||||
await expect(service.getSnapshot(REPO_CWD)).resolves.toEqual(snapshot);
|
||||
expect(getCheckoutStatus).toHaveBeenCalledTimes(reads);
|
||||
second.unsubscribe();
|
||||
|
||||
await vi.advanceTimersByTimeAsync(90_000);
|
||||
expect(service.getMetrics().workspaceTargetCount).toBe(0);
|
||||
} finally {
|
||||
await service.dispose();
|
||||
}
|
||||
});
|
||||
|
||||
test("onSnapshotUpdated delivers without workspace subscribers and can unsubscribe", async () => {
|
||||
const service = createService();
|
||||
const snapshots: WorkspaceGitRuntimeSnapshot[] = [];
|
||||
@@ -623,6 +646,7 @@ describe("WorkspaceGitServiceImpl", () => {
|
||||
const service = new WorkspaceGitServiceImpl({
|
||||
logger: createLogger() as unknown as pino.Logger,
|
||||
paseoHome: "/tmp/paseo-test",
|
||||
releaseGraceMs: 0,
|
||||
deps: {
|
||||
...buildDefaultTestServiceDeps(),
|
||||
getPullRequestStatus: async () => {
|
||||
|
||||
@@ -81,6 +81,9 @@ import { checkoutLiteFromGitSnapshot } from "./workspace-registry-model.js";
|
||||
import { createWatcherLivenessCanary } from "./watcher-liveness-canary.js";
|
||||
|
||||
const WORKSPACE_GIT_WATCH_DEBOUNCE_MS = 1_000;
|
||||
// A target outlives its last listener this long, so a reconnecting client reuses its snapshot
|
||||
// and watchers instead of re-reading every checkout.
|
||||
const WORKSPACE_GIT_RELEASE_GRACE_MS = 90_000;
|
||||
export const BACKGROUND_GIT_FETCH_INTERVAL_MS = 180_000;
|
||||
const FETCH_METADATA_ECHO_TTL_MS = 5_000;
|
||||
export const WORKSPACE_GIT_OBSERVATION_REENSURE_INTERVAL_MS = 60_000;
|
||||
@@ -441,6 +444,8 @@ interface WorkspaceGitServiceOptions {
|
||||
worktreesRoot?: string;
|
||||
fileObserver?: FileObserver;
|
||||
deps?: Partial<WorkspaceGitServiceDependencies>;
|
||||
/** How long a workspace target outlives its last listener; 0 releases it immediately. */
|
||||
releaseGraceMs?: number;
|
||||
}
|
||||
|
||||
class WorkspaceGitServiceDisposedError extends Error {
|
||||
@@ -463,6 +468,7 @@ interface WorkspaceGitTarget {
|
||||
gitDirPaths: GitObservationPaths | null;
|
||||
cwd: string;
|
||||
listeners: Set<WorkspaceGitListener>;
|
||||
releaseTimer: NodeJS.Timeout | null;
|
||||
workingTreeWatchTarget: WorkingTreeWatchTarget | null;
|
||||
debounceTimer: NodeJS.Timeout | null;
|
||||
pendingDebounceRequest: WorkspaceGitRefreshRequest | null;
|
||||
@@ -657,6 +663,7 @@ export class WorkspaceGitServiceImpl implements WorkspaceGitService {
|
||||
private readonly logger: pino.Logger;
|
||||
private readonly paseoHome: string;
|
||||
private readonly worktreesRoot: string | undefined;
|
||||
private readonly releaseGraceMs: number;
|
||||
private readonly fileObserver: FileObserver;
|
||||
private readonly deps: WorkspaceGitServiceDependencies;
|
||||
private readonly forgeResolver: ForgeResolver;
|
||||
@@ -710,6 +717,7 @@ export class WorkspaceGitServiceImpl implements WorkspaceGitService {
|
||||
this.logger = options.logger.child({ module: "workspace-git-service" });
|
||||
this.paseoHome = options.paseoHome;
|
||||
this.worktreesRoot = options.worktreesRoot;
|
||||
this.releaseGraceMs = options.releaseGraceMs ?? WORKSPACE_GIT_RELEASE_GRACE_MS;
|
||||
this.fileObserver = options.fileObserver ?? createFileObserver();
|
||||
this.deps = resolveWorkspaceGitServiceDeps(
|
||||
this.fileObserver.subscribe.bind(this.fileObserver),
|
||||
@@ -733,6 +741,7 @@ export class WorkspaceGitServiceImpl implements WorkspaceGitService {
|
||||
this.assertNotDisposed();
|
||||
const cwd = resolve(params.cwd);
|
||||
const target = this.ensureWorkspaceTarget(cwd);
|
||||
this.cancelWorkspaceRelease(target);
|
||||
target.listeners.add(listener);
|
||||
if (target.folderMissing) {
|
||||
void this.resumeWorkspaceIfFolderRestored(target);
|
||||
@@ -1318,6 +1327,7 @@ export class WorkspaceGitServiceImpl implements WorkspaceGitService {
|
||||
gitDirPaths: null,
|
||||
cwd,
|
||||
listeners: new Set(),
|
||||
releaseTimer: null,
|
||||
workingTreeWatchTarget: null,
|
||||
debounceTimer: null,
|
||||
pendingDebounceRequest: null,
|
||||
@@ -3065,6 +3075,9 @@ export class WorkspaceGitServiceImpl implements WorkspaceGitService {
|
||||
if (!target || target.closed || this.workspaceTargets.get(target.cwd) !== target) {
|
||||
return;
|
||||
}
|
||||
if (options.origin === "observation" && this.releaseChangedWarmTarget(target)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const request = this.buildScheduledRefreshRequest(options);
|
||||
target.pendingDebounceRequest = this.mergeRefreshRequests(
|
||||
@@ -3351,6 +3364,9 @@ export class WorkspaceGitServiceImpl implements WorkspaceGitService {
|
||||
if (target.closed || this.workspaceTargets.get(target.cwd) !== target) {
|
||||
return;
|
||||
}
|
||||
if (request.origin === "observation" && this.releaseChangedWarmTarget(target)) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await this.requestWorkspaceSnapshot(target, request);
|
||||
} catch (error) {
|
||||
@@ -4104,7 +4120,52 @@ export class WorkspaceGitServiceImpl implements WorkspaceGitService {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.releaseGraceMs <= 0 || !this.isWorkspaceObservationEstablished(target)) {
|
||||
this.removeWorkspaceTarget(target);
|
||||
return;
|
||||
}
|
||||
// Keep the snapshot and watchers warm for a reconnecting client; stop forge polling now.
|
||||
this.stopForgePrStatusPollForTarget(target);
|
||||
this.cancelWorkspaceRelease(target);
|
||||
target.releaseTimer = setTimeout(() => {
|
||||
target.releaseTimer = null;
|
||||
if (
|
||||
!target.closed &&
|
||||
target.listeners.size === 0 &&
|
||||
this.workspaceTargets.get(target.cwd) === target
|
||||
) {
|
||||
this.removeWorkspaceTarget(target);
|
||||
}
|
||||
}, this.releaseGraceMs);
|
||||
target.releaseTimer.unref?.();
|
||||
}
|
||||
|
||||
/** Only a fully watched target stays warm; one still recovering a watcher is released now. */
|
||||
private isWorkspaceObservationEstablished(target: WorkspaceGitTarget): boolean {
|
||||
const repoTarget = target.repoGitRoot ? this.repoTargets.get(target.repoGitRoot) : undefined;
|
||||
return Boolean(
|
||||
target.latestSnapshot &&
|
||||
!target.folderMissing &&
|
||||
target.workingTreeWatchTarget?.subscription &&
|
||||
repoTarget?.subscription,
|
||||
);
|
||||
}
|
||||
|
||||
/** A change seen while nobody listens ends the grace: the next consumer re-reads, nobody pays now. */
|
||||
private releaseChangedWarmTarget(target: WorkspaceGitTarget): boolean {
|
||||
if (target.listeners.size > 0 || !target.releaseTimer) {
|
||||
return false;
|
||||
}
|
||||
this.cancelWorkspaceRelease(target);
|
||||
this.removeWorkspaceTarget(target);
|
||||
return true;
|
||||
}
|
||||
|
||||
private cancelWorkspaceRelease(target: WorkspaceGitTarget): void {
|
||||
if (target.releaseTimer) {
|
||||
clearTimeout(target.releaseTimer);
|
||||
target.releaseTimer = null;
|
||||
}
|
||||
}
|
||||
|
||||
private removeWorkspaceTarget(target: WorkspaceGitTarget): void {
|
||||
@@ -4171,6 +4232,7 @@ export class WorkspaceGitServiceImpl implements WorkspaceGitService {
|
||||
|
||||
private closeWorkspaceTarget(target: WorkspaceGitTarget): void {
|
||||
target.closed = true;
|
||||
this.cancelWorkspaceRelease(target);
|
||||
this.stopWorkspaceObservation(target);
|
||||
target.listeners.clear();
|
||||
}
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -86,6 +86,12 @@ const patchedPackages = [
|
||||
nodeModulesPath: "node_modules/@mattermost/react-native-paste-input",
|
||||
patchPrefix: "@mattermost+react-native-paste-input+",
|
||||
},
|
||||
// Backport of https://github.com/mermaid-js/mermaid/pull/8459 (lexer half): a flowchart label
|
||||
// with an "@" parses. The patch header has the details. Remove when the app uses mermaid 12.
|
||||
{
|
||||
nodeModulesPath: "node_modules/mermaid",
|
||||
patchPrefix: "mermaid+",
|
||||
},
|
||||
{
|
||||
nodeModulesPath: "packages/server/node_modules/@opencode-ai/sdk",
|
||||
patchPrefix: "@opencode-ai+sdk+",
|
||||
|
||||
Reference in New Issue
Block a user