agent-relay-codex 0.4.26 → 0.4.27

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.
@@ -932,7 +932,7 @@ async function start(args: string[]): Promise<void> {
932
932
  const statePath = join(sidecarDir, "live-state.json");
933
933
  const sidecarPid = spawnManagedSidecar({
934
934
  runDir,
935
- env: { ...env, AGENT_RELAY_CODEX_MANAGED: "1" },
935
+ env: { ...env, AGENT_RELAY_CODEX_MANAGED: "1", AGENT_RELAY_CODEX_ASSUME_LOADED_THREAD: "1" },
936
936
  sessionDir: sidecarDir,
937
937
  statePath,
938
938
  threadMode: "resume",
package/live-sidecar.ts CHANGED
@@ -33,6 +33,7 @@ interface Config {
33
33
  sandbox?: string;
34
34
  approvalMode: ApprovalMode;
35
35
  parentPid?: number;
36
+ assumeLoadedThread: boolean;
36
37
  }
37
38
 
38
39
  interface RuntimeState {
@@ -90,10 +91,14 @@ class CodexLiveSidecar {
90
91
  constructor(private readonly config: Config) {
91
92
  this.relay = new RelayClient(config.relayUrl, (msg) => this.log(msg));
92
93
  this.app = this.createAppClient();
94
+ this.threadId = config.threadId || "";
93
95
  }
94
96
 
95
97
  async run(): Promise<void> {
96
98
  mkdirSync(dirname(this.config.statePath), { recursive: true });
99
+ if (this.config.assumeLoadedThread && this.config.threadId) {
100
+ this.log(`assuming remote TUI thread ${this.config.threadId} is already loaded`);
101
+ }
97
102
 
98
103
  process.on("SIGINT", () => void this.stop("SIGINT"));
99
104
  process.on("SIGTERM", () => void this.stop("SIGTERM"));
@@ -231,7 +236,7 @@ class CodexLiveSidecar {
231
236
  }
232
237
 
233
238
  const thread = this.threadId
234
- ? await this.resumeKnownThread(this.threadId)
239
+ ? await this.attachKnownThread(this.threadId)
235
240
  : await this.resolveThread();
236
241
  this.threadId = thread.id;
237
242
  this.syncThreadState(thread);
@@ -278,7 +283,11 @@ class CodexLiveSidecar {
278
283
  }
279
284
  }
280
285
 
281
- private async resumeKnownThread(threadId: string): Promise<Thread> {
286
+ private async attachKnownThread(threadId: string): Promise<Thread> {
287
+ if (this.config.assumeLoadedThread) {
288
+ return this.readThreadWithFallback(threadId).catch(() => syntheticLoadedThread(threadId, this.config.cwd));
289
+ }
290
+
282
291
  try {
283
292
  const resumed = await this.app.threadResume({
284
293
  threadId,
@@ -288,6 +297,13 @@ class CodexLiveSidecar {
288
297
  });
289
298
  return normalizeThread(resumed.thread);
290
299
  } catch (error) {
300
+ if (isThreadMissingRolloutError(error)) {
301
+ try {
302
+ return await this.readThreadWithFallback(threadId);
303
+ } catch {
304
+ // Fall through to normal resolution when the thread is neither loaded nor persisted.
305
+ }
306
+ }
291
307
  this.log(`resume failed for thread ${threadId}: ${describeError(error)}; falling back to thread resolution`);
292
308
  this.threadId = "";
293
309
  return this.resolveThread();
@@ -713,10 +729,25 @@ function normalizeThread(thread: Thread): Thread {
713
729
  };
714
730
  }
715
731
 
732
+ function syntheticLoadedThread(threadId: string, cwd: string): Thread {
733
+ return {
734
+ id: threadId,
735
+ cwd,
736
+ status: { type: "idle" },
737
+ updatedAt: Date.now(),
738
+ preview: "",
739
+ turns: [],
740
+ };
741
+ }
742
+
716
743
  function isThreadMaterializationError(error: unknown): boolean {
717
744
  return describeError(error).includes("not materialized yet");
718
745
  }
719
746
 
747
+ function isThreadMissingRolloutError(error: unknown): boolean {
748
+ return describeError(error).includes("no rollout found for thread id");
749
+ }
750
+
720
751
  function describeError(error: unknown): string {
721
752
  return error instanceof Error ? error.message : String(error);
722
753
  }
@@ -779,6 +810,7 @@ export function loadConfig(env: NodeJS.ProcessEnv = process.env): Config {
779
810
  sandbox: env.AGENT_RELAY_CODEX_SANDBOX,
780
811
  }),
781
812
  parentPid: envNumber(env, "AGENT_RELAY_CODEX_PARENT_PID", 0) || undefined,
813
+ assumeLoadedThread: env.AGENT_RELAY_CODEX_ASSUME_LOADED_THREAD === "1" || env.AGENT_RELAY_CODEX_ASSUME_LOADED_THREAD === "true",
782
814
  };
783
815
  }
784
816
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-relay-codex",
3
- "version": "0.4.26",
3
+ "version": "0.4.27",
4
4
  "description": "Codex integration for Agent Relay — auto-registers sessions as agents and enables inter-agent messaging",
5
5
  "type": "module",
6
6
  "bin": {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-relay",
3
- "version": "0.4.26",
3
+ "version": "0.4.27",
4
4
  "description": "Agent Relay integration for Codex sessions",
5
5
  "author": {
6
6
  "name": "Edin Mujkanovic"