Skip to content

agent: ensure today's daily note file exists before LLM read_file#755

Open
seanly wants to merge 1 commit intosipeed:mainfrom
seanly:fix/daily-memory-ensure
Open

agent: ensure today's daily note file exists before LLM read_file#755
seanly wants to merge 1 commit intosipeed:mainfrom
seanly:fix/daily-memory-ensure

Conversation

@seanly
Copy link

@seanly seanly commented Feb 25, 2026

  • Add EnsureTodayFile() to create memory/YYYYMM/YYYYMMDD.md with date header if missing
  • Call it from GetMemoryContext() so path advertised in system prompt always exists
  • Avoids read_file tool failure when agent (or cron) tries to read today's note

📝 Description

🗣️ Type of Change

  • 🐞 Bug fix (non-breaking change which fixes an issue)
  • ✨ New feature (non-breaking change which adds functionality)
  • 📖 Documentation update
  • ⚡ Code refactoring (no functional changes, no api changes)

🤖 AI Code Generation

  • 🤖 Fully AI-generated (100% AI, 0% Human)
  • 🛠️ Mostly AI-generated (AI draft, Human verified/modified)
  • 👨‍💻 Mostly Human-written (Human lead, AI assisted or none)

🔗 Related Issue

📚 Technical Context (Skip for Docs)

  • Reference URL:
  • Reasoning:

🧪 Test Environment

  • Hardware:
  • OS:
  • Model/Provider:
  • Channels:

📸 Evidence (Optional)

Click to view Logs/Screenshots

☑️ Checklist

  • My code/docs follow the style of this project.
  • I have performed a self-review of my own changes.
  • I have updated the documentation accordingly.

- Add EnsureTodayFile() to create memory/YYYYMM/YYYYMMDD.md with date header if missing
- Call it from GetMemoryContext() so path advertised in system prompt always exists
- Avoids read_file tool failure when agent (or cron) tries to read today's note

Co-authored-by: Cursor <cursoragent@cursor.com>
@seanly seanly force-pushed the fix/daily-memory-ensure branch from c9f8afc to f3daad6 Compare February 25, 2026 05:12

// EnsureTodayFile creates today's daily note file (and month directory) if missing,
// so paths advertised in the system prompt (memory/YYYYMM/YYYYMMDD.md) exist when the LLM reads them.
func (ms *MemoryStore) EnsureTodayFile() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

How is this different from AppendToday?

@xiaket xiaket added domain: agent bug Something isn't working labels Feb 25, 2026
Copy link

@nikolasdehor nikolasdehor 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 — proactively creating the daily note file avoids a common LLM tool failure. Two concerns:

  1. TOCTOU race in EnsureTodayFile: The function checks os.Stat then writes with os.WriteFile. If two goroutines (e.g., concurrent cron jobs) call GetMemoryContext simultaneously, both can pass the Stat check and both write the file. This is not catastrophic (the second write just overwrites with the same header), but use os.OpenFile with O_CREATE|O_EXCL to atomically create-if-not-exists:
f, err := os.OpenFile(todayFile, os.O_CREATE|os.O_EXCL|os.O_WRONLY, 0o644)
if err \!= nil {
    return // already exists or other error
}
f.Write([]byte(header))
f.Close()
  1. Silently swallowing errors: Both MkdirAll and WriteFile errors are silently ignored (return / _ =). If the file cannot be created (e.g., permissions issue on workspace dir), the LLM will still hit the read_file failure downstream. At minimum, consider logging a warning so the user knows why daily notes are not working.

Otherwise a clean, targeted fix.

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

Labels

bug Something isn't working domain: agent

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants