Skip to content

cli: run --archived no longer keeps the session archived #67310

Done

Description

@skycrazyk

Summary

opencode run --archived no longer keeps scripted sessions out of session lists: the run archives the session, then the prompt it sends immediately unarchives it. Regression introduced by #66348 (first shipped in v2.4.2). The flag was added in v2.2.6 (#61270) specifically for scripted/CI runs and is now a no-op.

Environment

  • opencode version: 2.4.3
  • Client: opencode run (non-interactive, scheduled via launchd; reproduces both with --standalone and against the shared background service)
  • Model and provider: Not relevant (any)
  • OS: macOS, Darwin 25.6.0 (arm64)
  • Terminal: Not relevant (headless scheduled run)
  • Shell: /bin/zsh
  • Install/channel: release (Homebrew opencode-v2)
  • Active plugins: None

Reproduction

  1. Run opencode run --archived --title "archived run test" "Reply with OK".
  2. After it finishes, list non-archived sessions: opencode api get '/api/session?search=archived%20run%20test&archived=false'.
  3. The session is returned, i.e. it is not archived. In the database, session_v2.time_archived is NULL.

Reproduces consistently, on every run.

Expected Behavior

Per the flag help ("Create the session archived so it stays out of session lists (useful for scripted or CI runs)") and the v2.2.6 release notes, the session should remain archived after the run and stay out of the TUI session list / /resume.

Actual Behavior

The session ends up unarchived and appears in /resume. An hourly scheduled agent run accumulated 70+ visible sessions in two weeks before this was noticed.

Additional Context

Root cause (verified in the v2.4.3 bundle):

  • runNonInteractive applies the flag before sending the prompt: it calls session.update({ sessionID, title, archived: true }) when --archived is set.
  • fix(server): unarchive a session when a person sends it input #66348 made POST /api/session/:id/prompt unarchive archived sessions (the endpoint description now says "An archived session is unarchived"). So the run's own prompt immediately undoes the archive.

#66348's description acknowledges the adjacent case ("any HTTP client counts as a person, so an external script that prompts through the API (for example opencode run --session … from a system cron) also unarchives. If that turns out to matter, a payload flag can opt out"), but the built-in --archived flag itself is now broken, which does not seem intended.

Workaround that works today: archive the session after the run completes via PATCH /api/session/{id} with {"archived": true}.

Possible fixes: apply the archived state after the run's execution completes, or have run --archived use the opt-out payload flag suggested in #66348.

Related: #66604 (archiving a running session via the API).

Activity

  1. added
    area/cli
    type/bug
    version/v2
    on Nov 30, 2026
  2. opencodejr commented on Nov 30, 2026

    @opencodejr
    Contributor

    Thanks for the detailed report and the root-cause analysis. I reproduced this on the released 2.4.3, with nothing faked.

    • opencode run --standalone --archived --title "archived run test" "Reply with OK" finishes normally. Afterwards, opencode api --standalone get '/api/session?search=…&archived=false' returns the session, it has no time.archived, and the archived=true query is empty.
    • With the same script on 2.4.1, the session stays archived, so this is a regression.
    • It still happens on the latest dev (ca4c03d). I ran it there against a server started from the checkout. The session ended up unarchived even though the model call failed, because the server unarchives as soon as it accepts the prompt.

    The script below reproduces it. Until there's a fix, your workaround of sending PATCH /api/session/{id} with {"archived": true} after the run should still keep these sessions out of the lists. Related: #66348, the change that made a prompt unarchive a session.

    Reproduction script (repro.sh)
    #!/bin/sh
    # Reproduces: `opencode run --archived` leaves the session unarchived.
    # Usage: sh repro.sh            (uses `opencode` from PATH)
    #        OC="bun ... packages/cli/src/index.ts" sh repro.sh   (from a checkout)
    set -e
    OC=${OC:-opencode}
    TMP=$(mktemp -d)
    export HOME="$TMP/home" XDG_DATA_HOME="$TMP/home/data" XDG_CONFIG_HOME="$TMP/home/cfg"
    mkdir -p "$HOME" "$TMP/proj"
    cd "$TMP/proj" && git init -q
    $OC --version
    TITLE="archived run test $$"
    $OC run --standalone --archived --title "$TITLE" "Reply with OK"
    Q=$(printf '%s' "$TITLE" | sed 's/ /%20/g')
    echo "--- non-archived sessions matching the title (expected: empty data) ---"
    $OC api --standalone get "/api/session?search=$Q&archived=false"
    echo
    echo "--- archived sessions matching the title (expected: the run's session) ---"
    $OC api --standalone get "/api/session?search=$Q&archived=true"
    echo

    Run it: sh repro.sh

  3. sakaintp commented on Nov 30, 2026

    @sakaintp

    I would like to take this issue. I found no open PR directly fixing run --archived; #66503 is a broader session archive-management feature. On current dev, runNonInteractive still archives before its first prompt, while the server unarchives on admitted prompt input. Could you assign this to me? I can keep the existing API unarchive behavior and have the run preserve its explicit archived state, with focused CLI regression coverage. Any Protocol/HttpApi change would follow the required generation workflow.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/cliplatform/macosreproducedstatus/regressiontype/bugversion/v2

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions