Skip to content

Commit 6cef45b

Browse files
fix(handlers): canonical error envelope (request_id) on 3 agent-facing branches (#234)
Three agent-facing error branches emitted a bespoke envelope missing request_id (and one used a non-standard "msg" key), so an agent couldn't correlate the failure to logs/support the way every respondError path lets it: - onboarding.go ClaimPreview invalid_token (not-found): routed through respondError — adds request_id, swaps the bespoke "msg" for the canonical "message" key. The `error` keyword (what clients match on) is unchanged. - env_policy.go Put owner_required 403: added request_id alongside the existing role/allowed_roles/agent_action fields. - resource.go respondPauseUpgradeRequired 402: added request_id alongside the existing upgrade_url/agent_action. No contract break — only additive (request_id) plus the msg→message rename on a branch whose documented shape was just {ok,error}. All three changed lines covered by existing tests (claim-preview not-found, env-policy non-owner, pause-tier-wall); verified locally against real Postgres+Redis. Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 53e312b commit 6cef45b

3 files changed

Lines changed: 6 additions & 5 deletions

File tree

internal/handlers/env_policy.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ func (h *EnvPolicyHandler) Put(c *fiber.Ctx) error {
100100
"role": role,
101101
"allowed_roles": []string{middleware.RoleOwner},
102102
"agent_action": newAgentActionOwnerRequired(role),
103+
"request_id": middleware.GetRequestID(c),
103104
})
104105
}
105106

internal/handlers/onboarding.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,10 @@ func (h *OnboardingHandler) ClaimPreview(c *fiber.Ctx) error {
9696
if err != nil {
9797
var notFound *models.ErrOnboardingNotFound
9898
if errors.As(err, &notFound) {
99-
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
100-
"ok": false,
101-
"error": "invalid_token",
102-
"msg": "Token not recognized",
103-
})
99+
// Canonical envelope: respondError adds request_id and uses the
100+
// standard "message" key (this branch previously emitted a bespoke
101+
// "msg" field with no request_id — agents couldn't correlate it).
102+
return respondError(c, fiber.StatusBadRequest, "invalid_token", "Token not recognized")
104103
}
105104
slog.Error("onboarding.claim_preview.db_error", "error", err, "request_id", requestID)
106105
return respondError(c, fiber.StatusServiceUnavailable, "lookup_failed", "Failed to verify token")

internal/handlers/resource.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -813,6 +813,7 @@ func respondPauseUpgradeRequired(c *fiber.Ctx, currentTier string) error {
813813
"message": "Pausing resources requires the Pro plan or higher. Your team is on the " + currentTier + " plan.",
814814
"upgrade_url": "https://instanode.dev/pricing",
815815
"agent_action": AgentActionPauseRequiresPro,
816+
"request_id": middleware.GetRequestID(c),
816817
})
817818
return ErrResponseWritten
818819
}

0 commit comments

Comments
 (0)