Significant-Gravitas/AutoGPT · warning · HTTPException
str(e)
Error message
str(e)
What it means
A 400 from the push subscription endpoint when validate_push_endpoint or upsert_push_subscription raises ValueError — i.e. the supplied Web Push endpoint or key material is malformed. The detail carries the validation message (str(e)) describing exactly which part failed.
Source
Thrown at autogpt_platform/backend/backend/api/features/push/routes.py:51
summary="Register a push subscription for the current user",
status_code=HTTP_204_NO_CONTENT,
dependencies=[Security(requires_user)],
)
async def subscribe_push(
user_id: Annotated[str, Security(get_user_id)],
body: PushSubscribeRequest,
) -> None:
try:
await validate_push_endpoint(body.endpoint)
await upsert_push_subscription(
user_id=user_id,
endpoint=body.endpoint,
p256dh=body.keys.p256dh,
auth=body.keys.auth,
user_agent=body.user_agent,
)
except ValueError as e:
raise HTTPException(status_code=HTTP_400_BAD_REQUEST, detail=str(e))
@router.post(
"/unsubscribe",
summary="Remove a push subscription",
status_code=HTTP_204_NO_CONTENT,
dependencies=[Security(requires_user)],
)
async def unsubscribe_push(
user_id: Annotated[str, Security(get_user_id)],
body: PushUnsubscribeRequest,
) -> None:
await delete_push_subscription(user_id, body.endpoint)
View on GitHub (pinned to 9c8bb5550f)
Solutions
- Read the 400 detail — it names the invalid field or format.
- Log the outgoing subscription object client-side and verify endpoint is an https push-service URL and keys are base64url-encoded strings of the expected lengths (p256dh 65 bytes, auth 16 bytes).
- Re-acquire the subscription via pushManager.subscribe() instead of persisting/reusing an old one.
- If your serialization converts ArrayBuffers, apply the standard bufferToBase64Url conversion before POSTing.
Example fix
// before — raw ArrayBuffer sent as {}
body: { endpoint: sub.endpoint, keys: { p256dh: sub.keys.p256dh, auth: sub.keys.auth } }
// after — proper base64url strings
const b64 = (buf) => btoa(String.fromCharCode(...new Uint8Array(buf))).replace(/\+/g,'-').replace(/\//g,'_').replace(/=+$/,'');
body: { endpoint: sub.endpoint, keys: { p256dh: b64(sub.getKey('p256dh')), auth: b64(sub.getKey('auth')) } }; Defensive patterns
Strategy: validation
Validate before calling
// Client: shape-check the subscription before subscribing
const b64url = (s: string) => /^[A-Za-z0-9_-]+$/.test(s);
if (!sub.endpoint.startsWith('https://') || !b64url(sub.keys.p256dh) || !b64url(sub.keys.auth)) {
throw new Error('invalid push subscription payload');
}
await api.post('/push/subscribe', sub); Type guard
interface PushKeys { p256dh: string; auth: string }
function isPushSubscription(o: unknown): o is { endpoint: string; keys: PushKeys } {
const p = o as any;
return typeof p?.endpoint === 'string' && p.endpoint.startsWith('https://')
&& typeof p?.keys?.p256dh === 'string' && typeof p?.keys?.auth === 'string';
} Try / catch
try { await subscribePush(body); }
catch (e) {
if (e.status === 400) { showPushConfigError(e.detail); /* don't retry */ }
else throw e;
} Prevention
- Convert ArrayBuffers to base64url exactly once, at acquisition time.
- Re-subscribe via pushManager.subscribe() rather than reusing stored subscriptions after browser updates.
- Surface the 400 detail to developers — it names the failing field.
When it happens
Trigger: POST /api/push/subscribe with an endpoint URL that isn't a valid push service URL, missing/invalid p256dh or auth keys (wrong base64url, wrong lengths), or a key format the server rejects. Typically the browser-generated PushSubscription was serialized incorrectly (e.g. keys not converted to buffers/base64 properly).
Common situations: Frontend sending endpoint/keys as ArrayBuffer or with base64 vs base64urlurl padding mismatches; corrupted subscription objects after browser updates; testing with hand-written payloads; proxy stripping parts of the JSON body.
Related errors
- start and end query params are required
- str(exc)
- Either user_id or email query parameter is required.
- Search query must be at least 3 characters.
- Unsupported grant_type: {request.grant_type}. Must be 'autho
AI-assisted analysis of Significant-Gravitas/AutoGPT@9c8bb5550f (2026-08-14).
Data as JSON: /api/errors/c26df4cf2114132f.
Report an issue: GitHub.