diff --git a/apps/server/src/git/Layers/GitStatusBroadcaster.ts b/apps/server/src/git/Layers/GitStatusBroadcaster.ts
index c75326dfbe..5f97954e97 100644
--- a/apps/server/src/git/Layers/GitStatusBroadcaster.ts
+++ b/apps/server/src/git/Layers/GitStatusBroadcaster.ts
@@ -127,11 +127,12 @@ export const GitStatusBroadcasterLive = Layer.effect(
Effect.gen(function* () {
const normalizedCwd = normalizeCwd(input.cwd);
yield* ensurePoller(normalizedCwd);
+ const subscription = yield* PubSub.subscribe(changesPubSub);
const initialStatus = yield* getStatus({ cwd: normalizedCwd });
return Stream.concat(
Stream.make(initialStatus),
- Stream.fromPubSub(changesPubSub).pipe(
+ Stream.fromEffectRepeat(PubSub.take(subscription)).pipe(
Stream.filter((event) => event.cwd === normalizedCwd),
Stream.map((event) => event.status),
),
diff --git a/apps/server/src/server.test.ts b/apps/server/src/server.test.ts
index 060dddd5b9..a3cc754dfd 100644
--- a/apps/server/src/server.test.ts
+++ b/apps/server/src/server.test.ts
@@ -1390,6 +1390,13 @@ it.layer(NodeServices.layer)("server router seam", (it) => {
);
assert.equal(pull.status, "pulled");
+ const refreshedStatus = yield* Effect.scoped(
+ withWsRpcClient(wsUrl, (client) =>
+ client[WS_METHODS.gitRefreshStatus]({ cwd: "/tmp/repo" }),
+ ),
+ );
+ assert.equal(refreshedStatus.isRepo, true);
+
const stackedEvents = yield* Effect.scoped(
withWsRpcClient(wsUrl, (client) =>
client[WS_METHODS.gitRunStackedAction]({
@@ -1492,11 +1499,35 @@ it.layer(NodeServices.layer)("server router seam", (it) => {
cwd: "/tmp/repo",
detail: "upstream missing",
});
+ let invalidationCalls = 0;
+ let statusCalls = 0;
yield* buildAppUnderTest({
layers: {
gitCore: {
pullCurrentBranch: () => Effect.fail(gitError),
},
+ gitManager: {
+ invalidateStatus: () =>
+ Effect.sync(() => {
+ invalidationCalls += 1;
+ }),
+ status: () =>
+ Effect.sync(() => {
+ statusCalls += 1;
+ return {
+ isRepo: true,
+ hasOriginRemote: true,
+ isDefaultBranch: true,
+ branch: "main",
+ hasWorkingTreeChanges: true,
+ workingTree: { files: [], insertions: 0, deletions: 0 },
+ hasUpstream: true,
+ aheadCount: 0,
+ behindCount: 0,
+ pr: null,
+ };
+ }),
+ },
},
});
@@ -1508,6 +1539,63 @@ it.layer(NodeServices.layer)("server router seam", (it) => {
);
assertFailure(result, gitError);
+ assert.equal(invalidationCalls, 1);
+ assert.equal(statusCalls, 1);
+ }).pipe(Effect.provide(NodeHttpServer.layerTest)),
+ );
+
+ it.effect("routes websocket rpc git.runStackedAction errors after refreshing git status", () =>
+ Effect.gen(function* () {
+ const gitError = new GitCommandError({
+ operation: "commit",
+ command: "git commit",
+ cwd: "/tmp/repo",
+ detail: "nothing to commit",
+ });
+ let invalidationCalls = 0;
+ let statusCalls = 0;
+ yield* buildAppUnderTest({
+ layers: {
+ gitManager: {
+ invalidateStatus: () =>
+ Effect.sync(() => {
+ invalidationCalls += 1;
+ }),
+ status: () =>
+ Effect.sync(() => {
+ statusCalls += 1;
+ return {
+ isRepo: true,
+ hasOriginRemote: true,
+ isDefaultBranch: false,
+ branch: "feature/demo",
+ hasWorkingTreeChanges: true,
+ workingTree: { files: [], insertions: 0, deletions: 0 },
+ hasUpstream: true,
+ aheadCount: 0,
+ behindCount: 0,
+ pr: null,
+ };
+ }),
+ runStackedAction: () => Effect.fail(gitError),
+ },
+ },
+ });
+
+ const wsUrl = yield* getWsServerUrl("/ws");
+ const result = yield* Effect.scoped(
+ withWsRpcClient(wsUrl, (client) =>
+ client[WS_METHODS.gitRunStackedAction]({
+ actionId: "action-1",
+ cwd: "/tmp/repo",
+ action: "commit",
+ }).pipe(Stream.runCollect, Effect.result),
+ ),
+ );
+
+ assertFailure(result, gitError);
+ assert.equal(invalidationCalls, 1);
+ assert.equal(statusCalls, 1);
}).pipe(Effect.provide(NodeHttpServer.layerTest)),
);
diff --git a/apps/server/src/ws.ts b/apps/server/src/ws.ts
index 8514469495..6697411062 100644
--- a/apps/server/src/ws.ts
+++ b/apps/server/src/ws.ts
@@ -570,10 +570,20 @@ const WsRpcLayer = WsRpcGroup.toLayer(
observeRpcStream(WS_METHODS.subscribeGitStatus, gitStatusBroadcaster.streamStatus(input), {
"rpc.aggregate": "git",
}),
+ [WS_METHODS.gitRefreshStatus]: (input) =>
+ observeRpcEffect(
+ WS_METHODS.gitRefreshStatus,
+ gitStatusBroadcaster.refreshStatus(input.cwd),
+ {
+ "rpc.aggregate": "git",
+ },
+ ),
[WS_METHODS.gitPull]: (input) =>
observeRpcEffect(
WS_METHODS.gitPull,
- git.pullCurrentBranch(input.cwd).pipe(Effect.tap(() => refreshGitStatus(input.cwd))),
+ git
+ .pullCurrentBranch(input.cwd)
+ .pipe(Effect.ensuring(refreshGitStatus(input.cwd).pipe(Effect.ignore({ log: true })))),
{ "rpc.aggregate": "git" },
),
[WS_METHODS.gitRunStackedAction]: (input) =>
@@ -589,7 +599,11 @@ const WsRpcLayer = WsRpcGroup.toLayer(
})
.pipe(
Effect.matchCauseEffect({
- onFailure: (cause) => Queue.failCause(queue, cause),
+ onFailure: (cause) =>
+ refreshGitStatus(input.cwd).pipe(
+ Effect.ignore({ log: true }),
+ Effect.andThen(Queue.failCause(queue, cause)),
+ ),
onSuccess: () =>
refreshGitStatus(input.cwd).pipe(
Effect.andThen(Queue.end(queue).pipe(Effect.asVoid)),
diff --git a/apps/web/src/components/GitActionsControl.tsx b/apps/web/src/components/GitActionsControl.tsx
index bd931f517b..36d528b2da 100644
--- a/apps/web/src/components/GitActionsControl.tsx
+++ b/apps/web/src/components/GitActionsControl.tsx
@@ -46,7 +46,7 @@ import {
gitPullMutationOptions,
gitRunStackedActionMutationOptions,
} from "~/lib/gitReactQuery";
-import { useGitStatus } from "~/lib/gitStatusState";
+import { refreshGitStatus, useGitStatus } from "~/lib/gitStatusState";
import { newCommandId, randomUUID } from "~/lib/utils";
import { resolvePathLinkTarget } from "~/terminal-links";
import { readNativeApi } from "~/nativeApi";
@@ -358,6 +358,29 @@ export default function GitActionsControl({ gitCwd, activeThreadId }: GitActions
};
}, [updateActiveProgressToast]);
+ useEffect(() => {
+ if (gitCwd === null) {
+ return;
+ }
+
+ const refreshCurrentGitStatus = () => {
+ void refreshGitStatus(gitCwd).catch(() => undefined);
+ };
+ const handleVisibilityChange = () => {
+ if (document.visibilityState === "visible") {
+ refreshCurrentGitStatus();
+ }
+ };
+
+ window.addEventListener("focus", refreshCurrentGitStatus);
+ document.addEventListener("visibilitychange", handleVisibilityChange);
+
+ return () => {
+ window.removeEventListener("focus", refreshCurrentGitStatus);
+ document.removeEventListener("visibilitychange", handleVisibilityChange);
+ };
+ }, [gitCwd]);
+
const openExistingPr = useCallback(async () => {
const api = readNativeApi();
if (!api) {
@@ -798,7 +821,13 @@ export default function GitActionsControl({ gitCwd, activeThreadId }: GitActions
)}
-