Skip to content

Commit 25b75ed

Browse files
author
ben
authored
feat(remote-sessions): register native clients as offload targets (#5853)
* feat(remote-sessions): register clients with recoverable offloads * test(remote-sessions): prove native recovery on the selected host * test(remote-sessions): await native plugin activation and clean up safely * test(remote-sessions): isolate native config from repository defaults * test(remote-sessions): verify native home is outside the checkout * test(remote-sessions): provide native folder plugin entrypoint * fix(opencode): use native model query shapes and expose runner health * fix(remote-sessions): bind runners to verified members and build types * test(opencode): wait for the unload cancellation witness * fix(remote-sessions): restrict registered admission to opted-in clients
1 parent 5a8d92a commit 25b75ed

80 files changed

Lines changed: 8354 additions & 862 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/workflows/ci-opencode-openwork.yml‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ on:
44
pull_request:
55
paths:
66
- "packages/opencode-plugin/**"
7+
- "packages/remote-sessions/**"
78
- ".github/workflows/ci-opencode-openwork.yml"
89
- ".github/workflows/publish-opencode-plugin.yml"
910
push:
1011
branches: [dev]
1112
paths:
1213
- "packages/opencode-plugin/**"
14+
- "packages/remote-sessions/**"
1315
- ".github/workflows/ci-opencode-openwork.yml"
1416
- ".github/workflows/publish-opencode-plugin.yml"
1517

@@ -41,7 +43,16 @@ jobs:
4143
version: 11.4.0
4244

4345
- name: Install dependencies
44-
run: pnpm install --frozen-lockfile --ignore-scripts --filter opencode-openwork
46+
run: pnpm install --frozen-lockfile --ignore-scripts --filter opencode-openwork --filter @different-ai/openwork-workspace
47+
48+
- name: Build shared offload primitives
49+
run: pnpm --dir ../remote-sessions build
50+
51+
- name: Test shared offload primitives
52+
run: pnpm --dir ../remote-sessions test
53+
54+
- name: Test shared installed packaging
55+
run: node --test ../remote-sessions/test/built.test.mjs
4556

4657
- name: Test
4758
run: pnpm test

‎apps/app/src/app/lib/den.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3206,6 +3206,15 @@ export function createDenClient(options: {
32063206
});
32073207
},
32083208

3209+
async mintSessionRunnerToken(orgId: string, registration: AutomationDesktopRunnerRegistration): Promise<AutomationRunnerTokenResponse> {
3210+
return requestJson<AutomationRunnerTokenResponse>(baseUrls, "/v1/session-runners/token", {
3211+
method: "POST",
3212+
token,
3213+
organizationId: orgId,
3214+
body: registration,
3215+
});
3216+
},
3217+
32093218
async createAutomation(orgId: string, input: CreateAutomation): Promise<AutomationDetail> {
32103219
return requestJson<AutomationDetail>(baseUrls, "/v1/automations", {
32113220
method: "POST",

‎apps/app/src/react-app/domains/automations/automation-runner-bridge.tsx‎

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import {
44
AUTOMATION_MODEL_ATTENTION_CAPABILITY,
55
REMOTE_SESSION_CONTROL_RUNNER_CAPABILITY,
66
REMOTE_SESSION_DESKTOP_RUNNER_CAPABILITY,
7+
REMOTE_SESSION_RECOVERY_RUNNER_CAPABILITY,
8+
REMOTE_SESSION_ONLY_RUNNER_CAPABILITY,
79
} from "@openwork/types/automations"
810
import type {
911
AutomationDesktopRunnerCapability,
@@ -53,7 +55,7 @@ function ActivatedAutomationRunnerBridge() {
5355
const coordinator = createAutomationRunnerConnectCoordinator({
5456
refreshMs: RUNNER_TOKEN_REFRESH_MS,
5557
connect: async (isCurrent) => {
56-
if (!deploymentEnabled || status !== "signed_in") {
58+
if (status !== "signed_in") {
5759
await disconnect()
5860
return
5961
}
@@ -71,6 +73,23 @@ function ActivatedAutomationRunnerBridge() {
7173
if (!isCurrent()) return
7274
const agent = navigator.userAgent
7375
const platform = /Mac/i.test(agent) ? "darwin" : /Win/i.test(agent) ? "win32" : "linux"
76+
// Recovery changes admission semantics. Negotiate it only for an
77+
// explicitly enabled organization; old Den/missing features fail
78+
// closed to the released capability ladder, not to a new engine.
79+
const features = await client.getOrgFeatures(organizationId).catch((error): Record<string, boolean> => {
80+
// Released Automation registration can fall back to its old
81+
// protocol. A remote-only desktop must retry an unavailable
82+
// feature lookup rather than silently wait thirty minutes.
83+
if (deploymentEnabled) return {}
84+
throw error
85+
})
86+
if (!isCurrent()) return
87+
const recoveryEnabled = features.remoteSessionTargets === true
88+
if (!deploymentEnabled && !recoveryEnabled) {
89+
await disconnect()
90+
return
91+
}
92+
const mintToken = deploymentEnabled ? client.mintAutomationRunnerToken : client.mintSessionRunnerToken
7493
const mintRunner = async (id: string) => {
7594
const registration = (
7695
capabilities: AutomationDesktopRunnerCapability[],
@@ -86,18 +105,30 @@ function ActivatedAutomationRunnerBridge() {
86105
// Older/self-hosted Den versions reject capabilities they do not
87106
// know with a 400. Step down one capability set at a time so
88107
// Automation delivery keeps working until that server upgrades.
89-
const capabilitySets: AutomationDesktopRunnerCapability[][] = [
108+
const recoveryCapabilities: AutomationDesktopRunnerCapability[] = [
109+
AUTOMATION_MODEL_ATTENTION_CAPABILITY,
110+
REMOTE_SESSION_DESKTOP_RUNNER_CAPABILITY,
111+
REMOTE_SESSION_CONTROL_RUNNER_CAPABILITY,
112+
REMOTE_SESSION_RECOVERY_RUNNER_CAPABILITY,
113+
]
114+
const capabilitySets: AutomationDesktopRunnerCapability[][] = deploymentEnabled ? [
115+
...(recoveryEnabled ? [recoveryCapabilities] : []),
90116
[
91117
AUTOMATION_MODEL_ATTENTION_CAPABILITY,
92118
REMOTE_SESSION_DESKTOP_RUNNER_CAPABILITY,
93119
REMOTE_SESSION_CONTROL_RUNNER_CAPABILITY,
94120
],
95121
[AUTOMATION_MODEL_ATTENTION_CAPABILITY, REMOTE_SESSION_DESKTOP_RUNNER_CAPABILITY],
96122
[AUTOMATION_MODEL_ATTENTION_CAPABILITY],
97-
]
123+
] : [[
124+
REMOTE_SESSION_DESKTOP_RUNNER_CAPABILITY,
125+
REMOTE_SESSION_CONTROL_RUNNER_CAPABILITY,
126+
REMOTE_SESSION_RECOVERY_RUNNER_CAPABILITY,
127+
REMOTE_SESSION_ONLY_RUNNER_CAPABILITY,
128+
]]
98129
for (const [index, capabilities] of capabilitySets.entries()) {
99130
try {
100-
return await client.mintAutomationRunnerToken(organizationId, registration(capabilities))
131+
return await mintToken(organizationId, registration(capabilities))
101132
} catch (error) {
102133
const last = index === capabilitySets.length - 1
103134
if (last || !(error instanceof DenApiError) || error.status !== 400) throw error

0 commit comments

Comments
 (0)