Skip to content

feat(core): add author_type (human|agent) to memory records - #1084

Merged
ajianaz merged 2 commits into
developfrom
feat/memory-author-type
Aug 24, 2026
Merged

ajianaz merged 2 commits into
developfrom
feat/memory-author-type

Conversation

@ajianaz

@ajianaz ajianaz commented Aug 21, 2026

Copy link
Copy Markdown
Collaborator

What

Add an author_type discriminator (human | agent) to memory records, defaulting to agent, filterable and sync-safe.

Why

Corin's agent-managed positioning and uteke-mobile quick-capture (human input) need to distinguish who authored a memory. Existing author columns on room_memories/documents are free-text names, not a type discriminator. Closes #1083.

Changes

  • Schema v15 → v16: ALTER TABLE memories ADD COLUMN author_type TEXT NOT NULL DEFAULT 'agent' + idx_memories_author_type; existing rows backfill to agent
  • Core: Memory.author_type (serde default/skip), validate_author_type() (invalid → Validation error), Store::set_author_type() + Uteke::set_author_type() facade (nonexistent id → false)
  • Server: /remember accepts optional author_type; validated before write → 400 on invalid
  • Bug found & fixed along the way: get_by_id/get_by_ids and all full-row SELECTs dropped source/source_type on read (mapper silently defaulted) — all now select the full column set
  • Tests: version asserts now use CURRENT_SCHEMA_VERSION instead of hardcoded numbers

Testing

  • cargo test -p uteke-core --lib: 493 passed, 0 failed, 25 ignored
  • cargo test -p uteke-server: 6 passed
  • cargo clippy -p uteke-core -p uteke-server uteke-mcp --all-features: clean
  • New tests: fresh-DB default agent; set human/agent + invalid rejected + missing id → false; simulated v15 DB migrates to v16 with legacy row backfilled

Schema v16: ALTER TABLE with DEFAULT 'agent' + index, backfills existing
rows. Memory struct + validate_author_type. set_author_type() on Store and
Uteke facade (invalid values -> Validation error). Server /remember accepts
optional author_type, 400 on invalid. All memory SELECTs now include
source/source_type/author_type (previously dropped on read). Version
asserts in tests use CURRENT_SCHEMA_VERSION instead of hardcoded numbers.
error!("Failed to set source for {id}: {e}");
}
}
// Set author type after storage (#1083). Validate before

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Dismissed as false positive after manual verification in 850507c: the first finding (persist-before-validate) was real and fixed — validation now runs before any insert. This follow-up claim is incorrect: set_author_type sits in the shared Ok(id) arm of match result, which both the remember and remember_with_contradiction paths reach (both map to id before the match). Verified against handlers.rs:224-227.

@github-actions

github-actions Bot commented Aug 21, 2026 •

Copy link
Copy Markdown

🔍 Cora AI Code Review

❌ Blocked — critical issues found.

🔴 Error (1)

  • crates/uteke-server/src/handlers.rs:224 — The handler validates req_data.author_type up front, but only the non-contradiction branch (remember path) calls uteke.set_author_type(&id, at). When req_data.detect_contradiction is true, the remember_with_contradiction result branch returns the id without ever setting author_type, so a client-supplied author_type: "human" is validated (passing) and then silently dropped — the memory is stored with the default 'agent'.

Review powered by cora-code · BYOK · MIT

…1083)

Cora review finding: /remember inserted the memory before validating
author_type, so an invalid value left a persisted record while the client
got a 400 (partial-write). Validation now runs before any insert.
Regenerates docs/api-reference.md (API Docs Fresh check).
@ajianaz
ajianaz merged commit 0dd4592 into develop Aug 24, 2026
13 of 14 checks passed
@ajianaz
ajianaz deleted the feat/memory-author-type branch August 24, 2026 00:32
ajianaz added a commit that referenced this pull request Aug 26, 2026
…1106) (#1108)

POST /remember and uteke remember --json stored author_type correctly
but never echoed it, so clients couldn't confirm what was recorded.
The CLI didn't even expose the field (#1084 shipped HTTP-only).

- HTTP /remember response now includes author_type (default mirrors
  the schema default 'agent', #1083)
- CLI: new --author-type flag (human|agent), validated BEFORE any
  write so invalid values fail loudly without leaving a stored row;
  echoed in --json on both remember paths (contradiction + plain)
- run_via_server path forwards the flag in the HTTP body

Verified empirically in isolated stores: explicit human -> echo human
+ DB human; default -> echo agent + DB agent; invalid 'robot' -> loud
error / HTTP 400, zero rows written.

Closes #1106

Co-authored-by: ajianaz <[email protected]>
ajianaz added a commit that referenced this pull request Sep 6, 2026