Skip to content

fix(mcp): harden handleSessionSummary with process override and empty-content guard#424

Merged
Alan-TheGentleman merged 2 commits into
mainfrom
fix/session-summary-hardening
May 27, 2026
Merged

fix(mcp): harden handleSessionSummary with process override and empty-content guard#424
Alan-TheGentleman merged 2 commits into
mainfrom
fix/session-summary-hardening

Conversation

@Alan-TheGentleman
Copy link
Copy Markdown
Collaborator

Summary

  • handleSessionSummary was the sole write tool still calling bare resolveWriteProject() after commit b094052 hardened every other write tool. The process-level project override (ENGRAM_PROJECT / engram mcp --project) was silently ignored, causing wrong-project writes and an OpenCode timeout in ambiguous-cwd environments.
  • An empty mem_session_summary had no content guard, so it persisted a blank observation that created a stuck sync_mutation blocking cloud upgrade.

Changes

Test plan

4 new tests in internal/mcp/mcp_test.go: process override writes to default project, override bypasses ambiguous cwd, empty content rejected, whitespace-only rejected. go test ./... && go vet ./... && go build ./... clean.

Closes #403
Closes #413
Closes #393

…ent guard

Closes #403
Closes #413
Closes #393

handleSessionSummary was the one write tool missed in commit b094052: it called
bare resolveWriteProject() instead of resolveWriteProjectWithProcessOverride(),
so ENGRAM_PROJECT / `engram mcp --project` was silently ignored, causing writes
to the wrong project and an OpenCode timeout on ambiguous cwd.

Additionally, no empty-content guard existed before AddObservation; an empty
mem_session_summary would persist a blank observation that created a stuck
sync_mutation blocking cloud upgrade.

Fixes:
- Switch to resolveWriteProjectWithProcessOverride(cfg.DefaultProject) so the
  process-level override takes precedence over cwd detection, matching all other
  write tools.
- Add strings.TrimSpace(content) == "" guard (same pattern as handleSave / #374)
  before any project resolution or store write.

Tests: 4 new table-driven tests covering process-override with no-git dir,
process-override bypassing ambiguous cwd, empty content rejection, and
whitespace-only content rejection.
Copilot AI review requested due to automatic review settings May 27, 2026 14:43
@Alan-TheGentleman Alan-TheGentleman added the type:bug Bug fix label May 27, 2026
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 hardens the MCP mem_session_summary write path to better match the expected “trusted process override first” project-resolution behavior and to prevent persisting empty session summaries that can later break cloud upgrade/sync validation.

Changes:

  • Reject empty/whitespace-only content in handleSessionSummary before any project resolution or store writes.
  • Resolve write project via resolveWriteProjectWithProcessOverride(cfg.DefaultProject) so ENGRAM_PROJECT / engram mcp --project is honored.
  • Add unit tests covering process override behavior and empty/whitespace content rejection.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
internal/mcp/mcp.go Adds empty-content guard and switches session summary project resolution to honor the process-level override.
internal/mcp/mcp_test.go Adds tests for session summary process override and empty/whitespace content rejection.

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

Comment thread internal/mcp/mcp.go
Comment on lines +1608 to 1613
// Honour process-level project override (cfg.DefaultProject) set via
// ENGRAM_PROJECT or `engram mcp --project` (#403/#413). Falls back to cwd
// detection when no override is configured.
detRes, err := resolveWriteProjectWithProcessOverride(cfg.DefaultProject)
if err != nil {
return writeProjectErrorResult(nil, "", detRes, err), nil
…ardening

# Conflicts:
#	internal/mcp/mcp_test.go
@Alan-TheGentleman Alan-TheGentleman merged commit 2087c5b into main May 27, 2026
5 checks passed
@Alan-TheGentleman Alan-TheGentleman deleted the fix/session-summary-hardening branch May 27, 2026 14:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type:bug Bug fix

Projects

None yet

2 participants