Skip to content

Commit 70d2ee5

Browse files
OpenCode fails to start: "no such column: project_id" (AltharIDE#519)
* OpenCode 1.x on a data folder OpenCode 2 moved on: say so, and download 2.x OpenCode 2's workspace_domain migration drops workspace.project_id, which OpenCode 1.x still updates on opening a repository, so it stops with 'no such column: project_id' (anomalyco/opencode#42170). The stuck card now says what's wrong and how to update to version 2, and Althar's own download of OpenCode takes the newest 2.x release rather than GitHub's latest, which is still 1.x. Co-authored-by: Althar <[email protected]> * The way out of an older OpenCode names OpenCode 2's own install 1.x's upgrade and installer refuse a 2.x version, so the card points at OpenCode 2's docs, which give its installer for each platform. Co-authored-by: Althar <[email protected]> --------- Co-authored-by: Althar <[email protected]>
1 parent 94199ff commit 70d2ee5

6 files changed

Lines changed: 93 additions & 33 deletions

File tree

‎packages/provider-adapters/src/registry.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,8 @@ export type AgentDownload = GitHubDownload | PinnedDownload
421421
export interface GitHubDownload {
422422
/** Its GitHub repository, owner/name: its latest release is what is downloaded. */
423423
readonly repository: string
424+
/** Only releases whose tag starts so, such as `v2.`: the newest of them, where its latest release is on another line. */
425+
readonly line?: string
424426
/** The release's file for each `platform-arch`, as Node names them: a zip or a gzipped tar with the command in it. */
425427
readonly assets: Readonly<Record<string, string>>
426428
/** About how big the download is, as the person reads it. */
@@ -1081,12 +1083,17 @@ export const agents: Readonly<Record<AgentId, AgentDefinition>> = {
10811083
}),
10821084
}
10831085
},
1084-
/* MIT licensed; its releases are at anomalyco/opencode (sst/opencode before), each file with GitHub's sha256. Seen 9 October 2026, v1.18.35. */
1086+
/*
1087+
* MIT licensed; its releases are at anomalyco/opencode (sst/opencode before), each file with GitHub's sha256.
1088+
* Its 2.x is what Althar runs (`--standalone` above), and GitHub's latest is still 1.x, which also can't open a
1089+
* data folder 2.x has migrated: the newest 2.x it is. Seen 2 November 2026, v2.2.5 beside v1.19.5.
1090+
*/
10851091
cli: {
10861092
name: 'opencode',
10871093
guide: 'https://github.com/anomalyco/opencode',
10881094
download: {
10891095
repository: 'anomalyco/opencode',
1096+
line: 'v2.',
10901097
assets: {
10911098
'darwin-arm64': 'opencode-darwin-arm64.zip',
10921099
'darwin-x64': 'opencode-darwin-x64.zip',

‎packages/runtime/src/Installs.ts‎

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -263,31 +263,46 @@ export class Installs extends Context.Service<
263263
return outThere(cli.name)
264264
}
265265

266-
/** The agent's latest release, and its file for this device with the digest GitHub gives it. */
266+
/** The agent's latest release, or the newest on its line, and its file for this device with the digest GitHub gives it. */
267267
const latest = (definition: AgentDefinition, install: Exclude<AgentDownload, PinnedDownload>) =>
268268
Effect.gen(function* () {
269269
const asset = assetOf(install.assets)
270270
if (asset === undefined) return yield* fail(definition.id, `There's no ${definition.name} for this computer to download.`)
271+
const line = install.line
271272
const response = yield* Effect.tryPromise({
272273
try: () =>
273-
fetch(`https://api.github.com/repos/${install.repository}/releases/latest`, {
274+
fetch(`https://api.github.com/repos/${install.repository}/releases${line === undefined ? '/latest' : '?per_page=30'}`, {
274275
headers: { Accept: 'application/vnd.github+json', 'User-Agent': 'Althar' },
275276
}),
276277
catch: (error) => fail(definition.id, `GitHub couldn't be reached to find ${definition.name}.`, error),
277278
})
278279
if (!response.ok)
279280
return yield* fail(definition.id, `GitHub didn't say where ${definition.name}'s latest release is.`, response.status)
280-
const body = (yield* Effect.tryPromise({
281+
const answer = yield* Effect.tryPromise({
281282
try: () => response.json() as Promise<unknown>,
282283
catch: (error) => fail(definition.id, `GitHub's answer about ${definition.name} couldn't be read.`, error),
283-
})) as {
284+
})
285+
type Answer = {
284286
readonly tag_name?: unknown
287+
readonly draft?: unknown
288+
readonly prerelease?: unknown
285289
readonly assets?: ReadonlyArray<{
286290
readonly name?: unknown
287291
readonly browser_download_url?: unknown
288292
readonly digest?: unknown
289293
}>
290294
}
295+
// Newest first, as GitHub lists them: the first published release on the line.
296+
const body: Answer =
297+
line === undefined
298+
? (answer as Answer)
299+
: ((Array.isArray(answer) ? (answer as ReadonlyArray<Answer>) : []).find(
300+
(each) =>
301+
each.draft !== true &&
302+
each.prerelease !== true &&
303+
typeof each.tag_name === 'string' &&
304+
each.tag_name.startsWith(line),
305+
) ?? {})
291306
const found = body.assets?.find((each) => each.name === asset)
292307
const digest = typeof found?.digest === 'string' ? /^sha256:([0-9a-f]{64})$/.exec(found.digest)?.[1] : undefined
293308
if (typeof body.tag_name !== 'string' || !/^[\w.-]{1,40}$/.test(body.tag_name) || found === undefined)

‎packages/runtime/src/words.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,18 @@ const hostDenied =
5050
/** A sentence, with its full stop. */
5151
const sentence = (words: string): string => (/[.!?]$/.test(words) ? words : `${words}.`)
5252

53+
/**
54+
* OpenCode 1.x on a data folder OpenCode 2 has migrated: 2's `workspace_domain`
55+
* rebuilt the `workspace` table without `project_id`, which 1.x still updates
56+
* when it opens a repository, so it stops on every start there (anomalyco/opencode#42170).
57+
* Neither `opencode upgrade` nor 1.x's installer moves to 2 (the installer refuses
58+
* a 2.x version): OpenCode 2 has an installer of its own, which its docs give for
59+
* each platform. Seen 2 November 2026, 1.18.31 against 2.2.5.
60+
*/
61+
const olderOpenCode = /no such column: project_id/
62+
const olderOpenCodeWords =
63+
'OpenCode’s own database was moved on by OpenCode 2, and this OpenCode is 1.x, which can’t open it. Install OpenCode 2 (opencode.ai/v2/docs says how), then try again.'
64+
5365
/** An agent whose account is signed out, as a step's call says it: the call itself offers signing in again. */
5466
export const signedOutWords = 'The agent is signed out. Sign it in again in Settings, then try again.'
5567

@@ -71,6 +83,7 @@ export const agentSaid = (error: unknown): string | undefined => {
7183
const said = lastLine(text(error, 'stderr'))
7284
// A bridge that started and then could not take the command out to the device says so; keep its sentence, not "the agent stopped".
7385
if (/flatpak-spawn|org\.freedesktop\.Flatpak/i.test(said)) return hostDenied
86+
if (olderOpenCode.test(said)) return olderOpenCodeWords
7487
return said === '' ? 'The agent stopped.' : sentence(`The agent stopped: ${said}`)
7588
}
7689
case 'AgentRequestFailed':

‎packages/runtime/tests/api.test.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2566,6 +2566,17 @@ describe('words', () => {
25662566
'The agent stopped: out of memory.',
25672567
)
25682568
assert.strictEqual(agentSaid(new AgentExited({ code: 1, signal: null, stderr: '' })), 'The agent stopped.')
2569+
// OpenCode 1.x on a data folder OpenCode 2 has moved on, as 1.18.31 said it: what's wrong and the way out, never the bare SQLite error.
2570+
assert.strictEqual(
2571+
agentSaid(
2572+
new AgentExited({
2573+
code: 1,
2574+
signal: null,
2575+
stderr: '\u001b[91m\u001b[1mError: \u001b[0mUnexpected error\n\nno such column: project_id\n',
2576+
}),
2577+
),
2578+
'OpenCode’s own database was moved on by OpenCode 2, and this OpenCode is 1.x, which can’t open it. Install OpenCode 2 (opencode.ai/v2/docs says how), then try again.',
2579+
)
25692580
const failed = (failure: AgentRequestFailed['failure'], resetsAt?: string) =>
25702581
agentSaid(
25712582
new AgentRequestFailed({

‎packages/runtime/tests/installs.test.ts‎

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,26 @@ const archive = (version = '9.9.9') => {
4040

4141
const sha = (bytes: Buffer) => createHash('sha256').update(bytes).digest('hex')
4242

43-
/** GitHub as far as a download asks it: the latest release, and its file. */
44-
const github = (bytes: Buffer, { digest = `sha256:${sha(bytes)}` as string | null, tag = 'v1.18.35', asset = ASSET } = {}) => {
43+
/** Whether a download asks GitHub which releases there are, rather than for a file. */
44+
const listing = (url: string) => url.includes('/releases?')
45+
46+
/**
47+
* GitHub as far as a download asks it: OpenCode's releases, newest first, and
48+
* the file. A newer 1.x and a 2.x prerelease come before the release it takes,
49+
* as 1.x is still GitHub's latest.
50+
*/
51+
const github = (bytes: Buffer, { digest = `sha256:${sha(bytes)}` as string | null, tag = 'v2.2.5', asset = ASSET } = {}) => {
4552
const asked: Array<string> = []
4653
const fetch = async (url: string) => {
4754
asked.push(url)
48-
if (url.endsWith('/releases/latest'))
49-
return Response.json({
50-
tag_name: tag,
51-
assets: [{ name: asset, browser_download_url: 'https://github.example/download', ...(digest === null ? {} : { digest }) }],
52-
})
55+
const assets = [{ name: asset, browser_download_url: 'https://github.example/download', ...(digest === null ? {} : { digest }) }]
56+
if (listing(url))
57+
return Response.json([
58+
{ tag_name: 'v1.99.0', assets },
59+
{ tag_name: 'v2.99.0-beta.1', prerelease: true, assets },
60+
{ tag_name: 'process-daemon-v0.4.0', assets },
61+
{ tag_name: tag, assets },
62+
])
5363
return new Response(new Uint8Array(bytes))
5464
}
5565
return { fetch, asked }
@@ -63,7 +73,7 @@ const using = (options: Partial<InstallsOptions>) => {
6373

6474
describe('downloading an agent', () => {
6575
// Not on Windows: the release it downloads is a shell script, which Althar runs (--version) to check it.
66-
it.skipIf(windows)('keeps its latest release, checked, and runs it where the person has none', async () => {
76+
it.skipIf(windows)('keeps its newest 2.x release, checked, and runs it where the person has none', async () => {
6777
const { fetch, asked } = github(archive())
6878
const { root, run } = using({ fetch })
6979
const before = await run(Effect.flatMap(Installs, (installs) => installs.state(opencode)))
@@ -76,8 +86,9 @@ describe('downloading an agent', () => {
7686
)
7787
const done = await run(Effect.flatMap(Installs, (installs) => installs.install(opencode)))
7888
assert.isTrue(Exit.isSuccess(done))
79-
assert.strictEqual(asked[0], 'https://api.github.com/repos/anomalyco/opencode/releases/latest')
80-
assert.strictEqual(readlinkSync(join(root, 'opencode', 'current')), 'v1.18.35')
89+
// Not GitHub's latest, which is still 1.x: that can't open a data folder 2.x has moved on.
90+
assert.strictEqual(asked[0], 'https://api.github.com/repos/anomalyco/opencode/releases?per_page=30')
91+
assert.strictEqual(readlinkSync(join(root, 'opencode', 'current')), 'v2.2.5')
8192
assert.strictEqual(execFileSync(join(root, 'opencode', 'current', 'opencode'), { encoding: 'utf8' }).trim(), '9.9.9')
8293
const after = await run(Effect.map(Installs, (installs) => installs.locate(opencode)))
8394
assert.deepStrictEqual(Exit.isSuccess(after) ? after.value : null, {
@@ -88,10 +99,10 @@ describe('downloading an agent', () => {
8899

89100
// Not on Windows: the release it downloads is a shell script, which Althar runs (--version) to check it.
90101
it.skipIf(windows)('replaces the version before, leaving nothing of the download behind', async () => {
91-
const first = github(archive('1.0.0'), { tag: 'v1.0.0' })
102+
const first = github(archive('2.0.0'), { tag: 'v2.0.0' })
92103
const { root, run } = using({ fetch: first.fetch })
93104
await run(Effect.flatMap(Installs, (installs) => installs.install(opencode)))
94-
const second = github(archive('2.0.0'), { tag: 'v2.0.0' })
105+
const second = github(archive('2.1.0'), { tag: 'v2.1.0' })
95106
const again = Installs.layer({
96107
root,
97108
platform: 'linux',
@@ -106,7 +117,7 @@ describe('downloading an agent', () => {
106117
again,
107118
),
108119
)
109-
assert.deepStrictEqual(readdirSync(join(root, 'opencode')).toSorted(), ['current', 'v2.0.0'])
120+
assert.deepStrictEqual(readdirSync(join(root, 'opencode')).toSorted(), ['current', 'v2.1.0'])
110121
})
111122

112123
it('keeps nothing that isn’t exactly the release’s file, or that its release gives no digest for', async () => {
@@ -213,11 +224,12 @@ describe('downloading an agent', () => {
213224
expect(await said(async () => Promise.reject(new Error('offline')))).toContain("GitHub couldn't be reached")
214225
expect(await said(async () => new Response('', { status: 403 }))).toContain("GitHub didn't say where")
215226
expect(await said(async () => new Response('not json'))).toContain("couldn't be read")
216-
expect(await said(async () => Response.json({ tag_name: '../../x', assets: [] }))).toContain('has no download for this computer')
217-
expect(await said(async (url) => (url.endsWith('/latest') ? good(url) : new Response('', { status: 404 })))).toContain(
227+
expect(await said(async () => Response.json([{ tag_name: 'v2.../../x', assets: [] }]))).toContain('has no download for this computer')
228+
expect(await said(async () => Response.json([{ tag_name: 'v1.99.0', assets: [] }]))).toContain('has no download for this computer')
229+
expect(await said(async (url) => (listing(url) ? good(url) : new Response('', { status: 404 })))).toContain(
218230
"OpenCode couldn't be downloaded",
219231
)
220-
expect(await said(async (url) => (url.endsWith('/latest') ? good(url) : Promise.reject(new Error('reset'))))).toContain(
232+
expect(await said(async (url) => (listing(url) ? good(url) : Promise.reject(new Error('reset'))))).toContain(
221233
"OpenCode couldn't be downloaded",
222234
)
223235
// An archive without the command, and one whose command won't run here.
@@ -241,7 +253,7 @@ describe('downloading an agent', () => {
241253
// A second download while the first runs is refused; the first finishes.
242254
let release: () => void = () => {}
243255
const slow = async (url: string) => {
244-
if (!url.endsWith('/latest')) await new Promise<void>((resolve) => (release = resolve))
256+
if (!listing(url)) await new Promise<void>((resolve) => (release = resolve))
245257
return good(url)
246258
}
247259
const once = using({ fetch: slow })

‎packages/runtime/tests/installsPinned.test.ts‎

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -122,17 +122,19 @@ describe('where an agent’s command is', () => {
122122
execFileSync('tar', ['-czf', file, '-C', dir, 'release'])
123123
const bytes = readFileSync(file)
124124
const fetch = async (url: string) =>
125-
url.endsWith('/releases/latest')
126-
? Response.json({
127-
tag_name: 'v1.18.35',
128-
assets: [
129-
{
130-
name: 'opencode-linux-x64.tar.gz',
131-
browser_download_url: 'https://github.example/download',
132-
digest: `sha256:${sum(bytes)}`,
133-
},
134-
],
135-
})
125+
url.includes('/releases?')
126+
? Response.json([
127+
{
128+
tag_name: 'v2.2.5',
129+
assets: [
130+
{
131+
name: 'opencode-linux-x64.tar.gz',
132+
browser_download_url: 'https://github.example/download',
133+
digest: `sha256:${sum(bytes)}`,
134+
},
135+
],
136+
},
137+
])
136138
: new Response(new Uint8Array(bytes))
137139
const root = mkdtempSync(join(tmpdir(), 'althar-agents-'))
138140
const layer = Installs.layer({ root, platform: 'linux', arch: 'x64', musl: false, fetch, search: { env: { PATH: '' }, dirs: [] } })

0 commit comments

Comments
 (0)