mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 04:44:21 +01:00
fix: refuse entity saves while a restart is pending and share replay payloads (OM-179)
This commit is contained in:
1 parent
8a6fd56e9a
commit
9fca96ecea
9 files changed
+82
-20
No files matched your search
@@ -27,6 +27,7 @@ import {
|
||||
import { readManagedOpenCodeConfig } from '../services/opencode-config-effective'
|
||||
import { applyOpenCodeConfigUpdate, toOpenCodeConfigApplyResponse } from '../services/opencode-config-apply'
|
||||
import { redactOpenCodeConfigContent, redactOpenCodeConfigFile } from '../services/opencode-config-redact'
|
||||
import { opencodeServerManager } from '../services/opencode-single-server'
|
||||
import { logger } from '../utils/logger'
|
||||
|
||||
interface OpenCodeConfigRoutesOptions {
|
||||
@@ -111,7 +112,6 @@ export function createOpenCodeConfigRoutes(
|
||||
const snapshot = await withOpenCodeConfigLock(readOpenCodeConfigSnapshot)
|
||||
const info = await readManagedOpenCodeConfig(openCodeClient.api, snapshot.sources)
|
||||
return c.json({
|
||||
revision: snapshot.revision,
|
||||
info: options.redactSecrets
|
||||
? redactOpenCodeConfigContent(info as Record<string, unknown>).content
|
||||
: info,
|
||||
@@ -175,6 +175,12 @@ export function createOpenCodeConfigRoutes(
|
||||
return c.json({ error: 'Invalid config data', details: parsed.error.issues }, 400)
|
||||
}
|
||||
|
||||
if (opencodeServerManager.isRestartPending()) {
|
||||
return c.json({
|
||||
error: 'OpenCode has not loaded the saved configuration yet. Restart OpenCode before editing entries.',
|
||||
}, 409)
|
||||
}
|
||||
|
||||
return applyUpdate(c, {
|
||||
content: parsed.data.patch,
|
||||
source: parsed.data.source,
|
||||
|
||||
@@ -61,6 +61,23 @@ export function planSessionStatusReplay(
|
||||
return { idle, busy }
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a `session.status` replay event restating the activity state of one session.
|
||||
*
|
||||
* @param buildEvent Replay event builder owned by the hub that delivers the event.
|
||||
* @param directory Directory the replayed event belongs to.
|
||||
* @param sessionID Session whose status is replayed.
|
||||
* @param status Activity state to replay.
|
||||
*/
|
||||
export function buildSessionStatusReplayEvent(
|
||||
buildEvent: ReplayEventBuilder,
|
||||
directory: string,
|
||||
sessionID: string,
|
||||
status: 'idle' | 'busy',
|
||||
): ReplayEvent {
|
||||
return buildEvent('session.status', directory, { sessionID, status: { type: status } })
|
||||
}
|
||||
|
||||
/**
|
||||
* Records the activity state an event implies for its session, so that directory-scoped work can be
|
||||
* limited to the sessions that are actually running.
|
||||
|
||||
@@ -12,6 +12,7 @@ import type {
|
||||
} from './opencode-server-registry'
|
||||
import {
|
||||
applySessionActivity,
|
||||
buildSessionStatusReplayEvent,
|
||||
collectPendingReplayEvents,
|
||||
createReplayEventBuilder,
|
||||
planSessionStatusReplay,
|
||||
@@ -316,7 +317,7 @@ export class RemoteServerEventHub {
|
||||
let replayed = 0
|
||||
|
||||
for (const { sessionID, directory } of plan.idle) {
|
||||
const event = this.buildReplayEvent('session.status', directory, { sessionID, status: { type: 'idle' } })
|
||||
const event = buildSessionStatusReplayEvent(this.buildReplayEvent, directory, sessionID, 'idle')
|
||||
this.aggregator.deliverRemoteEnvelope(serverId, directory, event)
|
||||
stream.busySessions.delete(sessionID)
|
||||
replayed++
|
||||
@@ -324,7 +325,7 @@ export class RemoteServerEventHub {
|
||||
|
||||
for (const sessionID of plan.busy) {
|
||||
const directory = stream.sessionDirectories.get(sessionID) ?? null
|
||||
const event = this.buildReplayEvent('session.status', directory ?? '', { sessionID, status: { type: 'busy' } })
|
||||
const event = buildSessionStatusReplayEvent(this.buildReplayEvent, directory ?? '', sessionID, 'busy')
|
||||
this.aggregator.deliverRemoteEnvelope(serverId, directory, event)
|
||||
stream.busySessions.add(sessionID)
|
||||
replayed++
|
||||
|
||||
@@ -4,6 +4,7 @@ import { type V2Event } from '@opencode-manager/shared/opencode'
|
||||
import type { OpenCodeClient } from './opencode/client'
|
||||
import { encodeSSEFrame } from '../utils/sse-frame'
|
||||
import {
|
||||
buildSessionStatusReplayEvent,
|
||||
collectPendingReplayEvents,
|
||||
createReplayEventBuilder,
|
||||
planSessionStatusReplay,
|
||||
@@ -308,7 +309,7 @@ class SSEAggregator {
|
||||
let replayed = 0
|
||||
|
||||
for (const { sessionID, directory } of plan.idle) {
|
||||
this.deliverEvent(directory, this.buildReplayEvent('session.status', directory, { sessionID, status: { type: 'idle' } }))
|
||||
this.deliverEvent(directory, buildSessionStatusReplayEvent(this.buildReplayEvent, directory, sessionID, 'idle'))
|
||||
replayed++
|
||||
}
|
||||
|
||||
@@ -319,7 +320,7 @@ class SSEAggregator {
|
||||
|
||||
for (const { sessionID, directory } of runningDirectories) {
|
||||
if (!directory) continue
|
||||
this.deliverEvent(directory, this.buildReplayEvent('session.status', directory, { sessionID, status: { type: 'busy' } }))
|
||||
this.deliverEvent(directory, buildSessionStatusReplayEvent(this.buildReplayEvent, directory, sessionID, 'busy'))
|
||||
replayed++
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user