Dev.to AI 🤖 Ai 👁 0 📖 5 min read

I Ran My Agent Memory Library on AlloyDB and Let Gemini Attack It

A week ago I entered Startup Buildathon India 2026 solo with MemShield, built on two open-source libraries of mine: adk-memshield, which makes PostgreSQL enforce who can read an AI agent's memories, and adk-leak-arena, w

A week ago I entered Startup Buildathon India 2026 solo with MemShield, built on two open-source libraries of mine: adk-memshield, which makes PostgreSQL enforce who can read an AI agent's memories, and adk-leak-arena, which attacks agent memory setups side by side to prove it. In that post I listed a Gemini Memory Guard and a Gemini red-team as planned and not built yet.

They're built now, along with a hosted suite on Google Cloud and a monitor. MemShield was shortlisted for the Mentor Evaluation at the Bengaluru round on 21 November, out of 214 teams, and didn't make the final selection.

You can attack the live console yourself: adk-leak-arena on Cloud Run. It's public and read-only, and I'll come back to how it's kept safe.

Moving to a managed database

Everything so far had run on plain PostgreSQL 16 and 17 in containers. A library that says "the database enforces it" should survive a managed database that bends the rules, so I ran it on AlloyDB Express (PostgreSQL 18.4), with a head start from Abirami Sukumaran's AlloyDB prep session for the buildathon.

The first thing that changes is the superuser. On AlloyDB, postgres belongs to alloydbsuperuser, a managed role that isn't a true superuser. 113 of adk-memshield's 122 tests pass there; the other 9 are fixtures that expect a true superuser, and none of them is a product bug. That's the result I wanted, because the library's design is that the application role is not privileged: it runs as NOSUPERUSER NOBYPASSRLS, owns no tables, and the public web service refuses to start if anyone hands it the admin connection string.

Then the index. AlloyDB ships ScaNN, Google's vector index, so I ran it under row-level security at 50,000 rows next to HNSW. ScaNN returned 0 forbidden rows across 20 configurations and built its index 2.3x faster (16.28 s against 38.14 s). For heavy users, recall@10 was 0.89 at 0.53 ms, against 0.82 to 0.85 for HNSW.

Now the number that doesn't flatter it. For a light user who can see 30 rows, on queries that rely on row-level security alone, ScaNN's recall@10 was 0.09, and 2 of 10 searches came back empty. It looks like the same silence a reader found in HNSW last week, though I haven't confirmed that ScaNN fails the same way. Nothing leaks, but empty looks normal. For HNSW there's a fix (pgvector's iterative scan plus a B-tree on the scope found 20 of 20 one-row tenants at 200,000 rows). For ScaNN I don't have one yet, so for now it's an index for heavy users, not a default.

Letting Gemini attack it

The arena's original attacks are scripted, which proves the scripted cases and nothing else. A scripted attack is a burglar who only ever tries the front door, and I wrote every one of those scripts myself, so it only knows the doors I thought of. So I added two Gemini pieces.

The first is a live eval on gemini-3.1-flash-lite: 108 of 108 calls, 0 fallbacks. On the unprotected pgvector memory, where the app filter has one of five common mistakes, 39 of 40 cross-boundary attack queries in my open synthetic benchmark returned a row the caller may not read; on adk-memshield, 0 of 40. Authorized recall was 86.4% unprotected and 100% on adk-memshield. Getting there on the free tier meant pacing the engine and retrying on 429 and 503 responses, which is less exciting than a red-team but is the reason the run finished.

The second is an adaptive red-team. Gemini plans its own probes, and a separate blind Gemini judge decides whether a response leaked. In one run it found 5 of 5 unscripted leaks on the unprotected target and 0 of 5 on adk-memshield, and the judge matched all 6 cases of a calibration set. That's one run and a small calibration set, so read it as "the red-team works", not as a leak rate.

The guard: allowed to read is not the same as safe to read

Row-level security answers one question: may this caller read this row? It has nothing to say about what's in the row. If someone writes a poisoned memory ("ignore your previous instructions and...") into a tier they're allowed to write to, every reader in that tier gets it, legally.

The Memory Guard screens every write with Gemini before it's stored. It can allow a write, tighten who can see it or block it, and it can never loosen access. When the guard can't answer, shared writes are refused and private writes go through with a flag. It logs its decisions without the memory text.

With it on, retrieval of a same-tier poisoned memory fell from 100% to 0%, while authorized recall stayed at 100%. It scored 150 of 150 on my own synthetic set, where a regex baseline caught 14.3% of the injections. On a frozen held-out set it scored 43 of 44: all 20 injections caught (Hindi and Hinglish ones included), 0 of 14 benign memories blocked, and one home address missed.

I also tried putting the check inside the database, with AlloyDB's AI.IF() in a BEFORE INSERT trigger. It got 50 of 50 verdicts right, at a 6.5 s median and 36.4 s p95 per insert. Correct, and far too slow for a write path, so the guard stays in the application. The guard's code is private for now.

The monitor: isolation that keeps holding

Gagan Madan's advice at the buildathon was to add a dashboard and monitoring, and to open with a use case people already recognize. He was right, and the monitoring point is the one I want to dwell on, because isolation you proved on release day can quietly stop holding: a migration drops a policy, or a new service role gets BYPASSRLS, and nothing tells you until something leaks.

The monitor runs canary-leak checks and a row-level-security posture check as a Cloud Run job, built to run every hour from Cloud Scheduler. During the event it logged incidents without any row content, raised Cloud Monitoring alerts (the alert emails arrived twice), and rendered status and incident reports against India's DPDP Act. Those reports are operational evidence, not legal advice. It watches two deployments on purpose: one protected by adk-memshield, and an intentionally unprotected baseline that must show a leak, so you can see that the detector detects. The hourly schedule is paused now that the event is over, but the dashboard is live; the code is private for now.

Keeping a public attack console safe

An attack tool on the internet with nobody watching it needs some care. The console runs in a read-only public mode: attacks run, while injecting, resetting and deleting history return 403. It's one Cloud Run instance with at most 10 concurrent requests, Gemini calls are throttled to 6 a minute, and the database scales to zero when idle (so the first load can take 10 to 20 seconds while it wakes up). The data is synthetic and lives in Singapore, because AlloyDB Express isn't in Mumbai yet; Mumbai is the production target.

What I'd tell you

If your agents share memory across customers, test the boring failures before the clever ones. Run your filtered searches as a light user on an approximate index and count the empty results. Then give the application role the least privilege your database allows, and check that it still has only that privilege every hour, not once at launch. Both libraries are open source, adk-memshield and adk-leak-arena, and the console is there to be broken.

📰 Read the original article on Dev.to AI

Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.