Skip to content

fix: avoid pulling containers when it is not enabled #17855

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 5 additions & 15 deletions site/src/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2453,21 +2453,11 @@ class ApiMethods {
const params = new URLSearchParams(
labels?.map((label) => ["label", label]),
);

try {
const res =
await this.axios.get<TypesGen.WorkspaceAgentListContainersResponse>(
`/api/v2/workspaceagents/${agentId}/containers?${params.toString()}`,
);
return res.data;
} catch (err) {
// If the error is a 403, it means that experimental
// containers are not enabled on the agent.
if (isAxiosError(err) && err.response?.status === 403) {
return { containers: [] };
}
throw err;
}
const res =
await this.axios.get<TypesGen.WorkspaceAgentListContainersResponse>(
`/api/v2/workspaceagents/${agentId}/containers?${params.toString()}`,
);
return res.data;
};

getInboxNotifications = async (startingBeforeId?: string) => {
Expand Down
8 changes: 7 additions & 1 deletion site/src/modules/resources/AgentRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type {
WorkspaceAgent,
WorkspaceAgentMetadata,
} from "api/typesGenerated";
import { isAxiosError } from "axios";
import { DropdownArrow } from "components/DropdownArrow/DropdownArrow";
import type { Line } from "components/Logs/LogLine";
import { Stack } from "components/Stack/Stack";
Expand Down Expand Up @@ -160,7 +161,12 @@ export const AgentRow: FC<AgentRowProps> = ({
select: (res) => res.containers.filter((c) => c.status === "running"),
// TODO: Implement a websocket connection to get updates on containers
// without having to poll.
refetchInterval: 10_000,
refetchInterval: (_, query) => {
const { error } = query.state;
return isAxiosError(error) && error.response?.status === 403
? false
: 10_000;
},
Comment on lines +166 to +169
Copy link
Member

@johnstcn johnstcn May 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So a non-200 and non-403 response will continue to poll forever?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will only stop, return false, on 403. Should we cover any other use-case?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably fine for now

});

return (
Expand Down
Loading