fix(memory): default missing daily[].date to today UTC (closes #435) - #438
Closed
samxu01 wants to merge 2 commits into
Closed
fix(memory): default missing daily[].date to today UTC (closes #435)#438samxu01 wants to merge 2 commits into
samxu01 wants to merge 2 commits into
Conversation
`commonly_save_my_memory` MCP tool contract documents `entries` as the
daily-write shape but doesn't disclose that each entry must already
carry a `date: YYYY-MM-DD` field. Cody surfaced this on 2026-05-24
during the Phase 2 huddle smoke: `long_term` writes succeeded, a
natural `daily` write failed with `sections.daily[].date must be
YYYY-MM-DD`.
Server-side default: when `date` is absent on a daily entry, fill in
today's UTC `YYYY-MM-DD` before validation. Explicit values still
flow through unchanged — `date: '2026/04/14'` (wrong format) and
`date: '2026-02-30'` (calendar-invalid) both still 400 per existing
tests. Only the omitted-date case is normalized.
This unblocks the most natural caller usage ("today's note") without
widening the schema's accepted shape. Backend-side fix keeps the
@commonlyai/mcp tool contract simple — no MCP tool-side change
needed.
## Tests
backend/__tests__/service/agent-memory-envelope.test.js — new test
case verifies that posting `{ sections: { daily: [{ content: 'x' }] } }`
without a date succeeds (200) and that the stored entry comes back
with today's UTC YYYY-MM-DD via a follow-up GET.
Existing tests still pass:
- rejects invalid YYYY-MM-DD date on daily entries (2026/04/14)
- also rejects calendar-invalid dates (feb 30)
- rejects invalid visibility on a daily entry
## Companion
GH issue #435 captures the original contract
drift report from Cody, including the MCP-tool seam pointer at
commonly-mcp/src/tools.js:230. After this lands the
`MCP tool says 'pass entries (array)' but backend says 'date is
required'` mismatch resolves to "tool says 'pass entries (array)',
backend fills date when missing" — caller-friendly.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…route) Self-review caught: the new daily-date-default test used mode: 'merge' which the /memory/sync route validator rejects (only 'full' and 'patch' are valid). My fix's defaulting logic runs BEFORE the mode validation in validateSectionsPayload, so the test was failing at the mode check not the date check. Switching to mode: 'patch' (merge-into-existing semantics, which is what we want) lets the route accept the request and exercise the date-defaulting path. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
samxu01
added a commit
that referenced
this pull request
May 24, 2026
…435) `commonly_save_my_memory` MCP tool contract advertises `entries` as the daily-write shape but doesn't disclose that each entry must already carry a `date: YYYY-MM-DD` field. Cody surfaced this on 2026-05-24 during the Phase 2 huddle smoke: `long_term` writes succeeded, a natural `daily` write failed with `sections.daily[].date must be YYYY-MM-DD`. Server-side default: when `date` is absent on a daily entry, fill in today's UTC `YYYY-MM-DD` before validation. Explicit values still flow through unchanged: - date: '2026/04/14' (wrong format) → still 400 (preserved) - date: '2026-02-30' (calendar-invalid) → still 400 (preserved) - date omitted → fills in today (new behaviour) Kindest fix for the common caller use case ("today's note") without widening the schema. Backend-only — no @commonlyai/mcp tool-side change needed. Test added in backend/__tests__/service/agent-memory-envelope.test.js verifies the default fills + the stored entry comes back with today's YYYY-MM-DD via a follow-up GET. Existing rejection tests preserved. Companion: GH issue #435 — Cody's original report with the MCP-tool seam pointer at commonly-mcp/src/tools.js:230. Co-Authored-By: Cody <cody@commonly.me> Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Contributor
Author
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.
Summary
sections.daily[].datewhen omitted — fills in today's UTCYYYY-MM-DDbefore validation.commonly_save_my_memoryMCP tool and backend YYYY-MM-DD validator).Why
Surfaced 2026-05-24 by Cody (cloud-codex) during the Phase 2 huddle smoke. The MCP tool advertises
section: 'daily'withentriesas input but doesn't tell callers each entry must already carry adate: YYYY-MM-DD. Natural writes fail:Cody's
long_termwrites worked; hisdailywrite didn't. Same bug for any agent calling the tool naturally.Fix
In
backend/routes/agentsRuntime.ts'svalidateSectionsPayload, before checkingisValidYMD(d?.date), defaultd.dateto today's UTCYYYY-MM-DDif missing. Explicit values still flow through unchanged:date: '2026/04/14'(wrong format) — still 400 (existing test passes)date: '2026-02-30'(calendar-invalid) — still 400 (existing test passes)dateomitted — fills in today (new test added)This is the kindest fix for the common caller: doesn't widen the schema, just normalizes one absent field.
Test plan
backend/__tests__/service/agent-memory-envelope.test.js:defaults missing daily[].date to today UTC (YYYY-MM-DD)— POSTs{ daily: [{ content: 'x' }] }(no date), expects 200, then GETs the memory and verifies today's date is on the stored entry.commonly_save_my_memory({ section: 'daily', entries: [{ content: '...' }] })without specifying date, confirms 200 + entry lands.Companion
commonly-mcp/src/tools.js:230.docs/audits/ui-smoke-2026-05-23/huddle-observations.md.🤖 Generated with Claude Code