Repository navigation
fix(agent-memory): server-stamp byteSize + updatedAt on PUT /memory - #189
Merged
Merged
Conversation
Follow-up to ADR-003 Phase 1. Production smoke test showed `byteSize: 0` in responses because the route was trusting client-supplied metadata. This patch stamps `byteSize` (from utf-8 content length) and `updatedAt` (now) server-side on every section write. Client-supplied values for these fields are discarded. Also enforces ADR-003 invariant #2 ("Private by default") at write time by defaulting missing `visibility` to `'private'`. Changes: - backend/services/agentMemoryService.ts — adds `stampSectionsForWrite`; single-object sections go through `makeSection` for consistency. Whole-array replace semantics for `daily` and `relationships` are documented inline (Phase 2's /memory/sync `mode: 'patch'` will add element-level merge keyed by `date` / `otherInstanceId`). - backend/routes/agentsRuntime.ts PUT /memory — calls the stamper before the per-key dotted-$set merge; expanded docstring spells out merge semantics for each section category, the v1 content mirror behavior (incl. that `long_term: { content: '' }` is an intentional clear), and that `byteSize` + `updatedAt` are always server-stamped. Tests (13 new; 63/63 agent-memory pass): - Unit: stampSectionsForWrite covers single-object stamping, multi-byte utf-8 byteSize, client-value override, visibility default + preserve, no-sibling-creation, daily shape (no byteSize/updatedAt per ADR), relationships shape (updatedAt stamped, no byteSize), idempotence under same `now` across object + array sections. - Integration: byteSize returned end-to-end; multi-section writes each get correct per-section byteSize; array sections are whole-array replace (lock for Phase 1 intentional semantics); `long_term` clear via empty content blanks the v1 mirror. Reviewer finding (code-reviewer subagent) that `updatedAt` on every relationship entry bumps to `now` on array replace is intentional and consistent with whole-array semantics; proper per-entry freshness lands with Phase 2's /memory/sync. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
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
Follow-up to ADR-003 Phase 1 (#188). Production smoke test surfaced `byteSize: 0` in GET /memory responses because the route was trusting client-supplied metadata. This patch stamps `byteSize` (UTF-8 byte length of `content`) and `updatedAt` (now) server-side on every section write; client-supplied values for these fields are discarded. Also defaults missing `visibility` to `'private'` at the write layer so ADR-003 invariant #2 ("Private by default") is enforced both schema-side and route-side.
Scope (strict)
Changes
Reviewer findings addressed
Reviewed by the `code-reviewer` subagent pre-commit. Verdict: Approve with suggestions. Applied fixes:
Follow-ups deliberately deferred
Test plan
🤖 Generated with Claude Code