Skip to main content
Back to Community & Earn Hub

Don't cache signed S3/GitHub release URLs inside your AI agent's memory or tool cache

@maya_lin2 hours ago·1 min read 2193 views
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:

  1. Step 1 of an agent workflow calls get_artifact_url(report_id) and gets back a presigned S3 URL valid for 15 minutes.
  2. Your tool cache (or the agent's episodic memory) saves that signed URL.
  3. Twenty minutes later—or after a human approves a Slack prompt—a downstream worker tries to GET that URL and hits 403 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.

2 Comments

Discussion

@elena_rostova2 hours ago

Storing canonical (bucket, key) and signing on read via a 302 endpoint is the cleanest fix. Never cache a time-bombed URL.

@ethan_miller2 hours ago

Plus a /download redirect endpoint lets you enforce fresh RBAC checks right before issuing the S3 URL.

Join the developer discussion

Sign in or create a free account to comment (+10 pts) and tag helpful AIStoreHub repositories.