Skip to content

fix(discovery): read OpenCode 2 stores and exclude backpass sessions - #176

Closed
PawanAIT wants to merge 10 commits into
kunchenguid:mainfrom
PawanAIT:pawan/opencode-v2
Closed

PawanAIT wants to merge 10 commits into
kunchenguid:mainfrom
PawanAIT:pawan/opencode-v2

Conversation

@PawanAIT

@PawanAIT PawanAIT commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Intent

Stacked on #174 (backpass own OpenCode sessions). OpenCode 2 no longer writes the session, message and part tables; its store keeps sessions in session_v2 and the whole history as one typed row per message in session_message, so on an OpenCode 2 store the opencode adapter failed with no such table: session and every session was skipped. Read both layouts from one database: list session_v2 dated by its newest message (session_v2.time_updated does not move), read a session found in both layouts from session_v2 after an in-place upgrade, report a store with neither table as drifted, and map each 2.x message type deliberately (user and assistant turns, tool calls in order with text output or error, background subagent and shell completions as the result of the call that started them, user shell commands and skills as calls; instruction files, continue notices, system notices and compaction summaries never become turns). Apply the same self-session, delegated-descendant and empty-session rules as 1.x. Pin both layouts with golden fixtures built from the real 2.0.18 and 1.18.32 DDL.

What Changed

  • Read OpenCode 1.x and 2.x layouts together, prefer upgraded sessions in session_v2, use newest-message activity for discovery, and report unrecognized stores.
  • Normalize 2.x turns and ordered tool calls, attach background completions to their originating calls, and omit injected notices and compaction summaries.
  • Exclude backpass sessions, delegated descendants, and empty probes from local and remote discovery while retaining attachment-only conversations; document the behavior and add golden fixtures based on OpenCode 1.18.32 and 2.0.18 schemas.

Risk Assessment

✅ Low: The change is limited to one read-only discovery adapter and meets every intent requirement: both layouts, dating by newest message, v2 preferred for upgraded sessions, drift reporting, deliberate message-type mapping, the same self, descendant and empty-session rules, and golden fixtures; the only findings are an unrequired fallback and minor cleanups.

Testing

Focused OpenCode tests and all seven live scenarios passed after correcting a disposable database-builder setup error; baseline reproduction, CLI transcripts, and fetched protocol payloads were saved, and temporary data was removed. No graphical UI changed, so evidence is CLI/protocol output rather than screenshots.

  • Live validation: ✅ go - 7 of 7 scenarios driven live against the product
Scenario Result Live Evidence
Scan an OpenCode 2 store without legacy session tables ✅ pass live baseline-v2.txt, v2-scan.txt, and v2-probe.json, linked from the validation report.
Read ordered OpenCode 2 turns and calls without injected harness text ✅ pass live v2-parent-trace.json and v2-parent-trace.frames.
Find a recently resumed session whose session timestamps remain old ✅ pass live v2-recency.txt and v2-recency-probe.json.
Continue scanning and reading OpenCode 1.x stores ✅ pass live v1-scan.txt, v1-probe.json, and v1-trace.json.
Prefer current v2 history after an in-place upgrade while retaining v1-only sessions ✅ pass live upgraded-scan.txt, upgraded-probe.json, and upgraded-traces.json.
Exclude self sessions, delegated descendants, and empty probes without false positives ✅ pass live guards-v1-1d.txt, guards-v2-1d.txt, guards-v2-all.txt, and corresponding probe/fetch artifacts.
Report an unrecognized store as drifted rather than silently empty ✅ pass live drift-human.txt, drift-scan.json, and drift-probe.json.
Evidence: Validation report with linked product evidence
# OpenCode store compatibility: live validation

Target: `12e6d91a45ed4f5333320a102e66990a6f68294f`.
Baseline: `ddf8a7b06a9d191ee696d2ae9a10683c8b1ca872`.

## Method

The real `bin/backpass.js scan` command ran in disposable Git repositories with isolated HOME, XDG configuration/data, and TMPDIR under the worktree.
SQLite databases were materialized from the checked-in OpenCode 1.18.32 and 2.0.18 golden DDL and populated with synthetic conversation data.
The production shipped probe ran through its stdin loader in separate Node processes, first discovering sessions and then fetching their normalized transcript payloads over its real framed protocol.
No adapter, CLI, or probe was mocked.
No model calls, operator data, shared services, or SSH connections were used.
SSH transport and downstream model analysis are outside this adapter change's tested surface.

## Product evidence

| Scenario | Observable result | Product artifacts |
| --- | --- | --- |
| OpenCode 2 scan | Baseline skips every session with `no such table: session`; target returns the three genuine sessions, excluding two self sessions and the empty probe. | [Baseline CLI](baseline-v2.txt), [target CLI](v2-scan.txt), [probe response](v2-probe.json) |
| Typed transcript ingestion | The fetched parent contains 13 ordered events: user/assistant turns, text tool outputs, an edit error, background subagent completion, background shell failure, and user shell/skill calls. Instruction files, continue notices, system notices, compaction, skill bodies, reasoning, and image payloads do not become turns. Rows were physically inserted in reverse order to challenge chronological reconstruction. | [Decoded payload](v2-parent-trace.json), [raw protocol frames](v2-parent-trace.frames) |
| Recent resumed session | `scan --since 1d` includes only the resumed session, whose session timestamps are ten days old but whose newest message is recent. | [CLI](v2-recency.txt), [probe](v2-recency-probe.json) |
| OpenCode 1 compatibility | The 1.x session is discovered and fetched despite its empty forward-looking `session_message` table; user/assistant text and `bash` output survive. | [CLI](v1-scan.txt), [fetched payload](v1-trace.json) |
| In-place upgrade | A populated stale 1.x copy loses to its 2.x counterpart, which appears only once with current title and full history; a separate 1.x-only session remains available. | [CLI](upgraded-scan.txt), [probe descriptors](upgraded-probe.json), [all fetched histories](upgraded-traces.json) |
| Self-session and empty-session boundaries | Both layouts exclude self sessions and recent children/grandchildren through old empty intermediates, even with a recent-only cutoff. Empty probes never appear. Attachment-only openings followed by sentinel quotes, literal sentinel mentions, genuine descendants, malformed rows with valid later text, orphans, and non-self ancestry cycles remain readable. Repeated CLI scans produce the same membership. | [1.x recent CLI](guards-v1-1d.txt), [2.x recent CLI](guards-v2-1d.txt), [2.x all-time CLI](guards-v2-all.txt), [2.x recent probe](guards-v2-1d-probe.json), [2.x fetched histories](guards-v2-1d-traces.json) |
| Schema drift | A database containing only an unrelated table produces an explicit named unreadable-store warning in human-readable CLI output, JSON, and probe output; the CLI remains fail-soft. | [Human CLI](drift-human.txt), [JSON CLI](drift-scan.json), [probe](drift-probe.json) |

## Commands and outcome

Targeted existing tests:

`` `sh
HOME="$PWD/.opencode-validation/test-home" XDG_CONFIG_HOME="$PWD/.opencode-validation/test-home/.config" TMPDIR="$PWD/.opencode-validation/tmp" GIT_CONFIG_NOSYSTEM=1 GIT_CONFIG_GLOBAL=/dev/null node --test --test-name-pattern='[Oo]pen[Cc]ode' test/adapters.test.js test/self-session.test.js
`` `

The focused OpenCode tests passed.
The complete repository suite, linters, formatters, static analysis, and other gate phases were not run.

Baseline preparation and live driver:

`` `sh
mkdir -p .opencode-validation/base .opencode-validation/tmp .opencode-validation/test-home
git archive ddf8a7b06a9d191ee696d2ae9a10683c8b1ca872 src bin package.json | tar -x -C .opencode-validation/base
node ~/.no-mistakes/evidence/01M3PBHV5RSAV96NQ138KWHJFA/opencode-live.mjs
`` `

The first live run encountered a disposable-builder error while creating the mixed-layout database: its DDL exclusion check incorrectly matched foreign-key references.
The driver was corrected to exclude tables by DDL ownership, then every live scenario was rerun successfully.
There were no product failures on the target and no source changes.
The disposable worktree data was removed after validation; this evidence directory is retained.
This is a CLI and transcript-ingestion change, not a graphical UI change, so evidence consists of actual CLI output and protocol payloads rather than screenshots.

The [driver](opencode-live.mjs) records the exact data mutations and behavioral assertions.
The [execution context](execution-context.json) records runtime and revision details.
Evidence: Baseline OpenCode 2 failure
$ HOME=<isolated v2> node <base>/bin/backpass.js scan --harness opencode --host none --since all --strict --json
exit: 0
stdout:
{
  "repo": "repo",
  "scope": "project",
  "perHarness": {
    "opencode": {
      "scanned": 0,
      "matched": 0,
      "cached": 0,
      "skipped": 0,
      "self": 0,
      "error": "no such table: session"
    }
  },
  "perHost": [],
  "mix": {
    "interactive": 0,
    "nonInteractive": 0,
    "total": 0
  },
  "transcripts": []
}

stderr:
warn opencode: transcript store unreadable (no such table: session) - harness skipped
Evidence: Successful OpenCode 2 CLI scan
$ HOME=<isolated v2> node bin/backpass.js scan --harness opencode --host none --since all --strict --json
exit: 0
stdout:
{
  "repo": "repo",
  "scope": "project",
  "perHarness": {
    "opencode": {
      "scanned": 5,
      "matched": 3,
      "cached": 0,
      "skipped": 0,
      "self": 2,
      "error": null
    }
  },
  "perHost": [],
  "mix": {
    "interactive": 0,
    "nonInteractive": 3,
    "total": 3
  },
  "transcripts": [
    {
      "harness": "opencode",
      "id": "opencode-ses_f0a1b2c3dffeResumedSession01",
      "nativeId": "ses_f0a1b2c3dffeResumedSession01",
      "path": "~/.no-mistakes/worktrees/9ce30939faf7/01M3PBHV5RSAV96NQ138KWHJFA/.opencode-validation/v2/home/.local/share/opencode/opencode.db",
      "cwd": "~/.no-mistakes/worktrees/9ce30939faf7/01M3PBHV5RSAV96NQ138KWHJFA/.opencode-validation/v2/repo",
      "gitBranch": null,
      "title": "Release checklist",
      "model": null,
      "startedAt": 1780000000000,
      "mtimeMs": 1790600200000,
      "bytes": 0,
      "contentSignature": null,
      "experimental": false,
      "association": {
        "tier": 1,
        "confidence": "exact",
        "reason": "cwd is worktree ~/.no-mistakes/worktrees/9ce30939faf7/01M3PBHV5RSAV96NQ138KWHJFA/.opencode-validation/v2/repo",
        "project": "~/.no-mistakes/worktrees/9ce30939faf7/01M3PBHV5RSAV96NQ138KWHJFA/.opencode-validation/v2/repo",
        "projectRoot": "~/.no-mistakes/worktrees/9ce30939faf7/01M3PBHV5RSAV96NQ138KWHJFA/.opencode-validation/v2/repo"
      },
      "extra": {
        "sessionId": "ses_f0a1b2c3dffeResumedSession01",
        "layout": "v2"
      },
      "interactionSignals": {},
      "project": "~/.no-mistakes/worktrees/9ce30939faf7/01M3PBHV5RSAV96NQ138KWHJFA/.opencode-validation/v2/repo",
      "projectRoot": "~/.no-mistakes/worktrees/9ce30939faf7/01M3PBHV5RSAV96NQ138KWHJFA/.opencode-validation/v2/repo",
      "host": null,
      "identity": "0e1a4a15f1a1094cbc19c94cc8901dd0f4c9ef415a0fb29ee8afabb7df223e34",
      "interaction": "non-interactive"
    },
    {
      "harness": "opencode",
      "id": "opencode-ses_f17ca477affeM7vJpYuwLTunDK",
      "nativeId": "ses_f17ca477affeM7vJpYuwLTunDK",
      "path": "~/.no-mistakes/worktrees/9ce30939faf7/01M3PBHV5RSAV96NQ138KWHJFA/.opencode-validation/v2/home/.local/share/opencode/opencode.db",
      "cwd": "~/.no-mistakes/worktrees/9ce30939faf7/01M3PBHV5RSAV96NQ138KWHJFA/.opencode-validation/v2/repo",
      "gitBranch": null,
      "title": "Parser fix",
      "model": null,
      "startedAt": 1790600000000,
      "mtimeMs": 1790600020800,
      "bytes": 0,
      "contentSignature": null,
      "experimental": false,
      "association": {
        "tier": 1,
        "confidence": "exact",
        "reason": "cwd is worktree ~/.no-mistakes/worktrees/9ce30939faf7/01M3PBHV5RSAV96NQ138KWHJFA/.opencode-validation/v2/repo",
        "project": "~/.no-mistakes/worktrees/9ce30939faf7/01M3PBHV5RSAV96NQ138KWHJFA/.opencode-validation/v2/repo",
        "projectRoot": "~/.no-mistakes/worktrees/9ce30939faf7/01M3PBHV5RSAV96NQ138KWHJFA/.opencode-validation/v2/repo"
      },
      "extra": {
        "sessionId": "ses_f17ca477affeM7vJpYuwLTunDK",
        "layout": "v2"
      },
      "interactionSignals": {},
      "project": "~/.no-mistakes/worktrees/9ce30939faf7/01M3PBHV5RSAV96NQ138KWHJFA/.opencode-validation/v2/repo",
      "projectRoot": "~/.no-mistakes/worktrees/9ce30939faf7/01M3PBHV5RSAV96NQ138KWHJFA/.opencode-validation/v2/repo",
      "host": null,
      "identity": "3f68412a46512b813823d4055233f699b817a4bc162ceae14b615539ed593d20",
      "interaction": "non-interactive"
    },
    {
      "harness": "opencode",
      "id": "opencode-ses_f17c42540ffeM0ZIydCm19byyr",
      "nativeId": "ses_f17c42540ffeM0ZIydCm19byyr",
      "path": "~/.no-mistakes/worktrees/9ce30939faf7/01M3PBHV5RSAV96NQ138KWHJFA/.opencode-validation/v2/home/.local/share/opencode/opencode.db",
      "cwd": "~/.no-mistakes/worktrees/9ce30939faf7/01M3PBHV5RSAV96NQ138KWHJFA/.opencode-validation/v2/repo",
      "gitBranch": null,
      "title": "Review the parser fix",
      "model": null,
      "startedAt": 1790600003000,
      "mtimeMs": 1790600008900,
      "bytes": 0,
      "contentSignature": null,
      "experimental": false,
      "association": {
        "tier": 1,
        "confidence": "exact",
        "reason": "cwd is worktree ~/.no-mistakes/worktrees/9ce30939faf7/01M3PBHV5RSAV96NQ138KWHJFA/.opencode-validation/v2/repo",
        "project": "~/.no-mistakes/worktrees/9ce30939faf7/01M3PBHV5RSAV96NQ138KWHJFA/.opencode-validation/v2/repo",
        "projectRoot": "~/.no-mistakes/worktrees/9ce30939faf7/01M3PBHV5RSAV96NQ138KWHJFA/.opencode-validation/v2/repo"
      },
      "extra": {
        "sessionId": "ses_f17c42540ffeM0ZIydCm19byyr",
        "layout": "v2"
      },
      "interactionSignals": {
        "parentId": "ses_f17ca477affeM7vJpYuwLTunDK"
      },
      "project": "~/.no-mistakes/worktrees/9ce30939faf7/01M3PBHV5RSAV96NQ138KWHJFA/.opencode-validation/v2/repo",
      "projectRoot": "~/.no-mistakes/worktrees/9ce30939faf7/01M3PBHV5RSAV96NQ138KWHJFA/.opencode-validation/v2/repo",
      "host": null,
      "identity": "6c95950ba1b3942ac3bfd55ecfbb6c5493c7c1ab943f48ddf3548686c597a659",
      "interaction": "non-interactive"
    }
  ]
}

stderr:
Evidence: Fetched OpenCode 2 turns and tool results
[
  {
    "header": {
      "key": "opencode:ses_f17ca477affeM7vJpYuwLTunDK",
      "harness": "opencode",
      "kind": "events",
      "bytes": 2166,
      "mtimeMs": 1790600020800,
      "contentSignature": "2c23943be6cfed7e001f512a9573fd2ebc0a3daf95d91f772240c9641cfa58e9",
      "model": "claude-opus-5.5"
    },
    "events": [
      {
        "kind": "message",
        "role": "user",
        "text": "Open a PR for the parser fix."
      },
      {
        "kind": "message",
        "role": "assistant",
        "text": "I'll run the tests first."
      },
      {
        "kind": "tool",
        "name": "shell",
        "input": {
          "command": "npm test",
          "workdir": "~/.no-mistakes/worktrees/9ce30939faf7/01M3PBHV5RSAV96NQ138KWHJFA/.opencode-validation/v2/repo"
        },
        "result": "2 passing",
        "status": "completed"
      },
      {
        "kind": "tool",
        "name": "read",
        "input": {
          "path": "~/.no-mistakes/worktrees/9ce30939faf7/01M3PBHV5RSAV96NQ138KWHJFA/.opencode-validation/v2/repo/src/parser.ts"
        },
        "result": "Read file ~/.no-mistakes/worktrees/9ce30939faf7/01M3PBHV5RSAV96NQ138KWHJFA/.opencode-validation/v2/repo/src/parser.ts, lines 1-1\n1: export function parse() {}",
        "status": "completed"
      },
      {
        "kind": "tool",
        "name": "subagent",
        "input": {
          "agent": "general",
          "description": "Review the parser fix",
          "background": true,
          "prompt": "You are a subagent spawned by another session.\nReview src/parser.ts."
        },
        "result": "<subagent sessionID=\"ses_f17c42540ffeM0ZIydCm19byyr\" state=\"completed\" description=\"Review the parser fix\">\nNo blocking findings.\n</subagent>",
        "status": "completed"
      },
      {
        "kind": "message",
        "role": "assistant",
        "text": "Opened PR #2731."
      },
      {
        "kind": "tool",
        "name": "edit",
        "input": {
          "path": "~/.no-mistakes/worktrees/9ce30939faf7/01M3PBHV5RSAV96NQ138KWHJFA/.opencode-validation/v2/repo/CHANGELOG.md",
          "oldString": "## Unreleased",
          "newString": "## 1.2.0"
        },
        "result": "oldString not found in content",
        "status": "error"
      },
      {
        "kind": "tool",
        "name": "shell",
        "input": {
          "command": "git status --short"
        },
        "result": "nothing to commit",
        "status": "completed"
      },
      {
        "kind": "tool",
        "name": "skill",
        "input": {
          "name": "release"
        },
        "status": "completed"
      },
      {
        "kind": "message",
        "role": "user",
        "text": "Thanks, ship it."
      },
      {
        "kind": "message",
        "role": "assistant",
        "text": "Building the release."
      },
      {
        "kind": "tool",
        "name": "shell",
        "input": {
          "command": "npm run build",
          "background": true
        },
        "result": "<shell id=\"sh_0e84aacd7001hD1EEplKBz5KVr\" state=\"error\" command=\"npm run build\">\nbuild failed: missing dist/\n</shell>",
        "status": "error"
      },
      {
        "kind": "message",
        "role": "assistant",
        "text": "The build failed; I will fix dist/ first."
      }
    ],
    "model": "claude-opus-5.5"
  }
]
Evidence: Fetched histories from the upgraded mixed-layout store
[
  {
    "header": {
      "key": "opencode:ses_f0a1b2c3dffeResumedSession01",
      "harness": "opencode",
      "kind": "events",
      "bytes": 184,
      "mtimeMs": 1790600200000,
      "contentSignature": "118d1c0ab375817acda1d5e52dbdf785836befb7f0be1a6d36f65644fb5399ea",
      "model": null
    },
    "events": [
      {
        "kind": "message",
        "role": "user",
        "text": "Draft the release checklist."
      },
      {
        "kind": "message",
        "role": "user",
        "text": "Picking this up again: add the rollback step."
      }
    ],
    "model": null
  },
  {
    "header": {
      "key": "opencode:ses_f17c42540ffeM0ZIydCm19byyr",
      "harness": "opencode",
      "kind": "events",
      "bytes": 219,
      "mtimeMs": 1790600008900,
      "contentSignature": "9f5710feac25cd2d4e48c0626a62ff8e9d70f7bf5c52b0a081e558c57c782173",
      "model": "claude-opus-5.5"
    },
    "events": [
      {
        "kind": "message",
        "role": "user",
        "text": "You are a subagent spawned by another session.\nReview src/parser.ts."
      },
      {
        "kind": "message",
        "role": "assistant",
        "text": "No blocking findings."
      }
    ],
    "model": "claude-opus-5.5"
  },
  {
    "header": {
      "key": "opencode:ses_f17ca477affeM7vJpYuwLTunDK",
      "harness": "opencode",
      "kind": "events",
      "bytes": 2190,
      "mtimeMs": 1790600020800,
      "contentSignature": "cad31ccd85dca06b629c8865d105f89ab379bb5ff4d5baf7ee91b50d90e96c86",
      "model": "claude-opus-5.5"
    },
    "events": [
      {
        "kind": "message",
        "role": "user",
        "text": "Open a PR for the parser fix."
      },
      {
        "kind": "message",
        "role": "assistant",
        "text": "I'll run the tests first."
      },
      {
        "kind": "tool",
        "name": "shell",
        "input": {
          "command": "npm test",
          "workdir": "~/.no-mistakes/worktrees/9ce30939faf7/01M3PBHV5RSAV96NQ138KWHJFA/.opencode-validation/upgraded/repo"
        },
        "result": "2 passing",
        "status": "completed"
      },
      {
        "kind": "tool",
        "name": "read",
        "input": {
          "path": "~/.no-mistakes/worktrees/9ce30939faf7/01M3PBHV5RSAV96NQ138KWHJFA/.opencode-validation/upgraded/repo/src/parser.ts"
        },
        "result": "Read file ~/.no-mistakes/worktrees/9ce30939faf7/01M3PBHV5RSAV96NQ138KWHJFA/.opencode-validation/upgraded/repo/src/parser.ts, lines 1-1\n1: export function parse() {}",
        "status": "completed"
      },
      {
        "kind": "tool",
        "name": "subagent",
        "input": {
          "agent": "general",
          "description": "Review the parser fix",
          "background": true,
          "prompt": "You are a subagent spawned by another session.\nReview src/parser.ts."
        },
        "result": "<subagent sessionID=\"ses_f17c42540ffeM0ZIydCm19byyr\" state=\"completed\" description=\"Review the parser fix\">\nNo blocking findings.\n</subagent>",
        "status": "completed"
      },
      {
        "kind": "message",
        "role": "assistant",
        "text": "Opened PR #2731."
      },
      {
        "kind": "tool",
        "name": "edit",
        "input": {
          "path": "~/.no-mistakes/worktrees/9ce30939faf7/01M3PBHV5RSAV96NQ138KWHJFA/.opencode-validation/upgraded/repo/CHANGELOG.md",
          "oldString": "## Unreleased",
          "newString": "## 1.2.0"
        },
        "result": "oldString not found in content",
        "status": "error"
      },
      {
        "kind": "tool",
        "name": "shell",
        "input": {
          "command": "git status --short"
        },
        "result": "nothing to commit",
        "status": "completed"
      },
      {
        "kind": "tool",
        "name": "skill",
        "input": {
          "name": "release"
        },
        "status": "completed"
      },
      {
        "kind": "message",
        "role": "user",
        "text": "Thanks, ship it."
      },
      {
        "kind": "message",
        "role": "assistant",
        "text": "Building the release."
      },
      {
        "kind": "tool",
        "name": "shell",
        "input": {
          "command": "npm run build",
          "background": true
        },
        "result": "<shell id=\"sh_0e84aacd7001hD1EEplKBz5KVr\" state=\"error\" command=\"npm run build\">\nbuild failed: missing dist/\n</shell>",
        "status": "error"
      },
      {
        "kind": "message",
        "role": "assistant",
        "text": "The build failed; I will fix dist/ first."
      }
    ],
    "model": "claude-opus-5.5"
  },
  {
    "header": {
      "key": "opencode:ses_f16e2d036ffeZd4lFcWRZCBMYV",
      "harness": "opencode",
      "kind": "events",
      "bytes": 476,
      "mtimeMs": 1790605324420,
      "contentSignature": "cb941a45f0ff80ecbcf28a141ea7aeee8d501f68751b5a7f228978c43ab2ea74",
      "model": "gpt-5.6-terra"
    },
    "events": [
      {
        "kind": "message",
        "role": "user",
        "text": "Open a PR for the parser fix."
      },
      {
        "kind": "tool",
        "name": "bash",
        "input": {
          "command": "npm test",
          "workdir": "~/.no-mistakes/worktrees/9ce30939faf7/01M3PBHV5RSAV96NQ138KWHJFA/.opencode-validation/upgraded/repo"
        },
        "result": "2 passing\n",
        "status": "completed"
      },
      {
        "kind": "message",
        "role": "assistant",
        "text": "I'll run the tests first."
      },
      {
        "kind": "message",
        "role": "assistant",
        "text": "Opened PR #2731."
      }
    ],
    "model": "gpt-5.6-terra"
  }
]
  • Evidence: Recent-only scan with adversarial self-session boundaries (local file: ~/.no-mistakes/evidence/01M3PBHV5RSAV96NQ138KWHJFA/guards-v2-1d.txt)
Evidence: Human-readable schema-drift warning
$ HOME=<isolated drift> node bin/backpass.js scan --harness opencode --host none --since all --strict
exit: 0
stdout:
repo · 1 worktree(s) · since all

HOST   HARNESS   SCANNED  MATCHED  SELF  CACHED  NOTE
local  opencode  0        0        0     0       unreadable: no session or session_v2 table (unrecognised opencode store)

0 transcript(s) associated with this repo · tier1 0 (exact) · tier1.5 0 (sibling clone) · tier2 0 (remote) · tier3 0 (best-effort) · interactive 0 · non-interactive 0

HOST  HARNESS  SESSION  KIND  WHEN  SIZE  TIER  HOW

stderr:
warn opencode: transcript store unreadable (no session or session_v2 table (unrecognised opencode store)) - harness skipped

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

⚠️ **Review** - 5 issues (3 warnings, 2 infos)
  • ⚠️ src/discovery/adapters/opencode.js:218 - The fallback in layoutOf accepts a ref without extra.layout and looks up session_v2 to choose a layout. Nothing in the product produces such a ref. Local discovery (sessionRow) and remote discovery always attach extra.layout. The remote probe also sends it: descriptorFrom and fetchHost in src/discovery/remote/probe.js and src/discovery/hosts.js pass it through row.extra. No persisted state stores OpenCode refs across releases. The only callers that pass a bare { id } are tests (test/adapters.test.js 'a ref recorded before the layout was' and test/self-session.test.js read({ id })). The intent does not require reading layout-less refs. Suggested fix: remove the lookup and treat a missing layout as v1, the only layout that existed before this change. Update the v2 test to read through a discovered row.
  • ℹ️ src/discovery/adapters/opencode.js:167 - In listV2, recorded (an EXISTS subquery) always equals message_time IS NOT NULL, because MAX(time_updated) over the same rows is NULL exactly when there are none. Deriving recorded from message_time removes one correlated subquery per session on every discovery, and behavior stays the same.
  • ℹ️ test/adapters.test.js:843 - withOpencodeHome creates a temp HOME with mkdtempSync and never deletes it, so each run of the five new OpenCode tests leaves a directory in the system temp dir. Also, when HOME was originally unset, the restore sets process.env.HOME to the string "undefined" instead of deleting it. Fix: in the finally, call fs.rmSync(homeDir, { recursive: true, force: true }) and delete HOME when previous is undefined.

🔧 Fix applied.
5 issues (3 warnings, 2 infos) still open:

  • ⚠️ src/discovery/adapters/opencode.js:218 - The fallback in layoutOf accepts a ref without extra.layout and looks up session_v2 to choose a layout. Nothing in the product produces such a ref. Local discovery (sessionRow) and remote discovery always attach extra.layout. The remote probe also sends it: descriptorFrom and fetchHost in src/discovery/remote/probe.js and src/discovery/hosts.js pass it through row.extra. No persisted state stores OpenCode refs across releases. The only callers that pass a bare { id } are tests (test/adapters.test.js 'a ref recorded before the layout was' and test/self-session.test.js read({ id })). The intent does not require reading layout-less refs. Suggested fix: remove the lookup and treat a missing layout as v1, the only layout that existed before this change. Update the v2 test to read through a discovered row.
  • ℹ️ src/discovery/adapters/opencode.js:167 - In listV2, recorded (an EXISTS subquery) always equals message_time IS NOT NULL, because MAX(time_updated) over the same rows is NULL exactly when there are none. Deriving recorded from message_time removes one correlated subquery per session on every discovery, and behavior stays the same.
  • ℹ️ test/adapters.test.js:843 - withOpencodeHome creates a temp HOME with mkdtempSync and never deletes it, so each run of the five new OpenCode tests leaves a directory in the system temp dir. Also, when HOME was originally unset, the restore sets process.env.HOME to the string "undefined" instead of deleting it. Fix: in the finally, call fs.rmSync(homeDir, { recursive: true, force: true }) and delete HOME when previous is undefined.
  • ⚠️ src/discovery/adapters/opencode.js:219 - This is the Round 1 finding. It was left unselected and is still present. layoutOf accepts a ref that has no extra.layout, then looks the id up in session_v2 to choose a layout. Nothing in the product produces such a ref. Local discovery always attaches extra.layout (sessionRow, line 196). Remote discovery does too, because descriptorFrom in src/discovery/remote/probe.js reads the discovered row. No persisted state keeps OpenCode refs across releases. The only callers that pass a bare { id } are tests: test/adapters.test.js ('a ref recorded before the layout was is looked up the same way') and test/self-session.test.js (read({ id })). No requirement in the intent needs layout-less refs to be read. Recommended remedy: remove the lookup and treat a missing layout as v1, the only layout that existed before this change. Change the v2 test to read through a discovered row.
  • ⚠️ test/adapters.test.js:858 - The Round 1 fix round (commit 12e6d91) added a 30-line test, 'opencode test homes are removed and HOME restored on success and failure'. It tests the test helper withOpencodeHome, not product behavior. The finding it addressed (test-home-tempdir-leak) only asked for fs.rmSync of the temp home and for deleting HOME when it was originally unset. The helper change at lines 843-857 already does both. The meta-test goes beyond that finding and beyond the intent. It also mutates process.env.HOME across six iterations, which adds fragility to the shared test file. Recommended remedy: keep the minimal helper fix and remove the meta-test.
✅ **Test** - passed

✅ No issues found.

  • Live validation: ✅ go - 7 of 7 scenarios driven live against the product
Scenario Result Live Evidence
Scan an OpenCode 2 store without legacy session tables ✅ pass live baseline-v2.txt, v2-scan.txt, and v2-probe.json, linked from the validation report.
Read ordered OpenCode 2 turns and calls without injected harness text ✅ pass live v2-parent-trace.json and v2-parent-trace.frames.
Find a recently resumed session whose session timestamps remain old ✅ pass live v2-recency.txt and v2-recency-probe.json.
Continue scanning and reading OpenCode 1.x stores ✅ pass live v1-scan.txt, v1-probe.json, and v1-trace.json.
Prefer current v2 history after an in-place upgrade while retaining v1-only sessions ✅ pass live upgraded-scan.txt, upgraded-probe.json, and upgraded-traces.json.
Exclude self sessions, delegated descendants, and empty probes without false positives ✅ pass live guards-v1-1d.txt, guards-v2-1d.txt, guards-v2-all.txt, and corresponding probe/fetch artifacts.
Report an unrecognized store as drifted rather than silently empty ✅ pass live drift-human.txt, drift-scan.json, and drift-probe.json.
  • HOME="$PWD/.opencode-validation/test-home" XDG_CONFIG_HOME="$PWD/.opencode-validation/test-home/.config" TMPDIR="$PWD/.opencode-validation/tmp" GIT_CONFIG_NOSYSTEM=1 GIT_CONFIG_GLOBAL=/dev/null node --test --test-name-pattern='[Oo]pen[Cc]ode' test/adapters.test.js test/self-session.test.js
  • git archive ddf8a7b06a9d191ee696d2ae9a10683c8b1ca872 src bin package.json | tar -x -C .opencode-validation/base followed by the baseline CLI scan reproduced no such table: session.
  • node ~/.no-mistakes/evidence/01M3PBHV5RSAV96NQ138KWHJFA/opencode-live.mjs exercised isolated databases through the real CLI and production shipped-probe discovery/fetch protocol.
  • Repeated scan --harness opencode --host none --since all|1d --strict --json against both layouts, upgraded stores, adversarial session data, and a drifted schema; inspected saved CLI output and fetched transcript payloads.
  • rm -rf .opencode-validation; git status --short removed disposable data and confirmed no worktree changes.
⚠️ **Document** - 1 info
  • ℹ️ src/tui/render.js:342 - The completed OpenCode collection row still displays "1 sqlite query", but discovery now queries each available layout and performs schema checks. Replace the numeric claim with "sqlite store" in a follow-up. Left unchanged because this phase permits documentation and mechanical lint fixes, not runtime presentation changes.

🔧 No changes applied.
1 info still open:

  • ℹ️ src/tui/render.js:342 - The approved label correction remains blocked by this phase's scope: replacing "1 sqlite query" with "sqlite store" requires a runtime presentation edit and updating test/tui-render.test.js:234, which explicitly expects the old label. This phase prohibits both runtime behavior and test changes. The outer executor must route the approved fix to an authorized phase. Documentation, targeted ESLint and Prettier checks, and TypeScript checking otherwise pass.
✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

acpx drives opencode, and opencode is on both default ladders, so every
analysis and synthesis call backpass makes through it is filed in the
opencode store under the repo's cwd - a tier-1 exact match on the next
run. Self-session detection only reads transcript files, and an
opencode store is one SQLite database, so three things went wrong:

- The file-head check read the database's first 256 KiB. Its pages hold
  every session's text, so a backpass prompt stored near the start of
  the file marked every session in the store as backpass's own, and a
  prompt stored further in was missed.
- With the head check unable to see them, backpass's own opencode
  sessions were analyzed as corpus - backpass auditing itself, which the
  self-session sentinel exists to prevent.
- Each agent probe (`acpx opencode sessions new`) leaves an empty
  session under the repo's cwd, which was listed and matched at tier 1.

The opencode listing query now reads each session's first user text
part, the part an acpx prompt lands in, and marks the row `self` when it
opens with the sentinel; discovery drops those rows and counts them in
SELF. A session with no user text at all recorded nothing and is not
listed. Discovery never reads a SQLite database as a transcript head.
The new cases in `test/self-session.test.js` put a genuine session, a
self session and a probe's empty session in one small opencode store;
they fail on all three counts before this change.
…cks the first user message, preserving attachment-opening conversations and their descendants when later messages quote backpass prompts. Remote probes respect the adapter's explicit classification. Self ancestry is computed once per discovery instead of querying ancestors per child. Both regressions failed before the fixes and pass afterward. Verification passed: 103 relevant tests, targeted ESLint and Prettier checks, TypeScript checking, and git diff --check. The hosted Greptile check was not rerun in this phase
OpenCode 2 no longer writes `session`, `message` and `part`. Its store
keeps each session in `session_v2` and the whole history as one typed
row per message in `session_message`. On a 2.x-only store the adapter's
listing query failed with `no such table: session`, so the harness was
skipped with a warning and none of those sessions could be analyzed.

The adapter now reads both layouts from the one database:

- Listing reads `session_v2`, and dates a session by its newest message:
  `session_v2.time_updated` does not move as messages arrive, so a
  session resumed today was otherwise outside every window.
- An in-place upgrade copies each 1.x session into `session_v2` under
  the same id and leaves the 1.x tables behind; a session in both is
  listed once and read from `session_v2`, where it continues. A store
  with neither table is reported as drifted instead of read as empty.
- Reading maps each message type deliberately. User and assistant turns
  keep their text, and tool calls stay in the order the model made
  them, with their text output or error message as the result. Text the
  harness injected - instruction files (the memory file itself),
  continue notices, system notices, and compaction summaries of turns
  still stored above them - never becomes a turn. A background subagent
  or shell reports back in an injected message; that completion becomes
  the result of the call that started the job. A shell command or skill
  the person ran from the prompt is kept as a call.
- A 2.x session follows the same rules as a 1.x one: it is backpass's
  own when its first user message opens with the self-session sentinel
  or it descends from such a session, and it is not listed when it has
  no messages at all.

Golden fixtures pin both layouts: `test/fixtures/opencode-v2-store.json`
and `opencode-v1-store.json` carry the DDL of real 2.0.18 and 1.18.32
stores and rows modeled field-for-field on real ones.
@greptile-apps

greptile-apps Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 5/5

[Medium risk] Extends OpenCode store reading to support version 2.x schema.

The PR appears safe to merge based on the changes since the previous review.

Reviews (2) · Last reviewed commit: "no-mistakes(ci): Fixed ci-1 in src/tui/r..."

Comment thread src/discovery/adapters/opencode.js Resolved
…easured "1 sqlite query" claim with "sqlite store" at the shared OpenCode/Hermes rendering boundary. Reproduced the incorrect rendered output before fixing it. Updated rendering tests to cover both harnesses at three terminal widths while preserving session counts. All 23 rendering tests, targeted ESLint and Prettier checks, and git diff --check pass. Discovery behavior is unchanged

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: closing as subsumed. Tip vs main for the OpenCode 2 store reader + self/descendant exclusion landed via squash-merge of stacked #181 (04ac5efa89ef466debad07612428ba4c5f61e65c); this branch now conflicts only because those changes are already on main. Contract-class was restore (broken OpenCode 2 adapter + scope self-exclusion); CI was CLEAN before the stack merge. No separate merge needed — thank you @PawanAIT.

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.

2 participants