Skip to content

Commit 0606e31

Browse files
authored
feat(gateway): broker GitHub publication (#126306)
* feat(gateway): broker GitHub publication * refactor(gateway): split publication owners * fix(gateway): enforce publication branch authority * fix(gateway): bind publication to remote identity * fix(gateway): bind publication recovery to remote state * fix(gateway): preserve publication git state * fix(gateway): retain publication recovery authority * fix(gateway): commit publication index atomically * fix(gateway): narrow publication index errors * refactor(gateway): keep publication CAS errors private * fix(gateway): recover publication index transactions * fix(agents): describe GitHub publication tool * fix(gateway): harden publication base fetch * fix(gateway): reject publication filter semantics * fix(gateway): verify publication creation base * refactor(agents): align publication tool options * fix(gateway): isolate publication object lineage * refactor(gateway): use shared table probe * test(gateway): keep publication helpers in routed suite * perf(ui): lazy-load GitHub publication request * fix(gateway): preserve publication support contracts * fix(gateway): recover publication before authority checks * fix(gateway): fence local publication snapshots * fix(android): format generated protocol models * fix(gateway): harden publication recovery * fix(gateway): fence publication recovery * fix(ui): reset completed publication cycles
1 parent 5159904 commit 0606e31

122 files changed

Lines changed: 8894 additions & 369 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.

‎apps/android/app/src/main/java/ai/openclaw/app/gateway/GatewayProtocol.kt‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
// Generated by scripts/protocol-gen-kotlin.ts — do not edit by hand.
22
package ai.openclaw.app.gateway
33

4+
import kotlinx.serialization.ExperimentalSerializationApi
45
import kotlinx.serialization.SerialName
56
import kotlinx.serialization.Serializable
7+
import kotlinx.serialization.json.JsonClassDiscriminator
68
import kotlinx.serialization.json.JsonElement
79

810
const val GATEWAY_PROTOCOL_VERSION = 4
@@ -173,6 +175,44 @@ data class ProjectsListResult(
173175
val observedProjects: List<ProjectsListResultObservedProjectsItem>? = null,
174176
)
175177

178+
@SerialName("requested")
179+
@Serializable
180+
data class SessionGitHubPublicationRequested(
181+
val requestId: String,
182+
val message: String,
183+
) : SessionGitHubPublicationResult
184+
185+
@SerialName("publishing")
186+
@Serializable
187+
data class SessionGitHubPublicationPublishing(
188+
val requestId: String,
189+
val message: String,
190+
) : SessionGitHubPublicationResult
191+
192+
@SerialName("published")
193+
@Serializable
194+
data class SessionGitHubPublicationPublished(
195+
val requestId: String,
196+
val url: String,
197+
val repository: String,
198+
val branch: String,
199+
val headCommit: String,
200+
) : SessionGitHubPublicationResult
201+
202+
@SerialName("failed")
203+
@Serializable
204+
data class SessionGitHubPublicationFailed(
205+
val requestId: String,
206+
val code: String,
207+
val message: String,
208+
val nextAction: String,
209+
) : SessionGitHubPublicationResult
210+
211+
@OptIn(ExperimentalSerializationApi::class)
212+
@Serializable
213+
@JsonClassDiscriminator("status")
214+
sealed interface SessionGitHubPublicationResult
215+
176216
@Serializable
177217
data class GatewayEventFrameStateVersion(
178218
val presence: Long,
@@ -591,6 +631,7 @@ enum class GatewayMethod(
591631
ProgressCardPut("progressCard.put"),
592632
ToolsGithubStatus("tools.github.status"),
593633
ToolsGithubConfigure("tools.github.configure"),
634+
SessionsGithubPublish("sessions.github.publish"),
594635
DiagnosticsLanes("diagnostics.lanes"),
595636
}
596637

‎apps/android/app/src/test/java/ai/openclaw/app/gateway/GatewayProtocolGeneratedTest.kt‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,35 @@ class GatewayProtocolGeneratedTest {
6565
assertEquals(events.size, events.toSet().size)
6666
assertEquals("sessions.move", GatewayMethod.SessionsMove.rawValue)
6767
}
68+
69+
@Test
70+
fun githubPublicationResultsRoundTripAsATypedUnion() {
71+
val cases =
72+
listOf(
73+
"""{"requestId":"request-1","status":"requested","message":"Accepted."}""" to
74+
SessionGitHubPublicationRequested::class,
75+
"""{"requestId":"request-1","status":"publishing","message":"Publishing."}""" to
76+
SessionGitHubPublicationPublishing::class,
77+
"""{"requestId":"request-1","status":"published","url":"https://github.com/openclaw/openclaw/pull/1","repository":"openclaw/openclaw","branch":"openclaw/task","headCommit":"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}""" to
78+
SessionGitHubPublicationPublished::class,
79+
"""{"requestId":"request-1","status":"failed","code":"push_rejected","message":"Failed.","nextAction":"Check access."}""" to
80+
SessionGitHubPublicationFailed::class,
81+
)
82+
83+
for ((payload, expectedType) in cases) {
84+
val decoded = json.decodeFromString(SessionGitHubPublicationResult.serializer(), payload)
85+
assertEquals(expectedType, decoded::class)
86+
val encoded =
87+
json.encodeToJsonElement(SessionGitHubPublicationResult.serializer(), decoded).jsonObject
88+
assertEquals(
89+
json
90+
.parseToJsonElement(payload)
91+
.jsonObject
92+
.getValue("status")
93+
.jsonPrimitive
94+
.content,
95+
encoded.getValue("status").jsonPrimitive.content,
96+
)
97+
}
98+
}
6899
}

‎apps/shared/OpenClawKit/Sources/OpenClawKit/Resources/tool-display.json‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,13 @@
525525
"model"
526526
]
527527
},
528+
"github_publish": {
529+
"emoji": "🔀",
530+
"title": "GitHub Publish",
531+
"detailKeys": [
532+
"title"
533+
]
534+
},
528535
"sessions": {
529536
"emoji": "🗂️",
530537
"title": "Session Settings",

‎apps/shared/OpenClawKit/Sources/OpenClawProtocol/GatewayModels.swift‎

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6771,6 +6771,140 @@ public struct SessionsObserverVisibilityResult: Codable, Sendable {
67716771
}
67726772
}
67736773

6774+
public struct SessionGitHubPublishParams: Codable, Sendable {
6775+
public let sessionkey: String?
6776+
public let idempotencykey: String
6777+
public let title: String?
6778+
public let body: String?
6779+
6780+
public init(
6781+
sessionkey: String? = nil,
6782+
idempotencykey: String,
6783+
title: String? = nil,
6784+
body: String? = nil)
6785+
{
6786+
self.sessionkey = sessionkey
6787+
self.idempotencykey = idempotencykey
6788+
self.title = title
6789+
self.body = body
6790+
}
6791+
6792+
private enum CodingKeys: String, CodingKey {
6793+
case sessionkey = "sessionKey"
6794+
case idempotencykey = "idempotencyKey"
6795+
case title
6796+
case body
6797+
}
6798+
}
6799+
6800+
public struct SessionGitHubPublicationRequested: Codable, Sendable {
6801+
public let requestid: String
6802+
public let status: String
6803+
public let message: String
6804+
6805+
public init(
6806+
requestid: String,
6807+
status: String,
6808+
message: String)
6809+
{
6810+
self.requestid = requestid
6811+
self.status = status
6812+
self.message = message
6813+
}
6814+
6815+
private enum CodingKeys: String, CodingKey {
6816+
case requestid = "requestId"
6817+
case status
6818+
case message
6819+
}
6820+
}
6821+
6822+
public struct SessionGitHubPublicationPublishing: Codable, Sendable {
6823+
public let requestid: String
6824+
public let status: String
6825+
public let message: String
6826+
6827+
public init(
6828+
requestid: String,
6829+
status: String,
6830+
message: String)
6831+
{
6832+
self.requestid = requestid
6833+
self.status = status
6834+
self.message = message
6835+
}
6836+
6837+
private enum CodingKeys: String, CodingKey {
6838+
case requestid = "requestId"
6839+
case status
6840+
case message
6841+
}
6842+
}
6843+
6844+
public struct SessionGitHubPublicationPublished: Codable, Sendable {
6845+
public let requestid: String
6846+
public let status: String
6847+
public let url: String
6848+
public let repository: String
6849+
public let branch: String
6850+
public let headcommit: String
6851+
6852+
public init(
6853+
requestid: String,
6854+
status: String,
6855+
url: String,
6856+
repository: String,
6857+
branch: String,
6858+
headcommit: String)
6859+
{
6860+
self.requestid = requestid
6861+
self.status = status
6862+
self.url = url
6863+
self.repository = repository
6864+
self.branch = branch
6865+
self.headcommit = headcommit
6866+
}
6867+
6868+
private enum CodingKeys: String, CodingKey {
6869+
case requestid = "requestId"
6870+
case status
6871+
case url
6872+
case repository
6873+
case branch
6874+
case headcommit = "headCommit"
6875+
}
6876+
}
6877+
6878+
public struct SessionGitHubPublicationFailed: Codable, Sendable {
6879+
public let requestid: String
6880+
public let status: String
6881+
public let code: AnyCodable
6882+
public let message: String
6883+
public let nextaction: String
6884+
6885+
public init(
6886+
requestid: String,
6887+
status: String,
6888+
code: AnyCodable,
6889+
message: String,
6890+
nextaction: String)
6891+
{
6892+
self.requestid = requestid
6893+
self.status = status
6894+
self.code = code
6895+
self.message = message
6896+
self.nextaction = nextaction
6897+
}
6898+
6899+
private enum CodingKeys: String, CodingKey {
6900+
case requestid = "requestId"
6901+
case status
6902+
case code
6903+
case message
6904+
case nextaction = "nextAction"
6905+
}
6906+
}
6907+
67746908
public struct SessionSharingIdentity: Codable, Sendable {
67756909
public let type: AnyCodable
67766910
public let id: String
@@ -21186,6 +21320,43 @@ public enum SecretStoreEntry: Codable, Sendable {
2118621320
}
2118721321
}
2118821322

21323+
public enum SessionGitHubPublicationResult: Codable, Sendable {
21324+
case requested(SessionGitHubPublicationRequested)
21325+
case publishing(SessionGitHubPublicationPublishing)
21326+
case published(SessionGitHubPublicationPublished)
21327+
case failed(SessionGitHubPublicationFailed)
21328+
21329+
private enum CodingKeys: String, CodingKey {
21330+
case discriminator = "status"
21331+
}
21332+
21333+
public init(from decoder: Decoder) throws {
21334+
let container = try decoder.container(keyedBy: CodingKeys.self)
21335+
let discriminator = try container.decode(String.self, forKey: .discriminator)
21336+
switch discriminator {
21337+
case "requested": self = try .requested(SessionGitHubPublicationRequested(from: decoder))
21338+
case "publishing": self = try .publishing(SessionGitHubPublicationPublishing(from: decoder))
21339+
case "published": self = try .published(SessionGitHubPublicationPublished(from: decoder))
21340+
case "failed": self = try .failed(SessionGitHubPublicationFailed(from: decoder))
21341+
default:
21342+
throw DecodingError.dataCorruptedError(
21343+
forKey: .discriminator,
21344+
in: container,
21345+
debugDescription: "Unknown SessionGitHubPublicationResult discriminator value"
21346+
)
21347+
}
21348+
}
21349+
21350+
public func encode(to encoder: Encoder) throws {
21351+
switch self {
21352+
case .requested(let value): try value.encode(to: encoder)
21353+
case .publishing(let value): try value.encode(to: encoder)
21354+
case .published(let value): try value.encode(to: encoder)
21355+
case .failed(let value): try value.encode(to: encoder)
21356+
}
21357+
}
21358+
}
21359+
2118921360
public enum SessionPlacement: Codable, Sendable {
2119021361
case local(LocalSessionPlacement)
2119121362
case requested(RequestedSessionPlacement)

‎apps/shared/OpenClawKit/Tests/OpenClawKitTests/GatewayProtocolGeneratedModelsTests.swift‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,4 +158,29 @@ struct GatewayProtocolGeneratedModelsTests {
158158
#expect(encoded["scope"] as? String == expectedScope)
159159
#expect(encoded["mode"] as? String == (expectedManaged ? "managed" : "inherit"))
160160
}
161+
162+
@Test(arguments: [
163+
(#"{"requestId":"request-1","status":"requested","message":"Accepted."}"#, "requested"),
164+
(#"{"requestId":"request-1","status":"publishing","message":"Publishing."}"#, "publishing"),
165+
(#"{"requestId":"request-1","status":"published","url":"https://github.com/openclaw/openclaw/pull/1","repository":"openclaw/openclaw","branch":"openclaw/task","headCommit":"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}"#, "published"),
166+
(#"{"requestId":"request-1","status":"failed","code":"push_rejected","message":"Failed.","nextAction":"Check access."}"#, "failed"),
167+
])
168+
func `GitHub publication results round trip as a typed union`(
169+
json: String,
170+
expectedStatus: String) throws
171+
{
172+
let result = try JSONDecoder().decode(
173+
SessionGitHubPublicationResult.self,
174+
from: Data(json.utf8))
175+
switch result {
176+
case .requested: #expect(expectedStatus == "requested")
177+
case .publishing: #expect(expectedStatus == "publishing")
178+
case .published: #expect(expectedStatus == "published")
179+
case .failed: #expect(expectedStatus == "failed")
180+
}
181+
182+
let encoded = try #require(
183+
JSONSerialization.jsonObject(with: JSONEncoder().encode(result)) as? [String: Any])
184+
#expect(encoded["status"] as? String == expectedStatus)
185+
}
161186
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"startupJsGzipBytes": 344429,
3-
"reason": "Channel conversation avatars (PR #125668): lead-slot render branch + row plumbing on top of the 344395 B main baseline; avatar element itself is code-split out of startup",
4-
"updatedAt": "2026-08-18"
2+
"startupJsGzipBytes": 345578,
3+
"reason": "GitHub publication controls: lazy request chunk and branch-row state",
4+
"updatedAt": "2026-08-19"
55
}

‎docs/gateway/cloud-workers.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,8 @@ The bundled Crabbox provider advertises whatever machine classes the configured
211211

212212
Completed cloud turns reconcile eligible, size-bounded workspace files back into the session's managed worktree before the turn claim is released. Worker-turn uses its terminal worker event to create the durable pending-result fence. Remote-exec waits for workspace quiescence and enters the same reconciliation flow after the local Codex attempt. Before applying the result, the Gateway stages complete authenticated base/current manifests plus each changed resulting blob as a Git ref under `refs/openclaw/worker-results/`; deletions are represented by the manifests and need no blob. This keeps the cloud delta recoverable even if the Gateway stops during the apply without duplicating unchanged baseline content. Workspace results use Git file semantics: regular files, executable bits, symlinks, additions, changes, and deletions are retained, while empty directories and other directory modes are not. The resulting file changes remain in the managed worktree for normal review and commit.
213213

214+
To publish the finished work, the agent calls `github_publish` as its final action and then completes the turn. The call records only a single-line title, body, and idempotency key. After reconciliation is durably accepted, but before the exact turn claim is released, the Gateway re-resolves the session-owned managed worktree and effective GitHub identity. It uses the title as the commit subject, appends deterministic verified participant trailers, pushes the authoritative branch through an exact HTTPS path, and creates or reuses a draft pull request. The terminal transcript entry contains either the pull request URL or a typed failure with the next action. A restart resumes from the accepted workspace-result fence and remote branch or pull-request evidence; it never gives the recovered worker new forge authority.
215+
214216
Apply uses the dispatch-time manifest as the merge base. Cloud-only changes are applied, local-only changes stay in place, and paths changed on both sides use a three-way keep-local policy. A conflicted turn still finishes: the transcript reports the bounded path summary and staged result ref, the placement exposes the same conflict for the Control UI, and non-conflicting cloud changes remain applied. The notice includes `git show <ref>:<path>` to inspect a present cloud file and a top-level literal-pathspec `git checkout <ref> -- <path>` command to take it from any workspace directory. Run the commands in Bash or zsh (Git Bash on Windows). If inspect says the path does not exist, the cloud result deleted it; verify and remove the retained local path manually. If checkout reports a file/directory obstruction, move or remove the blocking local path and retry. If the staged ref itself is gone, treat the notice as stale and do not change the local path. Conflicted staged refs remain available after the normal turn fence is released; a later clean result clears the notice and retires the old ref, while explicit fence removal is the final cleanup boundary.
215217

216218
While a fenced result is still reconciling, a new turn waits up to 15 seconds for the prior claim to release. If it is still busy, the turn fails with an actionable “previous cloud turn's workspace result is still reconciling” message and can be retried shortly. On restart, recovery discovers pending and staged results before stale-claim cleanup, completes or retries their local apply, and reclaims dead environments only after preserving the result. The bounded SQLite rollback journal makes an interrupted filesystem apply recoverable without replaying already accepted mutations.
@@ -264,6 +266,7 @@ The bundled Crabbox provider does not support Cloud Worker Desktop after node tr
264266
- **Minted credentials, hashed at rest.** Each dispatch mints a worker credential; the Gateway stores only its hash. Credential rotation and owner-epoch fencing guarantee at most one live owner per session — a stale worker that reconnects is fenced, never merged.
265267
- **Environment-bound enrollment.** One short-lived node-only setup credential is bound to the durable environment before allocation. Its first authenticated Ed25519 device identity is recorded atomically with setup completion; replay cannot substitute an unrelated node.
266268
- **No standing model, forge, or cloud credentials on the box.** OpenClaw worker turns proxy inference by `{provider, model}` reference. Codex remote-exec keeps the app-server plus ChatGPT subscription or API-key auth on the Gateway and sends only sandbox operations to the box. Remote-exec requires prepared auth and rejects ambient auth fallback. Workspace git commits are authored without forge credentials, and Crabbox AWS lease metadata is checked authoritatively for an instance role before setup. Keep setup commands credential-free too.
269+
- **Gateway-owned GitHub publication.** Publication credentials stay in the effective managed or native GitHub profile on the Gateway. The broker disables repository hooks, refuses configured Git clean filters, uses a temporary index and `git commit-tree`, pushes only a reconstructed public HTTPS URL with a command-local `gh auth git-credential` helper, and never writes a bearer token to argv, a remote URL, `.git/config`, a worker payload, or a transcript.
267270
- **Provider-owned egress.** Gateway-proxied inference removes any OpenClaw need for direct model access, but OpenClaw does not rewrite provider firewalls. Restrict outbound traffic in the worker provider when the task requires it.
268271
- **Durable, exactly-once worker transcripts.** In worker-turn mode, the worker commits transcript batches through a compare-and-swap protocol against the session's leaf; a stale base fail-stops the run instead of duplicating or rebasing paid output. Remote-exec writes through the Gateway's normal local harness path.
269272

@@ -283,6 +286,7 @@ The bundled Crabbox provider does not support Cloud Worker Desktop after node tr
283286
- **Cloud workspace conflict notice** — the turn completed and kept the local version of each listed path. Use the staged-ref commands in the notice to inspect or take the cloud version; no retry is required for the non-conflicting changes, which are already applied.
284287
- **Cloud session disk-space warning** — delete unneeded files from the remote workspace or stop the cloud worker before large writes. The warning clears automatically after the next successful sample shows enough free space; a failed sample leaves the last successful warning visible and does not affect the session lifecycle.
285288
- **“The previous cloud turn's workspace result is still reconciling”** — the Gateway waited briefly for the prior result's durable fence and could not acquire the session claim. Wait for reconciliation to finish, then retry the turn; restarting the Gateway is safe because recovery preserves staged results before reclaiming a dead worker.
289+
- **GitHub publication failed** — open **Agents → Tools → GitHub Identity** and confirm the effective `@login` and credential health. Save a new managed PAT when the identity changed or the existing credential stopped working. For push rejection, inspect repository write access and branch drift; the broker never force-pushes. For pull request rejection, grant pull-request write access and call `github_publish` again with a new tool call.
286290
- **Lease housekeeping** — `crabbox list --provider <backend> --json` is a read-only inventory. `crabbox stop --provider <backend> --id <lease>` and `crabbox release --provider <backend> --id <lease>` are destructive and release a lease manually. OpenClaw keeps the lease alive while its session is placed, then stops heartbeating during teardown so genuinely idle leases expire on the profile's `idleTimeout`. Crabbox 0.43.0 and older do not expose the heartbeat command; OpenClaw warns once per environment and cannot prevent coordinator-idle reaping on those binaries.
287291

288292
## Related

0 commit comments

Comments
 (0)