fix: Connect cloud OpenCode sessions to the latest conversation (no-changelog) (#39449)

This commit is contained in:
Svetoslav Dekov
2026-09-24 09:28:34 +00:00
committed by GitHub
parent 3b3ac393ba
commit dfeb93cdc7
5 changed files with 169 additions and 77 deletions
+13 -4
View File
@@ -94,7 +94,7 @@ function startChild(command, args, options = {}) {
async function bootstrap(codespace, options, signal) {
signal.throwIfAborted();
console.log(`Preparing OpenCode workspace '${options.name}' on ${codespace}…`);
const command = `umask 077; mkdir -p /workspaces/.n8n-opencode && flock --close -w 600 /workspaces/.n8n-opencode/launch.lock node --input-type=module - ${options.name} ${options.fresh}`;
const command = `umask 077; mkdir -p /workspaces/.n8n-opencode && flock --close -w 600 /workspaces/.n8n-opencode/launch.lock node --input-type=module - ${options.name} ${options.fresh} ${options.web}`;
const remote = startChild('gh', ['codespace', 'ssh', '-c', codespace, '--', command], {
stdio: ['pipe', 'pipe', 'inherit'],
detached: true,
@@ -129,8 +129,8 @@ async function bootstrap(codespace, options, signal) {
!state ||
!Number.isInteger(state.port) ||
!text(state.password) ||
!text(state.sessionID) ||
!text(state.directory)
!text(state.directory) ||
(options.web && !text(state.sessionID))
) {
throw new Error('Invalid OpenCode server response.');
}
@@ -236,9 +236,18 @@ export async function connectOpenCode(options, ensureCodespace) {
openBrowser(webUrl);
} else {
console.log(`Connecting to OpenCode ${health.version} in ${state.directory}…`);
// OpenCode's own resume spans all worktrees of the repository. The
// server resolved the workspace's latest conversation instead, so
// target it directly. A fresh TUI conversation needs no target.
client = startChild(
'opencode',
['attach', url, '--dir', state.directory, '--session', state.sessionID],
[
'attach',
url,
'--dir',
state.directory,
...(state.sessionID ? ['--session', state.sessionID] : []),
],
{
stdio: 'inherit',
env: {