Skip to content

fix(cli): parse get-memory response correctly - #2111

Merged
nicoloboschi merged 1 commit into
mainfrom
fix/cli-memory-get-parse
Jun 10, 2026
Merged

fix(cli): parse get-memory response correctly#2111
nicoloboschi merged 1 commit into
mainfrom
fix/cli-memory-get-parse

Conversation

@nicoloboschi

Copy link
Copy Markdown
Collaborator

Problem

hindsight memory get <bank> <id> fails with a misleading "Invalid API response format" error whenever the memory has any entities.

The CLI deserializes the response into a hand-written local MemoryUnitDetail struct that had drifted out of sync with what GET /memories/{memory_id} (MemoryEngine.get_memory_unit) actually returns:

  • entities — the API returns a flat list of canonical-name strings (["Alice", "Bob"]), but the struct expected a list of {id, name} objects. serde_json::from_value errors on the type mismatch, and the friendly error layer renders it as "Invalid API response format".
  • fact type — the API field is type, but the struct renamed it to fact_type, so even when parsing succeeded the Type: line always printed UNKNOWN.

The endpoint returns an untyped JSON body in the OpenAPI spec, so the generated client never validates it — the mismatch only blows up in the CLI handler. These commands had no test coverage (the docs only demonstrate them with curl), so the drift went unnoticed.

Fix

  • entities: Option<Vec<String>> (was Vec<EntityRef>); removed the now-unused EntityRef struct.
  • Rename the type field serde alias from fact_typetype.
  • Update the entity display loop to print the canonical-name strings.
  • Add a comment on the struct noting it must mirror get_memory_unit.

Tests

Added two regression tests deserializing realistic API payloads (full + minimal). Both fail before the fix, pass after. cargo test green; ./scripts/hooks/lint.sh clean.

Notes

hindsight memory history was mentioned alongside this in a bug report but is not affected — it pretty-prints the raw JSON value with no struct parsing. A missing/non-observation memory there returns 404 ("API request failed (404)"), not a format error.

The `hindsight memory get` command deserialized the API response into a
local `MemoryUnitDetail` struct whose shape had drifted from what
`GET /memories/{memory_id}` (MemoryEngine.get_memory_unit) actually
returns:

- `entities` is a flat list of canonical-name strings, but the struct
  expected a list of `{id, name}` objects, so serde failed whenever a
  memory had entities — surfaced to users as the misleading
  "Invalid API response format".
- the fact type is exposed as `type`, but the struct renamed it to
  `fact_type`, so the Type line always printed UNKNOWN.

The endpoint returns an untyped JSON body in the OpenAPI spec, so the
generated client never validates it and the mismatch only blew up in the
CLI handler. These commands had no test coverage (docs use curl).

Fix the struct to match the response and add regression tests.
@nicoloboschi
nicoloboschi merged commit 72d9881 into main Jun 10, 2026
148 of 150 checks passed
@nicoloboschi
nicoloboschi deleted the fix/cli-memory-get-parse branch June 10, 2026 16:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant