Skip to content

recent_activity formatter hardcodes display cap of 5, ignoring page_size #784

Closed

Description

@groksrc

Summary

recent_activity in project-specific mode displays at most 5 entities (and 5 relations) regardless of the page_size parameter, while the trailing "Activity Summary" line reports the true total returned by the API. This produces a misleading output where the user is told N items exist but only sees 5.

Reproduction

Call recent_activity against a project that has 9 entities in the timeframe, with default page_size=10:

recent_activity(project_id="755a4414-...", timeframe="today")

Output:

## Recent Activity: 755a4414-... (today)

**📄 Recent Notes & Documents (9):**
  • 01 - Welcome to Basic Memory
  • 02 - The Toolbox
  • 03 - The Structure of Basic Memory
  • 04 - Semantic Memory - Putting It All Together
  • 05 - Markdown Means It's Always a Two-Way Street

**Activity Summary:** 9 items found.

Only 5 of 9 entities are listed. Confirmed via Logfire: the API span api.memory.recent_activity.shape_response reports result_count: 9, so all 9 items came back from the API — the formatter is dropping 4 of them.

Root cause

src/basic_memory/mcp/tools/recent_activity.py, in _format_project_output:

# line 498
for entity in entities[:5]:  # Show top 5
    ...

# line 531
for rel in relations[:5]:  # Show top 5
    ...

The hardcoded [:5] slices are independent of page_size. Even recent_activity(page_size=100) will show only 5 entities and 5 relations.

The summary line at lines 543–550 uses len(activity_data.results) (the true count), so the heading says one number and the body shows another:

total = len(activity_data.results)
if activity_data.has_more:
    lines.append(f"\n**Activity Summary:** Showing {total} items (page {page}). ...")
else:
    lines.append(f"\n**Activity Summary:** {total} items found.")

Expected

Either:

  1. Replace the entities[:5] / relations[:5] slices with entities[:page_size] / relations[:page_size], or
  2. Drop the slice entirely (the API already paginates by page_size upstream — params["page_size"] = page_size is passed at line 149).

Option 2 is cleaner: the API is the canonical source of truth on how many items to return per page; the formatter shouldn't impose a second, lower cap.

There are similar hardcoded slices for observations (lines 513, 519, 521) and key items in discovery mode (lines 437, 444, 453) that may deserve the same review, though those have more nuanced grouping logic and may be intentional.

Environment

  • Discovered while exercising the cloud MCP surface from Claude Code.
  • Verified against Basic Memory Cloud - Dev MCP server.
  • Underlying server uses basic_memory package; bug is in the OSS code path.

Activity

  1. claude commented on May 3, 2026

    @claude
    Contributor

    Claude finished @groksrc's task in 2m 58s —— View job • claude/issue-784-20260503-0201 • Create PR ➔


    Triage & Fix: recent_activity hardcoded display cap

    • Analyze issue and classify
    • Read recent_activity.py to understand full context
    • Fix hardcoded [:5] slices in _format_project_output for entities and relations
    • Remove hardcoded [:10] cap on observations (API already paginates)
    • Add regression test (test_format_project_output_shows_all_entities_beyond_five)
    • Commit and push changes
    • Add bug label (other triage labels don't exist in the repo yet)

    Issue Classification:

    • Type: Bug
    • Priority: Medium — misleading output, not data loss; affects any recent_activity call where the project has >5 results in the timeframe
    • Component: MCP tool (recent_activity)
    • Complexity: Simple

    Root cause confirmed

    In src/basic_memory/mcp/tools/recent_activity.py, _format_project_output was slicing the already-paginated results a second time:

    for entity in entities[:5]:   # line 498 — hardcoded cap
    for obs in observations[:10]: # line 513 — hardcoded cap
    for rel in relations[:5]:     # line 531 — hardcoded cap

    The API already returns exactly page_size items (default 10). These secondary caps silently dropped results, producing the "9 items found / only 5 shown" discrepancy reported.

    Fix applied

    Removed all three formatter-side caps — the API is the canonical source of truth on result count:

    Location Before After
    Entities (line 498) for entity in entities[:5]: for entity in entities:
    Observations (line 513) for obs in observations[:10]: for obs in observations:
    Relations (line 531) for rel in relations[:5]: for rel in relations:

    The [:5] category grouping caps inside observations (show top 5 categories, 2 examples each) were left intentionally — those are display-density choices for the grouped view, not pagination caps.

    Discovery mode slices (lines 437, 444, 453) also left as-is per the issue's note that "those have more nuanced grouping logic and may be intentional."

    Files changed

    • src/basic_memory/mcp/tools/recent_activity.py — remove the three hardcoded slices
    • tests/mcp/test_tool_recent_activity.py — add test_format_project_output_shows_all_entities_beyond_five regression test with 9 entities

    |

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions