ScuttleBot
fix: apply mirror retry loop to codex-relay too
Commit
1f8b57e932716252dcb5945d27ab9b161554ca9659fd486ea5139f86618a9839
Parent
321167eca720bcc…
1 file changed
+24
-16
+24
-16
| --- cmd/codex-relay/main.go | ||
| +++ cmd/codex-relay/main.go | ||
| @@ -790,26 +790,34 @@ | ||
| 790 | 790 | sum := crc32.ChecksumIEEE([]byte(fmt.Sprintf("%s|%d|%d|%d", target, os.Getpid(), os.Getppid(), time.Now().UnixNano()))) |
| 791 | 791 | return fmt.Sprintf("%08x", sum) |
| 792 | 792 | } |
| 793 | 793 | |
| 794 | 794 | func mirrorSessionLoop(ctx context.Context, relay sessionrelay.Connector, cfg config, startedAt time.Time) { |
| 795 | - sessionPath, err := discoverSessionPath(ctx, cfg, startedAt) | |
| 796 | - if err != nil { | |
| 797 | - if ctx.Err() == nil { | |
| 798 | - _ = relay.Post(context.Background(), fmt.Sprintf("mirror failed: %v — session activity not visible in IRC", err)) | |
| 799 | - } | |
| 800 | - return | |
| 801 | - } | |
| 802 | - if err := tailSessionFile(ctx, sessionPath, cfg.MirrorReasoning, func(text string) { | |
| 803 | - for _, line := range splitMirrorText(text) { | |
| 804 | - if line == "" { | |
| 805 | - continue | |
| 806 | - } | |
| 807 | - _ = relay.Post(ctx, line) | |
| 808 | - } | |
| 809 | - }); err != nil && ctx.Err() == nil { | |
| 810 | - _ = relay.Post(context.Background(), fmt.Sprintf("mirror lost: %v — session activity no longer visible in IRC", err)) | |
| 795 | + for { | |
| 796 | + if ctx.Err() != nil { | |
| 797 | + return | |
| 798 | + } | |
| 799 | + sessionPath, err := discoverSessionPath(ctx, cfg, startedAt) | |
| 800 | + if err != nil { | |
| 801 | + if ctx.Err() != nil { | |
| 802 | + return | |
| 803 | + } | |
| 804 | + time.Sleep(10 * time.Second) | |
| 805 | + continue | |
| 806 | + } | |
| 807 | + if err := tailSessionFile(ctx, sessionPath, cfg.MirrorReasoning, func(text string) { | |
| 808 | + for _, line := range splitMirrorText(text) { | |
| 809 | + if line == "" { | |
| 810 | + continue | |
| 811 | + } | |
| 812 | + _ = relay.Post(ctx, line) | |
| 813 | + } | |
| 814 | + }); err != nil && ctx.Err() == nil { | |
| 815 | + time.Sleep(5 * time.Second) | |
| 816 | + continue | |
| 817 | + } | |
| 818 | + return | |
| 811 | 819 | } |
| 812 | 820 | } |
| 813 | 821 | |
| 814 | 822 | func discoverSessionPath(ctx context.Context, cfg config, startedAt time.Time) (string, error) { |
| 815 | 823 | root, err := codexSessionsRoot() |
| 816 | 824 |
| --- cmd/codex-relay/main.go | |
| +++ cmd/codex-relay/main.go | |
| @@ -790,26 +790,34 @@ | |
| 790 | sum := crc32.ChecksumIEEE([]byte(fmt.Sprintf("%s|%d|%d|%d", target, os.Getpid(), os.Getppid(), time.Now().UnixNano()))) |
| 791 | return fmt.Sprintf("%08x", sum) |
| 792 | } |
| 793 | |
| 794 | func mirrorSessionLoop(ctx context.Context, relay sessionrelay.Connector, cfg config, startedAt time.Time) { |
| 795 | sessionPath, err := discoverSessionPath(ctx, cfg, startedAt) |
| 796 | if err != nil { |
| 797 | if ctx.Err() == nil { |
| 798 | _ = relay.Post(context.Background(), fmt.Sprintf("mirror failed: %v — session activity not visible in IRC", err)) |
| 799 | } |
| 800 | return |
| 801 | } |
| 802 | if err := tailSessionFile(ctx, sessionPath, cfg.MirrorReasoning, func(text string) { |
| 803 | for _, line := range splitMirrorText(text) { |
| 804 | if line == "" { |
| 805 | continue |
| 806 | } |
| 807 | _ = relay.Post(ctx, line) |
| 808 | } |
| 809 | }); err != nil && ctx.Err() == nil { |
| 810 | _ = relay.Post(context.Background(), fmt.Sprintf("mirror lost: %v — session activity no longer visible in IRC", err)) |
| 811 | } |
| 812 | } |
| 813 | |
| 814 | func discoverSessionPath(ctx context.Context, cfg config, startedAt time.Time) (string, error) { |
| 815 | root, err := codexSessionsRoot() |
| 816 |
| --- cmd/codex-relay/main.go | |
| +++ cmd/codex-relay/main.go | |
| @@ -790,26 +790,34 @@ | |
| 790 | sum := crc32.ChecksumIEEE([]byte(fmt.Sprintf("%s|%d|%d|%d", target, os.Getpid(), os.Getppid(), time.Now().UnixNano()))) |
| 791 | return fmt.Sprintf("%08x", sum) |
| 792 | } |
| 793 | |
| 794 | func mirrorSessionLoop(ctx context.Context, relay sessionrelay.Connector, cfg config, startedAt time.Time) { |
| 795 | for { |
| 796 | if ctx.Err() != nil { |
| 797 | return |
| 798 | } |
| 799 | sessionPath, err := discoverSessionPath(ctx, cfg, startedAt) |
| 800 | if err != nil { |
| 801 | if ctx.Err() != nil { |
| 802 | return |
| 803 | } |
| 804 | time.Sleep(10 * time.Second) |
| 805 | continue |
| 806 | } |
| 807 | if err := tailSessionFile(ctx, sessionPath, cfg.MirrorReasoning, func(text string) { |
| 808 | for _, line := range splitMirrorText(text) { |
| 809 | if line == "" { |
| 810 | continue |
| 811 | } |
| 812 | _ = relay.Post(ctx, line) |
| 813 | } |
| 814 | }); err != nil && ctx.Err() == nil { |
| 815 | time.Sleep(5 * time.Second) |
| 816 | continue |
| 817 | } |
| 818 | return |
| 819 | } |
| 820 | } |
| 821 | |
| 822 | func discoverSessionPath(ctx context.Context, cfg config, startedAt time.Time) (string, error) { |
| 823 | root, err := codexSessionsRoot() |
| 824 |