Skip to content

Auto-write created / modified frontmatter on BM-owned writes #684

Closed

Description

@bm-clawd

Currently, Basic Memory tracks created_at and updated_at timestamps at the entity level (visible in JSON output via API/MCP), but these timestamps don't appear in the markdown files themselves.

Current behavior:

  • Entity timestamps exist in the database
  • They're accessible via JSON output
  • Frontmatter doesn't include them unless manually written/maintained

Desired behavior:

  • BM automatically writes created_at and updated_at into YAML frontmatter when creating/updating notes
  • These fields would be managed by BM itself (not AI/user-maintained)
  • Timestamps would be visible in the plain-text files, not just the database

Use cases:

  • Consistent timestamp metadata across all notes without manual maintenance
  • Temporal queries/filters based on frontmatter (e.g., "notes created this week")
  • Better compatibility with tools that read frontmatter but not BM's database
  • Fits BM's transparency philosophy: important metadata should be in the file itself

Suggested implementation:

  • Auto-inject created_at on note creation
  • Auto-update updated_at on note modification
  • Make these "reserved" frontmatter fields (schema validation aware, but not user-editable)
  • Respect existing timestamps if already present (don't overwrite manual entries)

Related:

  • Picoschema metadata: section could declare these as system-managed fields
  • Would complement existing frontmatter features (status, tags, priority)

Activity

  1. claude commented on Mar 20, 2026

    @claude
    Contributor

    Claude finished @bm-clawd's task in 58s —— View job


    Triage Analysis

    • Read and understand the issue
    • Search for duplicate issues
    • Classify issue type, priority, and complexity
    • Add appropriate labels
    • Provide triage summary

    Summary

    Type: Enhancement (improvement to existing feature)

    Priority: Medium — improves transparency and compatibility with external tools, aligns with BM's "files as source of truth" philosophy, but not blocking any core functionality.

    Component: Database/sync + MCP tools (write_note, edit_note)

    Complexity: Medium — requires changes across the markdown writing pipeline, sync layer, and potentially frontmatter parsing.


    Duplicate Check

    No exact duplicate found. Related issue: #616 (Temporal query optimization) touches created_at/updated_at as search dimensions, but focuses on querying — not on writing timestamps into frontmatter. These are complementary, not duplicates. Implementing this issue would actually help #616 by making dates visible in frontmatter for temporal filtering.


    Implementation Notes

    Key areas to touch:

    • src/basic_memory/markdown/ — frontmatter serialization when writing notes
    • src/basic_memory/services/ — entity write/update logic to inject timestamps
    • src/basic_memory/sync/ — ensure timestamps are preserved across sync
    • Need to handle the "reserved fields" concept (don't overwrite user-set values on first write, but manage on subsequent updates)

    Edge cases to consider:

    • What happens when a file is imported with existing created_at in frontmatter? (Respect it.)
    • What format for timestamps? ISO 8601 is likely the right choice.
    • updated_at should reflect file modification time, not DB update time — these should stay in sync.

    Labels added: enhancement, medium, database, mcp

  2. bm-clawd commented on Mar 20, 2026

    @bm-clawd
    ContributorAuthor

    Additional context from Discord #help

    Expected behavior (per Drew Nellins):

    • If created_at/updated_at exist in frontmatter → those should be authoritative (override DB)
    • If they're missing → DB manages them automatically

    Current observed behavior (per @titan):
    When trying to validate these fields via schema:

    schema:
      metadata:
        created_at:
          type: string
          format: datetime
        updated_at:
          type: string
          format: datetime

    Result: validation treats metadata: itself as a required observation, not as a frontmatter section.

    Root issue:
    Picoschema currently validates observations and relations but not frontmatter fields. This means:

    • Frontmatter can contain arbitrary YAML (by design)
    • But schemas can't enforce which frontmatter fields exist or their types
    • Timestamp fields in frontmatter may not be getting preserved/respected

    Test needed:

    1. Create note with created_at: 2024-01-01T10:00:00Z in frontmatter
    2. Index it
    3. Read entity JSON via API/MCP
    4. Verify: does entity['created_at'] match frontmatter value or DB auto-generated value?

    cc @titan for original use case

  3. added
    needs reviewA human maintainer needs to look at this issue
    needs investigationIssue needs further investigation and/or refinement
    and removed
    needs reviewA human maintainer needs to look at this issue
    on Mar 20, 2026
  4. phernandez commented on Jul 16, 2026

    @phernandez
    Member

    Being implemented together with #238 in a single PR (they share the frontmatter/timestamp code path). Canonical fields will be created / modified — the fields BM's markdown parser already reads (markdown/utils.py:59-60) — with BM auto-writing them on create/update and never overwriting a value the frontmatter already carries. Tracking the work from #238.

  5. phernandez commented on Jul 17, 2026

    @phernandez
    Member

    Managed timestamp policy after reviewing #1089

    This issue stays separate and follows #238. #238 establishes timestamp parsing and file/DB consistency; this issue adds automatic frontmatter mutation only for Basic Memory-owned writes.

    Write policy

    • Canonical written fields are created and modified.
    • Create: explicit canonical values supplied on creation are honored. Missing values are initialized to the same current timestamp.
    • Update/edit: preserve created and always set modified to the current write time.
    • Do not infer that an unchanged incoming modified was an intentional override merely because a full-document request carried the old frontmatter forward.
    • Move: preserve both semantic timestamps. A path change is not a content timestamp change.
    • Passive index/sync: never inject or rewrite timestamp frontmatter. User-authored file values remain authoritative through Feature Request: Support custom timestamps in note frontmatter #238.
    • Legacy frontmatterless notes: partial edits remain frontmatterless. We will not add a YAML block solely to stamp timestamps; a separate explicit migration/backfill can cover that use case if wanted.
    • Active writes normalize timestamp values to timezone-aware ISO 8601 strings so the persisted representation is stable across YAML readers and machines.
    • Aliases such as date, created_at, and updated_at are not part of the first managed-write implementation.

    Implementation constraints

    • Resolve the timestamp policy once in the service-owned note preparation stage.
    • Carry typed timestamps forward; do not reparse serialized metadata in local/cloud persistence layers.
    • Frontmatter updates used by partial edits must preserve the body bytes exactly, including leading indentation, trailing whitespace, newline style, and BOM handling.
    • Tests must cover create, full replace, every partial edit family, frontmatterless legacy notes, moves, and local/cloud parity.

    Implementation should begin only after the clean #238 foundation lands.

  6. changed the title [-]Auto-sync entity created_at / updated_at timestamps into frontmatter[/-] [+]Auto-write `created` / `modified` frontmatter on BM-owned writes[/+] on Aug 29, 2026
  7. phernandez commented on Aug 29, 2026

    @phernandez
    Member

    Narrowing this to what's left. The read side landed in #1100: created / modified in frontmatter are parsed into created_at / updated_at (markdown/entity_parser.py, services/note_preparation.py) and documented in docs/NOTE-FORMAT.md. What is not implemented is the write side — no BM-owned write (write_note, edit_note, move) injects the fields; only the importers do, and passive indexing deliberately never adds them.

    The policy is already settled in my comment above (create initializes both; edit bumps modified; move preserves; passive sync never touches; tz-aware ISO strings; byte-exact body preservation on partial edits), so this no longer needs investigation. Retitled accordingly and dropping the created_at/updated_at naming and the schema-validation ask (separate picoschema concern). Implementation is medium: the create/update/edit/move paths in note_preparation.py, frontmatter serialization via dump_frontmatter, and local + cloud parity tests including frontmatterless legacy notes.

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

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions