agent: ensure today's daily note file exists before LLM read_file#755
Open
seanly wants to merge 1 commit intosipeed:mainfrom
Open
agent: ensure today's daily note file exists before LLM read_file#755seanly wants to merge 1 commit intosipeed:mainfrom
seanly wants to merge 1 commit intosipeed:mainfrom
Conversation
- 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>
c9f8afc to
f3daad6
Compare
xiaket
reviewed
Feb 25, 2026
|
|
||
| // 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() { |
Collaborator
There was a problem hiding this comment.
How is this different from AppendToday?
nikolasdehor
left a comment
There was a problem hiding this comment.
Good idea — proactively creating the daily note file avoids a common LLM tool failure. Two concerns:
- TOCTOU race in
EnsureTodayFile: The function checksos.Statthen writes withos.WriteFile. If two goroutines (e.g., concurrent cron jobs) callGetMemoryContextsimultaneously, both can pass theStatcheck and both write the file. This is not catastrophic (the second write just overwrites with the same header), but useos.OpenFilewithO_CREATE|O_EXCLto 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()- Silently swallowing errors: Both
MkdirAllandWriteFileerrors 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📝 Description
🗣️ Type of Change
🤖 AI Code Generation
🔗 Related Issue
📚 Technical Context (Skip for Docs)
🧪 Test Environment
📸 Evidence (Optional)
Click to view Logs/Screenshots
☑️ Checklist