fix(fleet): block agent update when node unreachable#195
Merged
TerrifiedBug merged 2 commits intomainfrom Apr 28, 2026
Merged
Conversation
Triggering an agent update when the node is unreachable can't reach the agent, leaves a pending action queued, and surfaces a confusing failure state to the user. - Backend: triggerAgentUpdate throws FAILED_PRECONDITION when node.status === "UNREACHABLE" - Frontend: render "Update available" as a disabled badge with a tooltip explaining the agent must be reachable before updating
Comment on lines
+417
to
+422
| throw new TRPCError({ | ||
| code: "FAILED_PRECONDITION", | ||
| message: | ||
| "Cannot update an unreachable agent — wait for it to reconnect before retrying", | ||
| }); | ||
| } |
Contributor
There was a problem hiding this comment.
Invalid tRPC error code —
FAILED_PRECONDITION does not exist
FAILED_PRECONDITION is a gRPC status code, not a tRPC error code. tRPC v11's TRPC_ERROR_CODE_KEY type does not include this value, so TypeScript will reject this at compile time and tsc --noEmit (run in CI) will fail. The correct tRPC code for "operation rejected because a precondition is not met" is PRECONDITION_FAILED.
Suggested change
| throw new TRPCError({ | |
| code: "FAILED_PRECONDITION", | |
| message: | |
| "Cannot update an unreachable agent — wait for it to reconnect before retrying", | |
| }); | |
| } | |
| if (node.status === "UNREACHABLE") { | |
| throw new TRPCError({ | |
| code: "PRECONDITION_FAILED", | |
| message: | |
| "Cannot update an unreachable agent — wait for it to reconnect before retrying", | |
| }); | |
| } |
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/server/routers/fleet.ts
Line: 417-422
Comment:
**Invalid tRPC error code — `FAILED_PRECONDITION` does not exist**
`FAILED_PRECONDITION` is a gRPC status code, not a tRPC error code. tRPC v11's `TRPC_ERROR_CODE_KEY` type does not include this value, so TypeScript will reject this at compile time and `tsc --noEmit` (run in CI) will fail. The correct tRPC code for "operation rejected because a precondition is not met" is `PRECONDITION_FAILED`.
```suggestion
if (node.status === "UNREACHABLE") {
throw new TRPCError({
code: "PRECONDITION_FAILED",
message:
"Cannot update an unreachable agent — wait for it to reconnect before retrying",
});
}
```
How can I resolve this? If you propose a fix, please make it concise.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Fixes Notion bug: "Should not be able to try update agents when they are unreachable."
Previously, the "Update available" badge was always clickable when a newer agent version existed, regardless of node reachability. Triggering an update on an unreachable node could not actually deliver the action, queued a stale `pendingAction`, and surfaced a confusing failure state.
Defense in depth — both layers reject the action.
Test plan
Greptile Summary
This PR adds a defense-in-depth guard preventing agent updates when the target node is
UNREACHABLE: the backend throws an error and the frontend renders a visually disabled badge with a tooltip. The frontend change is correct, but the backend usesFAILED_PRECONDITION— a gRPC status code that is not part of tRPC v11'sTRPC_ERROR_CODE_KEYtype — which will causetsc --noEmitto fail in CI. The fix is a one-word change toPRECONDITION_FAILED.Confidence Score: 3/5
Not safe to merge as-is — the backend uses an invalid tRPC error code that will fail type-checking in CI.
A P1 syntax error in the backend (
FAILED_PRECONDITIONvsPRECONDITION_FAILED) would break CI type-checking. The fix is trivial (one word), and the rest of the PR logic is correct, but the build must pass before merging.src/server/routers/fleet.ts — invalid tRPC error code on line 417.
Important Files Changed
triggerAgentUpdate, but usesFAILED_PRECONDITIONwhich is not a valid tRPC error code — will failtsc --noEmitin CI.Sequence Diagram
sequenceDiagram actor User participant UI as Fleet Page (frontend) participant API as fleet.triggerAgentUpdate (tRPC) participant DB as PostgreSQL User->>UI: Views node with update available alt node.status === "UNREACHABLE" UI-->>User: Disabled badge + tooltip (wait for reconnect) Note over UI: No click handler — dialog never opens else node is reachable User->>UI: Clicks "Update available" badge UI->>API: triggerAgentUpdate({ nodeId, ... }) API->>DB: findUnique(nodeId) DB-->>API: node alt node.status === "UNREACHABLE" (API guard) API-->>UI: TRPCError PRECONDITION_FAILED UI-->>User: Error toast else node OK API->>DB: update pendingAction = self_update DB-->>API: updated node API-->>UI: success UI-->>User: Update initiated end endPrompt To Fix All With AI
Reviews (1): Last reviewed commit: "fix(fleet): block agent self-update when..." | Re-trigger Greptile