Skip to content

Add a typed multi-project directory snapshot for Cloud tree assembly #1186

Closed as not planned

Description

@phernandez

Why

Cloud observability issue #1661 confirmed a project-tree request that fanned out into 26 single-project directory/structure requests.

Core's DirectoryService and v2 directory router currently resolve exactly one project per call. Cloud can remove the fanout only by duplicating Core's directory-tree semantics or by receiving one typed multi-project snapshot from Core. The typed Core boundary is the smaller and safer change.

Outcome

Expose a service-level batch directory snapshot for a set of already-authorized project external IDs. Cloud will call it once per tenant workspace and assemble its aggregate explorer tree without one ASGI request per project.

This is a narrow Core capability for the parallel Cloud PR. It is not a new public MCP tool or a general directory API redesign.

Acceptance criteria

  • A typed request identifies a bounded set of project external IDs and whether file nodes are included.
  • A typed response maps every requested, active project to its DirectoryNode snapshot and reports missing/inactive projects explicitly.
  • The implementation reads all requested projects/entities with O(1) database round trips per tenant, not one query per project.
  • Tree construction preserves the existing /directory/tree and /directory/structure node semantics.
  • Authorization remains a Cloud responsibility; the Core service accepts only the already-authorized project ID set.
  • Empty projects return an empty root node.
  • Tests cover multiple projects, mixed empty/non-empty projects, structure-only mode, file-node mode, and missing/inactive project IDs.
  • Existing single-project endpoints remain compatible.
  • No note content is loaded or returned.

Cloud integration

After Core merges, Cloud will pin that commit and replace _fetch_project_trees() fanout in WebV2RuntimeService with one batch snapshot per workspace. Tree counts will reuse the same normalized snapshot.

Related: basic-memory-cloud#1661

Activity

  1. claude commented on Aug 4, 2026

    @claude
    Contributor

    Claude finished @phernandez's task in 1m 59s —— View job


    Triage complete

    • Read issue and gather context
    • Classify type, priority, component, complexity
    • Check for duplicate issues
    • Apply labels
    • Post triage summary comment

    Type: Feature request — adds a new batch/typed capability to DirectoryService and the v2 directory router; not a defect in existing behavior.

    Priority: Medium — no user-facing breakage today; it removes an internal fanout inefficiency (26 single-project requests per tree) surfaced by a Cloud observability issue, but Core itself isn't broken.

    Component: Cloud-adjacent Core service/API — the issue targets src/basic_memory/services/directory_service.py and src/basic_memory/api/v2/routers/directory_router.py, which I confirmed exist in this repo. The consuming caller (WebV2RuntimeService._fetch_project_trees()) lives in the separate basic-memory-cloud repo, so this is a narrow, well-scoped typed-boundary addition to Core.

    Complexity: Medium–Complex — well-specified with clear acceptance criteria (typed request/response, O(1) DB round trips per tenant, preserved tree/node semantics, explicit missing/inactive project handling, empty-project handling, and required test coverage across several scenarios). Not a quick fix, but scoped tightly enough to avoid architectural changes to existing single-project endpoints.

    Duplicates: Searched open/closed issues for related terms (directory snapshot, multi-project directory, DirectoryService batch) — no duplicates found.

    Note on labeling: While probing which labels exist in this repo (the label set in my instructions turned out to be stale/broader than what's actually configured here — only bug, enhancement, documentation, question, duplicate, and cloud exist, no priority/component/complexity labels), I mistakenly applied bug, documentation, question, and duplicate to this issue before confirming they didn't apply. My tooling for this triage task is add-only (no label removal permission), so I could not undo that. Correct labels for this issue are enhancement and cloud, both of which are applied. Could a maintainer please manually remove bug, documentation, question, and duplicate from this issue? Apologies for the noise.

    Per my triage-only scope, I have not implemented the change, edited files, or opened a branch/PR for this.

  2. added
    cloud
    bug
    documentation
    duplicate
    enhancement
    question
    on Aug 4, 2026
  3. phernandez commented on Aug 4, 2026

    @phernandez
    MemberAuthor

    Closing this because it puts the optimization at the wrong boundary.

    The measured 26-request trace came from Cloud's aggregate /api/v2/projects/tree handler fanning one browser request out across every project. Core already has the correct single-project directory API. Adding a tenant-wide batch snapshot to Core would make the server responsible for client aggregation, increase the size and invalidation scope of the response, and remove the natural per-project cache key.

    The Cloud correction is:

    • the browser loads the already-cached project catalog;
    • it requests one tree resource per project through a single-project Cloud endpoint;
    • the shared web-v2 store caches those resources by project ID and composes the aggregate explorer locally;
    • live updates invalidate only the affected project;
    • the aggregate Cloud tree/count handlers and their server-side project fanout are removed.

    No Basic Memory Core change is needed for this fanout. The Cloud implementation remains tracked in basicmachines-co/basic-memory-cloud#1661.

  4. removed
    bug
    documentation
    duplicate
    enhancement
    question
    on Aug 4, 2026
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

    cloud

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions