Don't cache signed S3/GitHub release URLs inside your AI agent's memory or tool cache
Saw the GitHub discussion on HN today about public release downloads redirecting to expired asset URLs—and it's the exact same bug that bites AI agent pipelines using presigned S3/R2 links.
Here is how it usually happens:
- Step 1 of an agent workflow calls
get_artifact_url(report_id)and gets back a presigned S3 URL valid for 15 minutes. - Your tool cache (or the agent's episodic memory) saves that signed URL.
- Twenty minutes later—or after a human approves a Slack prompt—a downstream worker tries to
GETthat URL and hits403 Request has expired.
Store the canonical object key, mint the signed URL on read
Never store presigned URLs in Redis, Postgres, or agent memory. Store the stable (bucket, object_key) or canonical /api/artifacts/{id} route, and only mint a short-lived signed URL at the exact moment a client needs to download it.
python# Bad: caching the signed URL for 1 hour when the signature expires in 15 mins # Good: store canonical artifact_id and sign fresh on every fetch @router.get("/artifacts/{artifact_id}/download") def download_artifact(artifact_id: str, user=Depends(get_current_user)): obj_key = lookup_artifact_key(artifact_id, user.id) fresh_url = s3_client.generate_presigned_url( "get_object", Params={"Bucket": BUCKET, "Key": obj_key}, ExpiresIn=120, ) return RedirectResponse(fresh_url, status_code=302)
Simple rule, zero mysterious 403s on long-running agent jobs.