jg-agent-hq 13.5.1 → 13.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 13.5.2
|
|
4
|
+
|
|
5
|
+
- Automatically rejoin previously managed Codex sessions after a shared connection loss or HQ restart when their verified latest native turn changed. Joining sends no input or settings, leaves earlier receipts unresolved and queues paused, and still refuses unverified state, pending submissions and turn changes during the join. Existing uncertain/external sessions still require explicit recovery.
|
|
6
|
+
|
|
3
7
|
## 13.5.1
|
|
4
8
|
|
|
5
9
|
- Allow confirmed recovery of a known quarantined Codex identity in the current HQ runtime, including loaded active, idle and unloaded sessions, without restarting HQ. Verify the native turn before and after joining, retain paused queues and unresolved receipts, and send no settings or input. Healthy controls, pending dispatches and unverified identities remain refused.
|
package/README.md
CHANGED
|
@@ -77,7 +77,7 @@ Native execution settings, instructions, skills and tool permissions remain with
|
|
|
77
77
|
|
|
78
78
|
When Claude sends structurally valid evidence HQ cannot interpret, HQ suspends that session's controls and live interpretation while its native work continues. It closes the quarantined controller automatically only after fresh native idle, a known empty task snapshot and no unresolved requests establish that work has finished. Unknown evidence or an unanswered approval keeps it alive; confirmed `thread-close` with `interrupt: true` explicitly stops its owned process group, including unfinished background work. Identity and transport-integrity failures retain their shutdown handling.
|
|
79
79
|
|
|
80
|
-
A quarantined known Codex identity offers confirmed recovery in the current runtime without an HQ restart. Recovery verifies the native turn before and after joining, sends no input or settings, keeps earlier queues paused and leaves uncertain receipts unresolved.
|
|
80
|
+
A quarantined known Codex identity offers confirmed recovery in the current runtime without an HQ restart. Recovery verifies the native turn before and after joining, sends no input or settings, keeps earlier queues paused and leaves uncertain receipts unresolved. Previously managed sessions also rejoin automatically after connection loss or runtime restart when their verified latest turn changed, without resolving earlier receipts or releasing old queues. Unknown state, pending submissions and a turn changing during the join still require inspection and explicit recovery. Native turn IDs do not prove exclusive control; keep other controlling clients closed.
|
|
81
81
|
|
|
82
82
|
After verified owned-group shutdown and controller release, that conversation becomes managed and inactive without restarting HQ. Resume retains its native identity and history. Unacknowledged input stays uncertain, earlier queued work stays paused, and pending approvals expire. Unconfirmed shutdown or a competing native terminal keeps ownership uncertain; another controlled conversation remains usable. See [Claude connection recovery](docs/recovery.md#claude-connection-recovery).
|
|
83
83
|
|
package/api/README.md
CHANGED
|
@@ -93,7 +93,7 @@ After optional `initializeHostStorage` completes, the runtime connects both nati
|
|
|
93
93
|
|
|
94
94
|
The controller holds the state root's `runtime` lock for its lifetime, as [lock lifecycle](#lock-lifecycle) describes. A live, dead, incomplete or unverifiable existing holder prevents another controller from starting, apart from a dead holder the host's `isPreviousRuntimeStopped` check proves stopped. Before deliberate recovery, establish that the inspected host, its worker and native process group have stopped. Runtime shutdown sends interruption requests across the bounded Claude session cohort concurrently, then closes IPC connections, SQLite and owned native processes before releasing the `runtime` lock. Failed cleanup keeps the lock held. A new runtime receives a new epoch.
|
|
95
95
|
|
|
96
|
-
Codex sessions outlive the runtime, because they run in Codex's shared app-server daemon. Shutdown leaves them running: it doesn't interrupt their turns, clean their background terminals or answer a request still waiting on one, and their managed records stay bound to the stopped runtime. At startup, the next runtime rejoins each one that had no action in flight, one at a time in the background. It reads the session's state and latest turn from the daemon, binds the record to its own epoch, then joins with `thread/resume` without settings. A turn still running stays the session's active turn. A turn that finished meanwhile completes its action's receipt, without a `result`, and lets a queued entry waiting on it advance. The daemon sends a still-waiting request again on joining, and it opens as a new approval in the new epoch.
|
|
96
|
+
Codex sessions outlive the runtime, because they run in Codex's shared app-server daemon. Shutdown leaves them running: it doesn't interrupt their turns, clean their background terminals or answer a request still waiting on one, and their managed records stay bound to the stopped runtime. At startup, the next runtime rejoins each one that had no action in flight, one at a time in the background. It reads the session's state and latest turn from the daemon, binds the record to its own epoch, then joins with `thread/resume` without settings. A turn still running stays the session's active turn. A turn that finished meanwhile completes its action's receipt, without a `result`, and lets a queued entry waiting on it advance. The daemon sends a still-waiting request again on joining, and it opens as a new approval in the new epoch. If the verified latest turn changed, the runtime restores control of that previously managed identity without assigning its completion to the earlier action or releasing earlier queued input. This also covers native daemon recovery continuations. Native turn IDs do not establish exclusive control or distinguish another client's turn, so competing controllers must remain closed. A session that cannot be verified or whose turn changes during the join stays uncertain for explicit recovery. A crash leaves the same bound records, so those sessions are rejoined too. A restored snapshot marks every session uncertain, so it never rejoins one. Claude sessions are processes the runtime owns: their turns stop with it, and they wait inactive for an explicit resume.
|
|
97
97
|
|
|
98
98
|
One Codex connection carries every managed Codex session, so a message the runtime can't validate never fails it. A notification about items, text deltas, token usage or a session's status that fails validation is dropped, and a session the runtime controls reports a gap in its live window; a status newer than the runtime knows makes the session `unknown`. A message over 33,554,432 bytes, including its continuation fragments, is skipped through its final fragment without being buffered; a request whose response was skipped fails at its 30-second deadline. A turn start, turn end or approval resolution that fails validation, or a skipped message, whose session can't be known so every session the runtime controls is affected, is made up for by reading the session from the daemon, one session at a time and outside the order other sessions' events keep:
|
|
99
99
|
|
|
@@ -46,9 +46,9 @@ export declare class ControlLifecycle extends ControlModel {
|
|
|
46
46
|
/**
|
|
47
47
|
* Binds a kept or reconnecting session to this runtime, as its native process reports
|
|
48
48
|
* it before the runtime rejoins it. A turn that finished meanwhile completes its action and lets
|
|
49
|
-
* the session's queued input advance, which this runtime then delivers. A
|
|
50
|
-
*
|
|
51
|
-
* uncertain
|
|
49
|
+
* the session's queued input advance, which this runtime then delivers. A different verified turn
|
|
50
|
+
* restores control without completing the earlier action or releasing its queued input.
|
|
51
|
+
* Unverifiable native state stays uncertain.
|
|
52
52
|
* @returns The thread and whether its queue may advance, or null when it is no longer one to rejoin.
|
|
53
53
|
* @throws
|
|
54
54
|
* - JG_AGENT_HQ_ACTION_CONFLICT: The HQ action conflicts with its recorded state
|
|
@@ -107,9 +107,9 @@ export class ControlLifecycle extends ControlModel {
|
|
|
107
107
|
/**
|
|
108
108
|
* Binds a kept or reconnecting session to this runtime, as its native process reports
|
|
109
109
|
* it before the runtime rejoins it. A turn that finished meanwhile completes its action and lets
|
|
110
|
-
* the session's queued input advance, which this runtime then delivers. A
|
|
111
|
-
*
|
|
112
|
-
* uncertain
|
|
110
|
+
* the session's queued input advance, which this runtime then delivers. A different verified turn
|
|
111
|
+
* restores control without completing the earlier action or releasing its queued input.
|
|
112
|
+
* Unverifiable native state stays uncertain.
|
|
113
113
|
* @returns The thread and whether its queue may advance, or null when it is no longer one to rejoin.
|
|
114
114
|
* @throws
|
|
115
115
|
* - JG_AGENT_HQ_ACTION_CONFLICT: The HQ action conflicts with its recorded state
|
|
@@ -124,25 +124,34 @@ export class ControlLifecycle extends ControlModel {
|
|
|
124
124
|
const now = Date.now();
|
|
125
125
|
const latest = input.latestTurn;
|
|
126
126
|
const isRunning = latest?.state === 'running';
|
|
127
|
-
|
|
128
|
-
(isRunning && thread.active_turn_id === null)
|
|
127
|
+
const hasChangedTurn = (latest?.nativeTurnId ?? null) !== (thread.active_turn_id ?? thread.last_turn_id) ||
|
|
128
|
+
(isRunning && thread.active_turn_id === null);
|
|
129
|
+
if (hasChangedTurn && latest === null) {
|
|
129
130
|
if (!input.isReconnect)
|
|
130
131
|
this.__quarantine(thread.id, now);
|
|
131
132
|
return { thread: this._managedThread(thread.id), canDispatchQueued: false };
|
|
132
133
|
}
|
|
133
134
|
this._availableSlot();
|
|
134
135
|
// the turn HQ left running, when it has finished since
|
|
135
|
-
const finished = thread.active_turn_id !== null && latest && latest.state !== 'running'
|
|
136
|
+
const finished = !hasChangedTurn && thread.active_turn_id !== null && latest && latest.state !== 'running'
|
|
136
137
|
? { nativeTurnId: latest.nativeTurnId, state: latest.state }
|
|
137
138
|
: null;
|
|
138
|
-
const state =
|
|
139
|
-
?
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
139
|
+
const state = hasChangedTurn
|
|
140
|
+
? latest.state
|
|
141
|
+
: isRunning
|
|
142
|
+
? thread.state === 'stopping'
|
|
143
|
+
? 'stopping'
|
|
144
|
+
: 'running'
|
|
145
|
+
: (finished?.state ??
|
|
146
|
+
(input.isReconnect ? (thread.last_turn_state ?? 'idle') : thread.state));
|
|
147
|
+
this._statements.run("UPDATE agent_hq_thread SET ownership = 'managed', runtime_epoch = ?, active_turn_id = ?, last_turn_id = ?, last_turn_state = ?, state = ?, updated_at = ? WHERE id = ?", this._epoch, isRunning ? latest.nativeTurnId : null, hasChangedTurn && latest && !isRunning
|
|
148
|
+
? latest.nativeTurnId
|
|
149
|
+
: (finished?.nativeTurnId ?? thread.last_turn_id), hasChangedTurn && latest && !isRunning
|
|
150
|
+
? latest.state
|
|
151
|
+
: (finished?.state ?? thread.last_turn_state), state, now, thread.id);
|
|
145
152
|
this._statements.run("UPDATE agent_hq_action SET runtime_epoch = ?, updated_at = ? WHERE thread_id = ? AND delivery = 'queued'", this._epoch, now, thread.id);
|
|
153
|
+
if (hasChangedTurn)
|
|
154
|
+
this._statements.run("UPDATE agent_hq_action SET queue_ready = 0 WHERE thread_id = ? AND delivery = 'queued'", thread.id);
|
|
146
155
|
const canDispatchQueued = finished?.state === 'completed' && thread.state !== 'stopping';
|
|
147
156
|
if (finished) {
|
|
148
157
|
this._statements.run('UPDATE agent_hq_action SET completion = ?, updated_at = ? WHERE thread_id = ? AND native_turn_id = ? AND completion IS NULL', finished.state, now, thread.id, finished.nativeTurnId);
|
package/docs/recovery.md
CHANGED
|
@@ -54,7 +54,7 @@ Async question subscriptions are ephemeral. Recreate the host's `observeAsyncInp
|
|
|
54
54
|
|
|
55
55
|
A quarantined session can still be monitored while a CLI runs it. Native observations update its live state without recovering ownership; the summary keeps uncertain ownership and its existing managed identity. Monitoring sends no input and leaves the control ledger and earlier queued entries unchanged.
|
|
56
56
|
|
|
57
|
-
A shared Codex daemon restart can interrupt every managed Codex session's live connection while HQ stays running. The runtime rechecks only its previously controlled sessions with no action in flight and rejoins
|
|
57
|
+
A shared Codex daemon restart can interrupt every managed Codex session's live connection while HQ stays running. The runtime rechecks only its previously controlled sessions with no action in flight and rejoins verified native turns without changing settings or repeating input. Matching-turn completions advance their waiting queues. A stable changed turn restores control while earlier receipts remain unresolved and earlier queues stay paused, including through later reconnects. Pending submissions are excluded, and unknown state or a turn changing during the join stays uncertain. The same policy applies to previously managed sessions retained at runtime restart; existing uncertain or externally discovered identities are never automatically adopted. Native turn IDs cannot distinguish a daemon continuation from another client's work or establish exclusive control, so keep competing controllers closed. Native command handles may have been lost, so rejoining establishes session control rather than successful command execution. See [runtime lifecycle](../api/README.md#runtime-lifecycle).
|
|
58
58
|
|
|
59
59
|
For a known Codex session left uncertain, inspect its native identity and close competing controllers before explicit recovery. The current HQ runtime can recover it once no action remains in flight; restarting HQ is unnecessary. Other recovery modes and providers retain their stopped-producing-runtime requirement. `thread-recover` with `recovery: { kind: 'resume' }` can rejoin its already known Codex identity whether unloaded or still held idle or active. The verified current turn is bound before joining and checked again afterward; no settings or input are sent. Reissued approvals can then be answered explicitly. Earlier queued entries stay paused, uncertain input receipts stay unresolved, and unknown state or a turn changing during the join leaves control uncertain. Never use attach/create to replace a known native identity or replay work to recover control.
|
|
60
60
|
|
package/package.json
CHANGED