Skip to content

feat: add created_by and last_updated_by user tracking to Entity#602

Merged
jope-bm merged 1 commit intomainfrom
add-entity-user-tracking
Feb 23, 2026
Merged

feat: add created_by and last_updated_by user tracking to Entity#602
jope-bm merged 1 commit intomainfrom
add-entity-user-tracking

Conversation

@jope-bm
Copy link
Contributor

@jope-bm jope-bm commented Feb 23, 2026

Summary

  • Add created_by and last_updated_by columns to the Entity model for tracking which cloud user created and last modified each entity
  • Add fields to EntityResponseV2 Pydantic schema so they appear in API responses
  • Add get_user_id callable to EntityService (default returns None for local/CLI; cloud overrides to read from UserContext)
  • Set tracking fields across all entity write paths: fast_write_entity, fast_edit_entity, create_entity, update_entity
  • Preserve created_by on updates — only last_updated_by changes
  • Add alembic migration k4e5f6g7h8i9 (idempotent, supports both SQLite and Postgres)

Test plan

  • Unit tests for all entity service write paths (created_by set on create, preserved on update, last_updated_by updated)
  • API test verifying created_by and last_updated_by fields appear in EntityResponseV2 (null for local/CLI)
  • CI passes

🤖 Generated with Claude Code

Track which cloud user created and last modified each entity. This enables
"last edited by {name}" display in team workspaces.

- Add created_by/last_updated_by columns to Entity model (nullable, null for local/CLI)
- Add fields to EntityResponseV2 Pydantic schema
- Add get_user_id callable to EntityService (default returns None)
- Set tracking fields in fast_write_entity, fast_edit_entity, create_entity, update_entity
- Preserve created_by on updates, only update last_updated_by
- Add alembic migration k4e5f6g7h8i9 (idempotent, supports both SQLite and Postgres)
- Add unit tests for all entity service write paths
- Add API test verifying fields appear in EntityResponseV2

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a81b7a4329

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

self._project_permalink: Optional[str] = None
# Callable that returns the current user ID (cloud user_profile_id UUID as string).
# Default returns None for local/CLI usage. Cloud overrides this to read from UserContext.
self.get_user_id: Callable[[], Optional[str]] = lambda: None

Choose a reason for hiding this comment

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

P1 Badge Inject user ID provider into EntityService

This change introduces created_by/last_updated_by writes, but get_user_id is initialized to lambda: None and there is no production wiring in this commit to override it, so all write paths keep storing NULL for both fields. In practice, cloud requests won’t record attribution even though the schema/migration now expose these columns, which defeats the feature and silently loses audit data.

Useful? React with 👍 / 👎.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is intentional — basic-memory is the open-source library and doesn't have a user concept itself. The get_user_id callable is a hook designed to be injected by the host application.

The production wiring lives in basic-memory-cloud's cloud_deps.py, which overrides all three entity service factories to inject _get_cloud_user_id (reads from UserContext contextvar set during ASGI proxy/MCP transport calls):

https://github.com/basicmachines-co/basic-memory-cloud/pull/468

So the flow is:

  1. basic-memory (this PR): adds get_user_id hook with safe lambda: None default
  2. basic-memory-cloud (PR Track: FastMCP 2.14.x outputSchema incompatibility with Claude Desktop #468): overrides entity services via dependency_overrides to inject the cloud-specific user resolution

NULL is correct for local CLI usage (no users). Cloud writes will have attribution once both PRs land.

Copy link
Member

@phernandez phernandez left a comment

Choose a reason for hiding this comment

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

good idea

@jope-bm jope-bm merged commit da4d369 into main Feb 23, 2026
32 checks passed
@jope-bm jope-bm deleted the add-entity-user-tracking branch February 23, 2026 18:21
@phernandez phernandez added this to the v0.19.0 milestone Feb 25, 2026
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.

2 participants