Repository navigation
feat(cloud): a box reports its agent status so the sidebar can show it #7824
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
apps/api/src/app/api/cloud-workspaces/[workspaceId]/agent-status/route.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| import { ACTIVE_AGENT_STATUSES } from "@superset/shared/agent-status"; | ||
| import { reportSandboxAgentStatus } from "@superset/trpc/lib/sandbox"; | ||
| import { z } from "zod"; | ||
|
|
||
| const bodySchema = z.object({ | ||
| status: z.enum(ACTIVE_AGENT_STATUSES).nullable(), | ||
| at: z.number().int().positive(), | ||
| }); | ||
|
|
||
| export async function POST( | ||
| request: Request, | ||
| { params }: { params: Promise<{ workspaceId: string }> }, | ||
| ): Promise<Response> { | ||
| const { workspaceId } = await params; | ||
| const presented = request.headers | ||
| .get("authorization") | ||
| ?.replace(/^Bearer\s+/i, ""); | ||
| if (!presented || !/^[0-9a-f-]{36}$/i.test(workspaceId)) { | ||
| return Response.json({ error: "unauthorized" }, { status: 401 }); | ||
| } | ||
| const parsed = bodySchema.safeParse(await request.json().catch(() => null)); | ||
| if (!parsed.success) { | ||
| return Response.json({ error: "invalid body" }, { status: 400 }); | ||
| } | ||
| const outcome = await reportSandboxAgentStatus({ | ||
| workspaceId, | ||
| presentedSecret: presented, | ||
| status: parsed.data.status, | ||
| at: parsed.data.at, | ||
| }); | ||
| if (outcome === "unauthorized") { | ||
| return Response.json({ error: "unauthorized" }, { status: 401 }); | ||
| } | ||
| if (outcome === "unknown") { | ||
| return Response.json({ error: "unknown workspace" }, { status: 404 }); | ||
| } | ||
| return Response.json({ ok: true }); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: superset-sh/superset
Length of output: 45470
🏁 Script executed:
Repository: superset-sh/superset
Length of output: 23097
Reject stale realtime updates in the desktop cache.
If a delayed older update arrives after a newer alarm has already broadcast,
patchoverwrites the cached row without comparingagentStatusAt. When no workspace is provisioning, the query has no polling refetch, and update messages do not invalidate it. The stale status can therefore remain until another refetch or socket reconnect. A pending-map guard does not protect updates that arrive in separate alarms.Suggested fix
📝 Committable suggestion
🤖 Prompt for AI Agents