Skip to content

AI Cleanup never succeeds with opencodeProvider #177

Description

@cristeaadrian

Summary

AI Cleanup (POST /api/user-profile/ai-cleanup) never succeeds with opencodeProvider/opencodeModel (no external memoryApiUrl). Every failure surfaces as Error: No AI provider configured for profile cleanup even though the provider is configured and working (auto-capture and profile learning use it fine), because callAICleanup catches any error from the opencode path and falls through to the unset memoryModel/memoryApiUrl branch.

Five stacked bugs, each hidden behind the next. Four are in callViaOpencodeWithClient (ai-cleanup.js), one is in the web UI (web/app.js):

  1. noReply: true on the session.prompt call suppresses assistant generation, so no response is produced. The working auto-capture path avoids noReply for this reason. Set it to false.
  2. Reads a nonexistent field. The prompt response is { info: AssistantMessage, parts: Array<Part> }, and AssistantMessage has no text field (per SDK types). Reading info.text yields undefined, then "AI response did not contain valid JSON". Read the text from promptResult.data.parts filtered by type === "text", as the rest of the codebase does.
  3. Server timeout too short. The session.prompt race uses TIMEOUT_MS = 120000, but a real cleanup on a sizable profile takes longer, so it aborts. Raise it.
  4. Client default timeout too short. fetchAPI in web/app.js defaults the /ai-cleanup fetch to 180000ms.
  5. Explicit client timeout overrides the default. The cleanup call passes an explicit timeout: 180000, which wins over the fetchAPI default via options.timeout || .... This is the one that actually keeps hanging the modal: the browser aborts before the server responds, so the loading spinner never clears even though the server completed. Raise this explicit value too.

Repro

  1. Configure opencodeProvider + opencodeModel, no external memory API.
  2. Confirm auto-capture / profile learning work.
  3. Web UI, click "AI Cleanup".
  4. Fails or hangs; log chain: prompt timeout, then AI response did not contain valid JSON, then No AI provider configured.

Verified: with all five fixes applied, cleanup completes and the diff renders for review/apply.

Environment

  • opencode-mem v2.19.4, OpenCode v1.18.3, macOS
  • opencodeProvider: amazon-bedrock, opencodeModel: global.anthropic.claude-sonnet-5, no external memory API

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions