Skip to content

Plugin session.update ignores archived #61038

Done

Description

@LuckUVeryX

Description

The plugin API accepts archived in session.update, but the call succeeds without changing the session's archive state. The equivalent HTTP API call works.

I understand the archive is only used for the desktop and mobile apps at the moment, but I would like to expose it and set it via the plugin interface.

Plugins

No response

OpenCode version

2.2.5

Steps to reproduce

await ctx.session.update({
  sessionID,
  archived: true,
})

The session remains unarchived. Passing archived: false for an archived session also has no effect.

Screenshot

No response

Operating System

No response

Terminal

No response

Activity

  1. opencodejr commented on Nov 1, 2026

    @opencodejr
    Contributor

    Thanks for the clear report. I reproduced this on 2.2.5, and it still happens on the latest dev (69269e4).

    Steps: a plugin in .opencode/plugins/ creates a session, calls ctx.session.update({ sessionID, archived: true }), then reads the session back.

    • time.archived is still unset afterwards, and no error is raised.
    • A title update through the same ctx.session.update call does apply.
    • Archiving the same session through the HTTP API (PATCH /api/session/:sessionID with {"archived":true}) works.

    The script below reproduces it against a release or a source checkout.

    In the code, the plugin host's session.update (packages/core/src/plugin/host.ts) handles title, metadata and permissions, but has no archive/unarchive branch like the HTTP handler has. So archived: false is ignored too. I couldn't test that case from a plugin, because a plugin can't archive a session first.

    Related: #61036 (your fix PR, which was auto-closed because it didn't link an issue) and #51468 (an earlier case where plugin session.update dropped metadata).

    Reproduction script (repro.sh)
    #!/usr/bin/env bash
    # Reproduces #61038: plugin ctx.session.update({ archived }) is silently ignored.
    # Usage: bash repro.sh            -> uses `opencode` from PATH (e.g. @opencode/[email protected])
    #        OC_DEV=/path/to/repo bash repro.sh  -> runs the CLI from a source checkout
    set -euo pipefail
    
    WORK=$(mktemp -d /tmp/opencode/archive-repro.XXXX)
    PROJ=$WORK/proj
    mkdir -p "$PROJ/.opencode/plugins" "$WORK/home"
    export HOME=$WORK/home XDG_CONFIG_HOME=$WORK/home/c XDG_DATA_HOME=$WORK/home/d XDG_STATE_HOME=$WORK/home/s XDG_CACHE_HOME=$WORK/home/k
    export REPRO_OUT=$WORK/plugin.log
    
    if [ -n "${OC_DEV:-}" ]; then
      # Start a server from the checkout (its bunfig preload only applies inside the repo), then point the CLI at it.
      PORT=${PORT:-47123}
      export OPENCODE_PASSWORD=repro-password
      (cd "$OC_DEV/packages/cli" && bun --conditions=browser src/index.ts serve --port "$PORT" >"$WORK/server.log" 2>&1 &)
      for i in $(seq 1 60); do grep -q "server listening" "$WORK/server.log" >/dev/null 2>&1 && break; sleep 1; done
      oc() { bun --conditions=browser --preload="$OC_DEV/packages/tui/node_modules/@opentui/solid/scripts/preload.js" "$OC_DEV/packages/cli/src/index.ts" --server "http://127.0.0.1:$PORT" "$@"; }
      PLUGIN_VERSION=latest
    else
      oc() { opencode "$@"; }
      PLUGIN_VERSION=$(opencode --version | sed 's/^opencode v//')
    fi
    
    cd "$PROJ"
    git init -q
    cat > .opencode/plugins/archive-repro.ts <<'EOF'
    import { Plugin } from "@opencode/plugin"
    import { appendFileSync } from "node:fs"
    
    const log = (...a: unknown[]) =>
      appendFileSync(process.env.REPRO_OUT!, a.map((x) => (typeof x === "string" ? x : JSON.stringify(x))).join(" ") + "\n")
    
    export default Plugin.define({
      id: "archive-repro",
      setup: async (ctx) => {
        setTimeout(async () => {
          try {
            const s = await ctx.session.create()
            log("created", s.id, "time.archived =", (await ctx.session.get({ sessionID: s.id })).time.archived ?? null)
            await ctx.session.update({ sessionID: s.id, archived: true })
            log("after update({archived:true}) time.archived =", (await ctx.session.get({ sessionID: s.id })).time.archived ?? null)
            await ctx.session.update({ sessionID: s.id, title: "renamed-by-plugin" })
            log("after update({title}) title =", (await ctx.session.get({ sessionID: s.id })).title)
          } catch (e) {
            log("error", String(e))
          }
        }, 500)
      },
    })
    EOF
    bun add -d "@opencode/plugin@$PLUGIN_VERSION" >/dev/null 2>&1
    
    # Any request for this directory loads the project's plugins; retry until the plugin has logged.
    for i in $(seq 1 20); do
      oc session list >/dev/null 2>&1 || true
      sleep 3
      grep -q "after update({title})\|error" "$REPRO_OUT" 2>/dev/null && break
    done
    cat "$REPRO_OUT"
    if [ -n "${OC_DEV:-}" ]; then pkill -f "src/index.ts serve --port $PORT" || true; else oc service stop >/dev/null 2>&1 || true; fi

    Run it: bash repro.sh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions