The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 22, 09:30 UTC
fix(server): keep relay catch-up requests working after startup (#25201)
Co-authored-by: Alex Southwell <4596216+saphid@users.noreply.github.com>
maria committed
Oct 31, 2026 at 08:38 UTC
044775d69712ccdf018840e0a14c10eefddbb9ad
2 files changed
+39
-6
apps/server/src/relay/AgentAwarenessRelay.test.ts
+32
@@ -720,3 +720,35 @@ describe("AgentAwarenessRelay", () => {
720
),
721
);
722
});
723
+
724
+it.effect("catches up after startup without polling after success", () =>
725
+ Effect.gen(function* () {
726
+ const { relay, secrets, secretReads, catchUp } = yield* makeTestRelay();
727
+ yield* relay.start();
728
+ yield* TestClock.adjust("1 second");
729
+ assert.equal(catchUp.shellSnapshotReads, 1);
730
+
731
+ yield* secrets.set(PUBLISH_AGENT_ACTIVITY_SECRET, new TextEncoder().encode("false"));
732
+ yield* relay.requestCatchUp();
733
+ yield* TestClock.adjust("1 second");
734
+ assert.equal(catchUp.shellSnapshotReads, 1);
735
+
736
+ yield* secrets.set(PUBLISH_AGENT_ACTIVITY_SECRET, new TextEncoder().encode("true"));
737
+ yield* relay.requestCatchUp();
738
+ yield* TestClock.adjust("1 second");
739
+ assert.equal(catchUp.shellSnapshotReads, 2);
740
+
741
+ const readsBeforeIdle = secretReads.length;
742
+ yield* TestClock.adjust("10 minutes");
743
+ assert.equal(catchUp.shellSnapshotReads, 2);
744
+ assert.equal(secretReads.length, readsBeforeIdle);
745
+
746
+ yield* secrets.set(
747
+ RELAY_ENVIRONMENT_CREDENTIAL_SECRET,
748
+ new TextEncoder().encode("credential-2"),
749
+ );
750
+ yield* relay.requestCatchUp();
751
+ yield* TestClock.adjust("1 second");
752
+ assert.equal(catchUp.shellSnapshotReads, 3);
753
+ }).pipe(Effect.scoped),
754
+);
apps/server/src/relay/AgentAwarenessRelay.ts
+7
-6
@@ -369,7 +369,6 @@ export const make = Effect.gen(function* () {
369
const scope = yield* Effect.scope;
370
const cloudLinkKeyPair = yield* getOrCreateEnvironmentKeyPairFromSecretStore(secrets);
371
const startedAt = (yield* DateTime.now).epochMilliseconds;
372
- const activeSnapshotPublishedRef = yield* Ref.make(false);
372
const catchUpRequests = yield* Queue.dropping<void>(1);
373
const publishedStateByThreadRef = yield* Ref.make(new Map<ThreadId, string>());
374
@@ -759,23 +758,25 @@ export const make = Effect.gen(function* () {
758
// s to 60 s. A linked environment keeps the 5 s retry, because `t3 connect
759
// publish` can turn publishing on from another process. Keep this untraced:
760
// an unlinked environment can retry for the lifetime of the process.
762
- const publishActiveThreadsOnceWhenConfigured = Effect.fnUntraced(function* (
761
+ const publishActiveThreadsWhenConfigured = Effect.fnUntraced(function* (
762
logEnabledWhenReady: boolean,
763
) {
764
let unlinkedRetryDelayMs = 5_000;
766
- while (!(yield* Ref.get(activeSnapshotPublishedRef))) {
765
+ while (true) {
766
const result = yield* publishActiveThreadsUnsafe.pipe(
767
Effect.orElseSucceed(() => "failed" as const),
768
);
769
if (result === "published") {
771
- yield* Ref.set(activeSnapshotPublishedRef, true);
770
if (logEnabledWhenReady) {
771
const relayConfig = yield* readRelayConfig.pipe(Effect.orElseSucceed(() => null));
772
yield* Effect.logInfo("agent activity publishing enabled after link reconciliation", {
773
relayUrl: relayConfig?.url,
774
});
775
}
778
- return;
776
+ logEnabledWhenReady = false;
777
+ unlinkedRetryDelayMs = 5_000;
778
+ yield* Queue.take(catchUpRequests);
779
+ continue;
780
}
781
const retryDelayMs = result === "unlinked" ? unlinkedRetryDelayMs : 5_000;
782
yield* Effect.race(Effect.sleep(retryDelayMs), Queue.take(catchUpRequests));
@@ -826,7 +827,7 @@ export const make = Effect.gen(function* () {
827
}
828
yield* forkParked(
829
Effect.sleep("1 second").pipe(
829
- Effect.andThen(publishActiveThreadsOnceWhenConfigured(startupState !== "enabled")),
830
+ Effect.andThen(publishActiveThreadsWhenConfigured(startupState !== "enabled")),
831
),
832
);
833
yield* forkParked(