Skip to content

The ctx_memory tool definition visible to the LLM does not match the source code definition #249

Description

@zllzmcdcr

Short description

The ctx_memory tool definition visible to the LLM does not match the source code definition, causing frequent calling failures and infinite retry loops (especially with models like GLM 5.2).

What happened?

Description

The ctx_memory tool definition visible to the LLM does not match the source code definition, causing frequent calling failures and infinite retry loops (especially with models like GLM 5.2).

Environment

  • Magic Context version: 0.32.0 (confirmed issue also present in v0.33.0 source via src/tools/ctx-memory/tools.ts)
  • OpenCode: latest

Root Cause: 3 discrepancies between source and LLM-facing definition

1. Action enum mismatch

  • Source constants.ts: "Supported actions: write, delete, list, update, merge, archive" (6 actions)
  • LLM sees: enum: ["write", "archive", "update", "merge", "list"] (5 actions — delete missing, archive incorrectly renamed)
  • If LLM calls action="archive", the backend handler expects action="delete" → fails

2. Missing id parameter (critical)

  • Source tools.ts defines BOTH id: number and ids: number[]:
    • id → used for delete/update/archive actions
    • ids → used only for merge
  • LLM sees only ids: number[] (described as "required for update/archive/merge")
  • LLM passes ids: [42] for update → backend checks args.id (undefined) → "Error: 'id' is required"

3. Incomplete category description

  • Source: "required for write, optional filter for list, optional override for merge"
  • LLM: "required for write; optional merge override" (missing "filter for list")

Impact

  • Any operation other than write and list is guaranteed to fail
  • GLM 5.2 entered an infinite retry loop (repeatedly calling with wrong params), wasting tokens
  • Other frontier models also retry with slightly different params, getting the same error

Likely Cause

The opencode tool definition serialization layer appears to be merging id and ids parameters and remapping deletearchive. The source code in src/tools/ctx-memory/tools.ts defines both parameters correctly.

Steps to Reproduce

  1. Ask any LLM to update or delete an existing memory
  2. LLM calls ctx_memory(action="update", ids=[42], content="new content")
  3. Backend returns "Error: 'id' is required"
  4. LLM retries with different params, same error

Diagnostics

Plugin version

0.32.0

OpenCode version

1.18.5

Platform

windows 64

Client

OpenCode TUI (CLI)

Log output (optional)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions