Skip to content

feat(memory): add selective branch pick support#193

Merged
mergify[bot] merged 16 commits into
matrixorigin:mainfrom
gouhongshen:feature/memory-pick
May 12, 2026
Merged

feat(memory): add selective branch pick support#193
mergify[bot] merged 16 commits into
matrixorigin:mainfrom
gouhongshen:feature/memory-pick

Conversation

@gouhongshen
Copy link
Copy Markdown
Contributor

@gouhongshen gouhongshen commented Apr 21, 2026

Summary

  • add selective branch pick support across git, MCP remote, and REST API
  • support key_list, snapshot_range, and retrieve selectors, optional target branch, and fail|skip|accept conflict strategies
  • add retrieve.min_score and dry_run preview/output shaping for memory_pick
  • add MCP/API/remote e2e coverage for success, validation, conflicts, target branches, retrieve ranking, and dry-run previews

Interface

MCP

Tool: memory_pick

Inputs:

  • source: source branch name
  • target: optional target branch, defaults to main
  • strategy: optional fail | skip | accept, defaults to fail
  • selector:
    • {"type":"key_list","keys":["", "..."]}
    • {"type":"snapshot_range","from_snapshot":"snap_a","to_snapshot":"snap_b"}
    • {"type":"retrieve","query":"alpha query","top_k":5,"min_score":0.82} (top_k and min_score only apply to retrieve)
  • dry_run (optional preview mode; no database mutation):
    • {"limit":10,"offset":0,"include_content_preview":true,"include_scores":true}
    • limit / offset only shape preview output; they do not change the selected candidate set
    • preview output never includes embeddings

Outputs:

  • normal execution returns plain text in content[0].text
  • dry_run returns preview JSON rendered in content[0].text, including:
    • result
    • summary
    • page
    • candidates
  • v1 intentionally does not add session_id

REST API

POST /v1/branches/:source/pick

Request body:

  • target: optional target branch, defaults to main
  • strategy: optional fail | skip | accept, defaults to fail
  • selector: same shape as MCP
  • dry_run: same shape as MCP; when present, returns a structured preview instead of applying changes

Success response:

  • normal execution:
{"result":"Picked ..."}
  • dry_run preview:
{
  "dry_run": true,
  "result": "Previewed ...",
  "summary": {
    "candidate_count": 2,
    "shown_count": 1,
    "would_apply": 2,
    "would_skip": 0,
    "conflict_count": 0,
    "would_abort": false
  },
  "page": {
    "limit": 1,
    "offset": 0,
    "has_more": true
  },
  "candidates": [
    {
      "memory_id": "019...",
      "content_preview": "alpha branch memory",
      "score": 0.93,
      "status": "would_apply",
      "reason": "new_or_updated_row"
    }
  ]
}

Error mapping:

  • 422: validation error
  • 404: source/target branch or snapshot not found
  • 409: pick conflict when strategy=fail

Testing

  • cargo check -p memoria-mcp -p memoria-api
  • cargo test -p memoria-mcp --test branch_e2e --no-run
  • cargo test -p memoria-api --test api_e2e --no-run
  • local runtime pick e2e currently still depends on a ready MatrixOne test DB; on this machine the existing multi-db harness times out before tests start

Copilot AI review requested due to automatic review settings April 21, 2026 02:36
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds a new selective “branch pick” capability that applies a subset of changes from one memory branch into another (defaulting to main), wiring it through MCP tooling, the RemoteClient, and the REST API, with E2E coverage for success and conflict cases.

Changes:

  • Introduces memory_pick MCP tool + GitForDataService support for picking by key_list, snapshot_range, or retrieve selectors with conflict strategies.
  • Adds REST endpoint POST /v1/branches/:name/pick and RemoteClient forwarding for memory_pick.
  • Adds MCP/API/remote E2E tests covering happy paths, validation, and conflict handling.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
memoria/crates/memoria-mcp/tests/branch_e2e.rs Adds MCP E2E coverage for key_list/snapshot_range/retrieve pick and conflict strategies
memoria/crates/memoria-mcp/src/remote.rs Forwards memory_pick to the new REST pick endpoint
memoria/crates/memoria-mcp/src/git_tools.rs Implements memory_pick tool parsing, selection logic, and pick execution
memoria/crates/memoria-git/src/service.rs Adds MatrixOne DDL helpers for data branch pick (keys + snapshot range)
memoria/crates/memoria-api/tests/api_e2e.rs Adds REST + remote E2E tests for pick, validation, and conflicts
memoria/crates/memoria-api/src/routes/snapshots.rs Adds REST handler that calls MCP git_tools pick and maps conflicts to HTTP 409
memoria/crates/memoria-api/src/routes/mcp.rs Marks memory_pick as dirtying FULL metrics state
memoria/crates/memoria-api/src/models.rs Adds PickRequest and PickSelector request models
memoria/crates/memoria-api/src/lib.rs Adds /v1/branches/:name/pick route and metrics dirty-path handling

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread memoria/crates/memoria-mcp/src/git_tools.rs
Comment thread memoria/crates/memoria-mcp/src/git_tools.rs Outdated
Comment thread memoria/crates/memoria-mcp/src/git_tools.rs Outdated
Comment thread memoria/crates/memoria-git/src/service.rs
gouhongshen and others added 2 commits April 21, 2026 11:10
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@gouhongshen gouhongshen force-pushed the feature/memory-pick branch from dc5812a to a8ecfdf Compare April 21, 2026 03:15
@gouhongshen gouhongshen changed the title Add selective memory_pick branch apply feat(memory): add selective branch pick support Apr 21, 2026
gouhongshen and others added 4 commits April 21, 2026 11:26
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@gouhongshen gouhongshen requested a review from Copilot April 21, 2026 09:01
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread memoria/crates/memoria-mcp/src/git_tools.rs Outdated
Comment thread memoria/crates/memoria-mcp/src/git_tools.rs
gouhongshen and others added 10 commits April 21, 2026 17:49
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Resolve conflicts: keep memory_pick MCP tool, route, and docs alongside
upstream's selective apply helpers and list_branches tuple upgrade.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@mergify
Copy link
Copy Markdown

mergify Bot commented May 12, 2026

Merge Queue Status

  • Entered queue2026-05-12 06:22 UTC · Rule: main
  • Checks skipped · PR is already up-to-date
  • Merged2026-05-12 06:23 UTC · at 0eda39b1dbab1e837819643f6e966d981ac3a896 · squash

This pull request spent 13 seconds in the queue, including 2 seconds running CI.

Required conditions to merge

@mergify mergify Bot merged commit 4d16236 into matrixorigin:main May 12, 2026
5 checks passed
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.

3 participants