Skip to content

feat: Phase-1 Maia <-> ALMA memory gateway adapter#34

Open
RBKunnela wants to merge 2 commits into
mainfrom
feat/maia-alma-adapter
Open

feat: Phase-1 Maia <-> ALMA memory gateway adapter#34
RBKunnela wants to merge 2 commits into
mainfrom
feat/maia-alma-adapter

Conversation

@RBKunnela

Copy link
Copy Markdown
Owner

Summary

Deploy-ready Phase-1 adapter bridging the Maia gateway and ALMA memory. Maps the gateway's memory.query / memory.store RPC calls onto ALMA's retrieve() / 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()
  • Phase 1 scope: facts-first. Stores and retrieves factual domain knowledge. Outcome/strategy enrichment is explicitly out of scope for this phase.

Deployment

  • Deploys on the user's VPS at /opt/maia.
  • Requires pip install alma-memory[local] on the VPS.
  • See the included runbook for the deploy procedure.

Deferred (documented as TODOs)

  • Phase 3 — outcomes / strategy enrichment.
  • Phase 4 — RN parity and HIPAA considerations.

Validation

  • 11 tests passing in integrations/maia/.

🤖 Generated with Claude Code

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>
@coderabbitai

coderabbitai Bot commented Jun 30, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@RBKunnela, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 59 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 89e65e5c-c7b5-405a-b328-39a7d0371223

📥 Commits

Reviewing files that changed from the base of the PR and between 164d2e3 and 94ed8e9.

📒 Files selected for processing (4)
  • integrations/maia/README.md
  • integrations/maia/alma_gateway_adapter.py
  • integrations/maia/spike_roundtrip.py
  • integrations/maia/test_alma_gateway_adapter.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/maia-alma-adapter

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +53 to +68
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())

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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}")

Comment on lines +171 to +178
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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant