feat: Phase-1 Maia <-> ALMA memory gateway adapter#34
Conversation
Self-contained, framework-agnostic adapter that backs the Maia gateway's
WebSocket JSON-RPC memory methods with ALMA (facts-first read + write).
- handle_memory_query: alma.retrieve -> {ok, payload.results[{content}]};
empty memory returns empty results, not an error
- handle_memory_store: alma.add_domain_knowledge (facts); persona -> agent/scope
- build_alma(): ALMA.quickstart() local backend, or from_config(path)
- Defensive: handlers never raise into the RPC layer ({ok: False, error})
- No top-level alma import -> module imports without the package installed
- Tests run against a fake in-memory ALMA (no embeddings model/network)
- README VPS runbook + device contract; Phase-3/4 deferred TODOs documented
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Warning Review limit reached
Next review available in: 59 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Code Review
This pull request introduces the Maia <-> ALMA Memory Adapter (Phase 1), which backs the Maia gateway's memory with ALMA. It includes the adapter implementation, a runnable spike script, unit tests using a fake in-memory ALMA, and documentation. Feedback focuses on improving the robustness of string formatting in _slice_to_contents to avoid awkward outputs when attributes are empty, and expanding _resolve_user_id to handle non-string user IDs (such as integers) by converting them to strings.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| for h in getattr(memory_slice, "heuristics", None) or []: | ||
| condition = getattr(h, "condition", "") | ||
| strategy = getattr(h, "strategy", "") | ||
| if condition or strategy: | ||
| contents.append(f"When {condition}: {strategy}".strip()) | ||
|
|
||
| for pref in getattr(memory_slice, "preferences", None) or []: | ||
| text = getattr(pref, "preference", None) | ||
| if text: | ||
| contents.append(str(text)) | ||
|
|
||
| for ap in getattr(memory_slice, "anti_patterns", None) or []: | ||
| pattern = getattr(ap, "pattern", "") | ||
| better = getattr(ap, "better_alternative", "") | ||
| if pattern: | ||
| contents.append(f"Avoid: {pattern}. Instead: {better}".strip()) |
There was a problem hiding this comment.
The current implementation of _slice_to_contents can produce malformed or awkward strings if some attributes are None or empty. For example, if condition is None or empty, it formats as When : some_strategy. If better_alternative is None or empty, it formats as Avoid: some_pattern. Instead: None or Avoid: some_pattern. Instead: . Improving the checks and fallback values ensures clean, human-readable strings are returned.
for h in getattr(memory_slice, "heuristics", None) or []:
condition = (getattr(h, "condition", "") or "").strip()
strategy = (getattr(h, "strategy", "") or "").strip()
if condition and strategy:
contents.append(f"When {condition}: {strategy}")
elif condition:
contents.append(f"When {condition}")
elif strategy:
contents.append(f"Strategy: {strategy}")
for pref in getattr(memory_slice, "preferences", None) or []:
text = getattr(pref, "preference", None)
if text:
contents.append(str(text))
for ap in getattr(memory_slice, "anti_patterns", None) or []:
pattern = (getattr(ap, "pattern", "") or "").strip()
better = (getattr(ap, "better_alternative", "") or "").strip()
if pattern and better:
contents.append(f"Avoid: {pattern}. Instead: {better}")
elif pattern:
contents.append(f"Avoid: {pattern}")| def _resolve_user_id(metadata: Optional[Dict[str, Any]]) -> Optional[str]: | ||
| """Derive a user_id from metadata when the device supplies one.""" | ||
| if isinstance(metadata, dict): | ||
| for key in ("user_id", "userId", "user"): | ||
| value = metadata.get(key) | ||
| if isinstance(value, str) and value.strip(): | ||
| return value.strip() | ||
| return None |
There was a problem hiding this comment.
The _resolve_user_id function currently only extracts the user ID if it is explicitly a string (isinstance(value, str)). However, user IDs are very commonly represented as integers (e.g., database auto-increment IDs). Converting non-container types (like integers) to strings makes the adapter significantly more robust and compatible with various user ID formats.
| def _resolve_user_id(metadata: Optional[Dict[str, Any]]) -> Optional[str]: | |
| """Derive a user_id from metadata when the device supplies one.""" | |
| if isinstance(metadata, dict): | |
| for key in ("user_id", "userId", "user"): | |
| value = metadata.get(key) | |
| if isinstance(value, str) and value.strip(): | |
| return value.strip() | |
| return None | |
| def _resolve_user_id(metadata: Optional[Dict[str, Any]]) -> Optional[str]: | |
| """Derive a user_id from metadata when the device supplies one.""" | |
| if isinstance(metadata, dict): | |
| for key in ("user_id", "userId", "user"): | |
| value = metadata.get(key) | |
| if value is not None and not isinstance(value, (dict, list)): | |
| val_str = str(value).strip() | |
| if val_str: | |
| return val_str | |
| return None |
…imit (pentest MED) Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Summary
Deploy-ready Phase-1 adapter bridging the Maia gateway and ALMA memory. Maps the gateway's
memory.query/memory.storeRPC calls onto ALMA'sretrieve()/add_domain_knowledge()APIs.Adds
integrations/maia/(adapter + runbook + spike + tests). 11 tests passing.What it does
memory.query->ALMA.retrieve()memory.store->ALMA.add_domain_knowledge()Deployment
/opt/maia.pip install alma-memory[local]on the VPS.Deferred (documented as TODOs)
Validation
integrations/maia/.🤖 Generated with Claude Code