jg-agent-hq 13.5.8 → 13.5.10
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 +10 -0
- package/api/README.md +4 -2
- package/dist/actions/reattach/reattach.js +28 -2
- package/dist/providers/claude/control/diagnostics.d.ts +3 -1
- package/dist/providers/claude/control/diagnostics.js +46 -9
- package/dist/providers/claude/control/stream.d.ts +3 -3
- package/dist/providers/claude/control/stream.js +13 -6
- package/docs/recovery.md +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 13.5.10
|
|
4
|
+
|
|
5
|
+
- Keep Claude control when a valid result arrives without a user-message UUID and without an active turn. Empty cycles produce no live turn or completion notice, and any input still waiting for replay completes under its own identity.
|
|
6
|
+
- Include bounded result-shape metadata in empty-cycle and rejection diagnostics. Malformed results and conflicting turn or input evidence still quarantine the controller.
|
|
7
|
+
|
|
8
|
+
## 13.5.9
|
|
9
|
+
|
|
10
|
+
- Retain Codex control when the same controller records a valid native recovery turn while rejoining after a connection loss or runtime restart. Reconcile the observed turn instead of quarantining it against the pre-join snapshot.
|
|
11
|
+
- Keep unverified and overlapping turn changes quarantined, earlier receipts unchanged and queued input paused, without repeating input, settings or native joins.
|
|
12
|
+
|
|
3
13
|
## 13.5.8
|
|
4
14
|
|
|
5
15
|
- Keep informational Codex messages in the transcript and out of question observers when their async delivery carries no questions. Preserve validation for question bundles.
|
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. 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
|
|
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 turn that changes during the join is retained only when the same controller's ordered native events already recorded that exact turn and state, with no action in flight. This reconciliation sends no input, repeats no join or events and does not release earlier queued input. Unverified, unobserved or overlapping transitions stay 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
|
|
|
@@ -407,6 +407,8 @@ Codex leaves `reasoning` items out as it reads them, so a Codex page can hold fe
|
|
|
407
407
|
|
|
408
408
|
Controller setup uses the managed record's existing `creating` preparation state for creation, adoption, resume and recovery. Until native readiness its session state is unknown, rather than a running inference turn. Readiness alone records `opened`, never `turn-completed`; `starting` is reserved for an action that actually submits turn input. Verified existing turns and autonomous native output still record their actual lifecycle.
|
|
409
409
|
|
|
410
|
+
A structurally valid Claude result with no user-message UUID and no active turn ends an empty autonomous cycle. It adds no turn transitions or live items, and leaves any written input waiting for its own replay and result. Background-command observations continue independently. A result without a UUID during an active HQ input remains a control conflict.
|
|
411
|
+
|
|
410
412
|
Every session has a live state: `running`, `waiting` (on the operator), `idle`, `closed`, `failed` or `unknown`. A managed session reports it from its managed record. A session another client drives is observed and listed with `ownership: 'external'`; the runtime sends it no input until `thread-adopt` records it as managed, and never stops, wakes or drives a session a terminal runs. A managed session the runtime closed is observed again, so a terminal that continues it shows its state.
|
|
411
413
|
|
|
412
414
|
A retained session with uncertain ownership also takes its live state from native observation, including loaded Codex sessions found at startup and later status changes. Thread reads, discovery and active-session summaries retain its managed ID and `ownership: 'uncertain'`. Observation never changes its control record, settles uncertain input, advances queued input or restores execution authority. Without a native observation its state remains unknown; explicit recovery is still required to regain control.
|
|
@@ -546,7 +548,7 @@ Use `models --provider <id>` for native model and effort choices, and `configura
|
|
|
546
548
|
|
|
547
549
|
Native execution settings, instructions, skills and tool permissions remain with each CLI. Claude uses an owned structured process per controlled session, closes it after 60 idle minutes and reopens it for the next input, and steers its active turn with a structured user message. Close other CLI controllers before confirming adoption, resume or recovery. The runtime coordinates sessions sharing one state directory; it cannot lock independently running native CLIs. Integrating browser hosts can use durable host-action admission and operator-scoped reconciliation through the programmatic API; see the [browser host contract](../api/README.md#browser-host-integration). The standalone CLI advertises only commands it implements.
|
|
548
550
|
|
|
549
|
-
When Claude sends
|
|
551
|
+
When Claude sends conflicting turn evidence or other evidence HQ cannot interpret, HQ suspends that session's controls and live interpretation while its native work continues. Empty autonomous cycles and rejected results report bounded diagnostics with validated correlation IDs, known subtype or a fingerprint of a short unfamiliar subtype, error flag, turn count, and duration/usage presence. The diagnostics omit native content. 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.
|
|
550
552
|
|
|
551
553
|
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.
|
|
552
554
|
|
|
@@ -57,12 +57,38 @@ export const createReattach = (context, dispatcher, events) => {
|
|
|
57
57
|
return;
|
|
58
58
|
own(thread.provider, nativeId);
|
|
59
59
|
isOwned = true;
|
|
60
|
+
const liveKey = key(thread.provider, nativeId);
|
|
61
|
+
const owner = context.controlled.get(liveKey);
|
|
60
62
|
const joined = await control.reattachThread(`${randomUUID()}:reattach`, nativeId, thread.workspaceRoot);
|
|
61
63
|
assertKnownTurn(joined);
|
|
62
64
|
const turnId = bound.thread.activeTurnId;
|
|
63
65
|
const latest = joined.latestTurn;
|
|
64
|
-
if ((latest?.nativeId ?? null) !== (read.latestTurn?.nativeId ?? null))
|
|
65
|
-
|
|
66
|
+
if ((latest?.nativeId ?? null) !== (read.latestTurn?.nativeId ?? null)) {
|
|
67
|
+
if (!latest)
|
|
68
|
+
agentUnavailable();
|
|
69
|
+
// Codex can interrupt the old turn and start its recovery while the join is in flight.
|
|
70
|
+
// Accept only the transition this same controller already recorded, without replaying it.
|
|
71
|
+
await state.lane;
|
|
72
|
+
const current = await store.call('reads', 'getThread', thread.id);
|
|
73
|
+
const recorded = await store.call('reads', 'getTurnRecord', thread.provider, nativeId);
|
|
74
|
+
const hasObservedTurn = latest.state === 'running'
|
|
75
|
+
? current?.activeTurnId === latest.nativeId &&
|
|
76
|
+
recorded?.activeTurnId === latest.nativeId
|
|
77
|
+
: current?.activeTurnId === null &&
|
|
78
|
+
current.state === latest.state &&
|
|
79
|
+
recorded?.lastTurnId === latest.nativeId;
|
|
80
|
+
if (state.isClosing ||
|
|
81
|
+
state.isUnavailable ||
|
|
82
|
+
context.blockedProviders.has(thread.provider) ||
|
|
83
|
+
context.controlled.get(liveKey) !== owner ||
|
|
84
|
+
current?.ownership !== 'managed' ||
|
|
85
|
+
current.runtimeEpoch !== epoch ||
|
|
86
|
+
current.nativeId !== nativeId ||
|
|
87
|
+
recorded?.hasPendingAction !== false ||
|
|
88
|
+
!hasObservedTurn)
|
|
89
|
+
agentUnavailable();
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
66
92
|
if (turnId && latest?.nativeId === turnId && latest.state !== 'running') {
|
|
67
93
|
const { state: turnState } = latest;
|
|
68
94
|
live.completeTurn(key(thread.provider, nativeId), turnId);
|
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import type { IClaudeSession } from './types.js';
|
|
2
2
|
/** Reports one rejected result without exposing prompts, output, paths or parser payloads. */
|
|
3
|
-
export declare const reportRejectedClaudeResult: (session: IClaudeSession, result: unknown, reason: "invalid-result" | "
|
|
3
|
+
export declare const reportRejectedClaudeResult: (session: IClaudeSession, result: unknown, reason: "invalid-result" | "missing-input-uuid" | "input-mismatch") => void;
|
|
4
|
+
/** Reports an autonomous cycle that finished without opening a live turn. */
|
|
5
|
+
export declare const reportEmptyClaudeCycle: (session: IClaudeSession, result: unknown) => void;
|
|
@@ -1,7 +1,23 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
1
2
|
import { z } from 'zod';
|
|
2
|
-
//
|
|
3
|
+
// keep result diagnostics independent of structural validation so malformed results are visible too
|
|
3
4
|
const MAX_DIAGNOSTIC_IDS = 64;
|
|
4
|
-
const
|
|
5
|
+
const ResultDiagnosticSchema = z.object({
|
|
6
|
+
user_message_uuid: z.unknown().optional(),
|
|
7
|
+
subtype: z.unknown().optional(),
|
|
8
|
+
is_error: z.unknown().optional(),
|
|
9
|
+
num_turns: z.unknown().optional(),
|
|
10
|
+
duration_api_ms: z.unknown().optional(),
|
|
11
|
+
usage: z.unknown().optional(),
|
|
12
|
+
});
|
|
13
|
+
const KnownSubtypeSchema = z.enum([
|
|
14
|
+
'success',
|
|
15
|
+
'error_during_execution',
|
|
16
|
+
'error_max_turns',
|
|
17
|
+
'error_max_budget_usd',
|
|
18
|
+
'error_max_structured_output_retries',
|
|
19
|
+
]);
|
|
20
|
+
const TurnCountSchema = z.int().nonnegative();
|
|
5
21
|
const uuidOrNull = (candidate) => {
|
|
6
22
|
const parsed = z.uuid().safeParse(candidate);
|
|
7
23
|
return parsed.success ? parsed.data : null;
|
|
@@ -19,17 +35,38 @@ const collectIds = (identities) => {
|
|
|
19
35
|
}
|
|
20
36
|
return selected;
|
|
21
37
|
};
|
|
22
|
-
/**
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
38
|
+
/**
|
|
39
|
+
* Projects safe result metadata. Short unfamiliar subtypes get a stable fingerprint so repeated
|
|
40
|
+
* observations can be matched without copying arbitrary provider strings into logs.
|
|
41
|
+
*/
|
|
42
|
+
const describeResult = (session, result) => {
|
|
43
|
+
const { data: metadata } = ResultDiagnosticSchema.safeParse(result);
|
|
44
|
+
const subtype = metadata?.subtype;
|
|
45
|
+
const knownSubtype = KnownSubtypeSchema.safeParse(subtype);
|
|
46
|
+
return {
|
|
27
47
|
sessionId: uuidOrNull(session.id),
|
|
28
|
-
userMessageUuid:
|
|
48
|
+
userMessageUuid: uuidOrNull(metadata?.user_message_uuid),
|
|
49
|
+
hasUserMessageUuid: metadata?.user_message_uuid !== undefined,
|
|
29
50
|
inputId: uuidOrNull(session.input?.id),
|
|
30
51
|
nativeTurnId: uuidOrNull(session.nativeTurn?.id),
|
|
31
52
|
pendingSteerCount: session.steers.size,
|
|
32
53
|
pendingSteerIds: collectIds(session.steers.keys()),
|
|
33
54
|
replayedSteerIds: collectIds(session.replayedSteers ?? []),
|
|
34
|
-
|
|
55
|
+
subtype: knownSubtype.success ? knownSubtype.data : null,
|
|
56
|
+
subtypeFingerprint: !knownSubtype.success && typeof subtype === 'string' && subtype.length <= 64
|
|
57
|
+
? createHash('sha256').update(subtype).digest('hex')
|
|
58
|
+
: null,
|
|
59
|
+
isError: typeof metadata?.is_error === 'boolean' ? metadata.is_error : null,
|
|
60
|
+
numTurns: TurnCountSchema.safeParse(metadata?.num_turns).data ?? null,
|
|
61
|
+
hasDurationApiMs: metadata?.duration_api_ms !== undefined,
|
|
62
|
+
hasUsage: metadata?.usage !== undefined,
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
/** Reports one rejected result without exposing prompts, output, paths or parser payloads. */
|
|
66
|
+
export const reportRejectedClaudeResult = (session, result, reason) => {
|
|
67
|
+
console.error('[jg-agent-hq] Claude result rejected', JSON.stringify({ reason, ...describeResult(session, result) }));
|
|
68
|
+
};
|
|
69
|
+
/** Reports an autonomous cycle that finished without opening a live turn. */
|
|
70
|
+
export const reportEmptyClaudeCycle = (session, result) => {
|
|
71
|
+
console.warn('[jg-agent-hq] Claude empty cycle completed', JSON.stringify(describeResult(session, result)));
|
|
35
72
|
};
|
|
@@ -20,9 +20,9 @@ export declare const setBackgroundCommands: (session: IClaudeSession, count: num
|
|
|
20
20
|
*/
|
|
21
21
|
export declare const failSteers: (session: IClaudeSession, turnId?: string, failure?: unknown) => void;
|
|
22
22
|
/**
|
|
23
|
-
* Normalizes native stream evidence without retaining another conversation buffer.
|
|
24
|
-
*
|
|
25
|
-
*
|
|
23
|
+
* Normalizes native stream evidence without retaining another conversation buffer. Autonomous
|
|
24
|
+
* output starts a native turn, and a valid UUID-free result with no active turn ends an empty
|
|
25
|
+
* cycle without publishing a turn or acknowledging input still waiting for replay.
|
|
26
26
|
* @throws
|
|
27
27
|
* - JG_AGENT_HQ_CLAUDE_FAILED: The Claude integration failed
|
|
28
28
|
*/
|
|
@@ -6,7 +6,7 @@ import { toTurnResult } from '../../results/index.js';
|
|
|
6
6
|
import { parseActionRequest } from '../../utilities.js';
|
|
7
7
|
import { HQ_ERRORS } from '../../../errors/index.js';
|
|
8
8
|
import { createClaudePrompt } from './permissions.js';
|
|
9
|
-
import { reportRejectedClaudeResult } from './diagnostics.js';
|
|
9
|
+
import { reportEmptyClaudeCycle, reportRejectedClaudeResult } from './diagnostics.js';
|
|
10
10
|
const FrameSchema = z.object({
|
|
11
11
|
type: z.string(),
|
|
12
12
|
session_id: z.string().optional(),
|
|
@@ -270,9 +270,9 @@ const resolveRequests = (session, message, events) => {
|
|
|
270
270
|
}
|
|
271
271
|
};
|
|
272
272
|
/**
|
|
273
|
-
* Normalizes native stream evidence without retaining another conversation buffer.
|
|
274
|
-
*
|
|
275
|
-
*
|
|
273
|
+
* Normalizes native stream evidence without retaining another conversation buffer. Autonomous
|
|
274
|
+
* output starts a native turn, and a valid UUID-free result with no active turn ends an empty
|
|
275
|
+
* cycle without publishing a turn or acknowledging input still waiting for replay.
|
|
276
276
|
* @throws
|
|
277
277
|
* - JG_AGENT_HQ_CLAUDE_FAILED: The Claude integration failed
|
|
278
278
|
*/
|
|
@@ -402,13 +402,20 @@ export const receiveClaudeMessage = (session, raw, events) => {
|
|
|
402
402
|
}
|
|
403
403
|
const result = parsedResult.data;
|
|
404
404
|
observeFastMode(session, raw);
|
|
405
|
+
if (result.user_message_uuid === undefined && getActiveTurn(session) === undefined) {
|
|
406
|
+
// an empty cycle never started a turn, so the waiting input and idle steer deadline still apply
|
|
407
|
+
delete session.apiMessageId;
|
|
408
|
+
endTurn(session, events);
|
|
409
|
+
reportEmptyClaudeCycle(session, raw);
|
|
410
|
+
return;
|
|
411
|
+
}
|
|
405
412
|
// a turn Claude started, or one a steer runs after its turn, has no action to capture its result
|
|
406
413
|
if (result.user_message_uuid === undefined ||
|
|
407
414
|
result.user_message_uuid === session.nativeTurn?.id ||
|
|
408
415
|
(session.nativeTurn !== undefined && session.replayedSteers?.has(result.user_message_uuid))) {
|
|
409
416
|
const turn = session.nativeTurn;
|
|
410
417
|
if (!turn) {
|
|
411
|
-
reportRejectedClaudeResult(session,
|
|
418
|
+
reportRejectedClaudeResult(session, raw, 'missing-input-uuid');
|
|
412
419
|
unavailable();
|
|
413
420
|
}
|
|
414
421
|
if (result.user_message_uuid !== undefined)
|
|
@@ -427,7 +434,7 @@ export const receiveClaudeMessage = (session, raw, events) => {
|
|
|
427
434
|
}
|
|
428
435
|
const input = session.input;
|
|
429
436
|
if (!input || input.id !== result.user_message_uuid || session.nativeTurn) {
|
|
430
|
-
reportRejectedClaudeResult(session,
|
|
437
|
+
reportRejectedClaudeResult(session, raw, 'input-mismatch');
|
|
431
438
|
unavailable();
|
|
432
439
|
}
|
|
433
440
|
acknowledge(session, events);
|
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 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
|
|
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. A turn changing during the join retains control only when the same controller has already recorded that exact native transition and state, with no action in flight. This reconciliation repeats no native operation or events and leaves earlier queued input paused. Unknown, unobserved or overlapping transitions stay 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