Skip to content

fix: require container scope on by-id memory routes; bump getmnemo to ^0.5.1 - #2

Merged
shhahhussain merged 2 commits into
mainfrom
claude/hungry-gates-192630
Aug 19, 2026
Merged

fix: require container scope on by-id memory routes; bump getmnemo to ^0.5.1#2
shhahhussain merged 2 commits into
mainfrom
claude/hungry-gates-192630

Conversation

@shhahhussain

Copy link
Copy Markdown
Contributor

Problem

The Mnemo API requires a container on by-id memory routes (requireMemoryScope guard): GET/PATCH/DELETE /v1/memories/:id return 400 without a containerTag (or scopeType+scopeId) query param. The get and rm commands sent neither, so both failed against production.

Changes

Container scope fix

  • get and rm now take -C/--container, resolved via the same precedence as the other commands (flag > GETMNEMO_CONTAINER > config defaultContainerTag) and passed to the SDK call; exit 2 with the standard container-required message when nothing resolves ({ok:false,error:"container_required"} under --json).
  • Bumped getmnemo ^0.2.0^0.5.1 for the options parameter on get/update/delete; getClient() also seeds defaultContainerTag from env/config as a backstop (per-call values win).

Regressions from the 0.5.1 bump, caught in review and fixed

  • login was broken for every user: its credential probe called list() with no container, which 0.5.1 rejects client-side. Now probes with a synthetic read-only cli:login-probe tag.
  • Bare getmnemo list threw a raw SDK error at exit 1 (0.5.1 requires a container on list). Now gated like the other commands; README updated.
  • CI prod-smoke cleanup deleted ids without --container (ids span two containers), leaking memories into the prod test workspace every run. Now tracks id + container pairs.
  • rm misreported recoverable deletes as final: now prints the restorable-until window, includes the delete receipt in --json, and supports --permanent for an immediate purge.

Test plan

  • npm run lint (tsc --noEmit) green
  • npm test — 14/14, including: containerTag reaches the request query for get/rm/list; flag beats GETMNEMO_CONTAINER; env fallback; exit-2 + message (human and --json) when nothing resolves; --permanent sends permanent=true; login probe URL
  • npm run build green
  • Independent code review (6 finder angles + verification against the installed SDK); all CRITICAL/HIGH findings fixed
  • CI prod smoke on main after merge (exercises the fixed cleanup path against production)

Deferred

  • workspaceId is @deprecated and ignored by SDK 0.5.1 (identity comes from the API key), but the CLI still hard-requires it and workspace switch is effectively a no-op — needs its own PR.
  • 0.5.1 add() validates a modern write receipt and can fail after a successful write against lagging self-hosted APIs — no CLI change for now.
  • Pre-existing: login --api-url is silently ignored (reads opts.baseUrl instead of opts.apiUrl) — being fixed in a separate session.

🤖 Generated with Claude Code

…emo to ^0.5.1

GET/PATCH/DELETE /v1/memories/:id 400 without a containerTag or
scopeType+scopeId query param (requireMemoryScope guard). The get and rm
commands sent neither, so both failed against production.

- add -C/--container to get and rm, resolved via the same
  resolveContainerTag precedence as add/search/list (flag > env > config)
- exit 2 with the existing container-required message when nothing resolves
- pass the env/config container into the Mnemo constructor as
  defaultContainerTag; per-call flag still wins
- bump getmnemo ^0.2.0 -> ^0.5.1 for the options parameter on
  get/update/delete
- tests assert the containerTag reaches the request query string
Independent review of the container-scope fix surfaced regressions the
getmnemo ^0.2.0 -> ^0.5.1 bump introduced beyond the by-id routes:

- login: the credential probe called list() with no container, which
  0.5.1 rejects client-side — login failed for every user. Probe with a
  synthetic read-only tag (cli:login-probe) instead.
- list: 0.5.1 list() throws without a container, so bare 'getmnemo list'
  died with a raw SDK error at exit 1. Gate it with the same
  container-required exit-2 message as the other commands.
- prod smoke: cleanup ran 'rm <id> --yes' with no --container (ids span
  two containers), leaking memories into the prod test workspace every
  CI run. Track id+container pairs and pass --container per delete.
- rm: 0.5.1 deletes are recoverable by default; surface the receipt
  (restorable-until in human output, receipt in --json) and add
  --permanent for an immediate purge.
- --json: container-required errors now emit {ok:false,error:
  "container_required"} instead of ANSI prose, matching the sibling
  error shapes.
- tests: exit-code assertions use rejects.toThrow (the try/catch form
  passed vacuously when nothing threw); realistic delete fixtures; new
  coverage for list, login probe, --json error shape, --permanent.
- dedupe the 5x-copied -C/--container option; fix stale comments;
  update README for the required-container contract.

Deferred (tracked in PR body): workspaceId is deprecated/ignored by SDK
0.5.1 but still a hard CLI gate; add() strict receipt validation vs
lagging self-hosted APIs.
@shhahhussain
shhahhussain merged commit e4c930b into main Aug 19, 2026
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