Inspiration

Brain-Computer Interfaces read electrical signals from the brain and translate them into control commands — a cursor, a robotic limb, a speech synthesizer. The signals drift over time: electrodes shift, scar tissue forms, the brain itself adapts. Today, fixing that drift means a clinical engineer has to notice it by hand and manually recalibrate — a real, cited bottleneck that keeps BCIs from scaling past a handful of research subjects.

I wanted to build something that closes that loop automatically, without ever removing the human from the decision that actually matters: whether to touch someone's neural implant. The hackathon's "agentic memory" framing gave me the missing piece — a system that doesn't just apply a static rule to every drift event, but genuinely recalls how similar cases were resolved before, and gets more useful every time it resolves one.

What it does

Reanchor watches simulated BCI telemetry, detects when it drifts outside clinical guardrails, and diagnoses the likely cause by searching CockroachDB's distributed vector index for similar past incidents for that patient. It proposes a correction — either reused from a strong historical match, or computed fresh via closed-form circular-mean rotation fitting on the session's own raw trial data. A clinician reviews the full evidence trail in a web cockpit, can edit the proposed numbers, and only then does anything get applied. The result is measured for real, and the resolved case is written back into memory — so the next similar drift has one more precedent to draw on than the last one did.

How i built it

CockroachDB Basic (free tier) holds a 9-table schema, including a VECTOR(16) column with a distributed vector index that's the core memory mechanism. Eight AWS Lambda functions form the pipeline: a telemetry simulator standing in for real hardware, an anomaly detector, a diagnostic agent (the only one that calls a language model — Amazon Bedrock's Nova 2 Lite — and only ever for reasoning text, never a number), a calibration agent that does pure deterministic math with zero LLM involvement by design, a deployment agent, a recovery sweeper, and a guardian agent that produces a periodic health digest from CockroachDB Cloud's own status API. A React frontend (loaded via CDN, no build step) served from S3 gives a clinician a real approval gate, backed by its own API Gateway + Lambda. Every agent runs on its own EventBridge schedule and holds only the database credentials it strictly needs — no shared or admin-level access anywhere.

Challenges i ran into

The state machine's ordering was originally wrong — the human approval step was sequenced before calibration instead of after, meaning a clinician would have been asked to approve numbers that didn't exist yet. I caught it, fixed the ordering, and re-verified the whole chain.

A more subtle bug: a scheduled telemetry heartbeat kept writing healthy- looking readings into a session even after it had already been flagged anomalous, which meant a diagnosis could evaluate stale data instead of the reading that actually triggered it. The fix directly implements something my own original concept document called for on day one — freezing a session's telemetry the moment it leaves a monitoring state — I just hadn't built it yet when the bug appeared.

I also hit — and traced to the exact byte — a UUID array parsing issue where CockroachDB returned an array column as a raw string in one specific query path, causing a single stray character to be mistaken for a UUID. And more than once, a least-privilege permission grant was missing exactly one table a query touched — each one caught via CloudWatch logs and fixed with a single targeted GRANT rather than a broad credential.

Separately, i discovered mid-build that the ccloud CLI can't authenticate non-interactively at all — it always requires a browser popup — which meant my original plan to have an agent shell out to it inside a headless Lambda was a dead end. I pivoted the Guardian Agent to call CockroachDB Cloud's REST API directly with a service-account key instead, which turned out to be the actually-correct, officially-supported path for exactly this kind of automation.

Accomplishments that I am proud of

The calibration Mathematics is real, not a placeholder — a closed-form circular-mean rotation estimator, checked on a live test run against a known injected ground-truth drift of 33.82°, and it landed at 34.04°, a 0.22° error. The Deployment Agent then re-measures the correction against the same raw data and the residual error genuinely collapses toward zero — an honest, check-able proof the fix worked, not an assumed number.

I am also proud of the discipline around the human gate: the AI never outputs a number that could be applied to a device, only reasoning text. All deterministic math lives in code with zero LLM involvement, specifically so that "the AI hallucinated a bad number" can't be a failure mode of this system by construction.

What I learned

A lot of hands-on CockroachDB internals — vector indexing behavior, exactly how array columns come back over the wire in edge cases, optimistic concurrency patterns for a real multi-agent state machine. A lot of AWS Lambda deployment mechanics — bundling binary dependencies, IAM least privilege at both the database and the AWS layer, EventBridge Scheduler. And, repeatedly, that a system's safety net is only real once it's actually tested under a real failure — every rollback-and-recover behavior in this project was proven by a genuine bug, not a hypothetical one.

What's next for Reanchor

Extending the Telemetry Simulator to accept real device data instead of synthetic readings, so the same pipeline could sit in front of an actual research BCI platform without re-architecting anything downstream. Moving the fixed clinical thresholds into a small config table so they're tunable by a clinician at runtime instead of a code constant. And exploring a config-driven version of the calibration math for BCI paradigms beyond 2D cursor control.

Built With

Share this project:

Updates

Submission history