Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/daemon/run-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ export const cancelRun = (runId: string): boolean => {
};

export const sendInput = (runId: string, text: string): boolean => {
if (!text || typeof text !== 'string') return false;
const tracked = runs.get(runId);
if (!tracked) return false;
if (tracked.run.state !== 'input_required') return false;
Expand Down
13 changes: 13 additions & 0 deletions src/daemon/websocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,19 @@ const bufferMessage = (runId: string, msg: BufferedMessage): void => {
const replayBuffer = (ws: WebSocket, runId: string): void => {
const buf = runBuffers.get(runId);
if (!buf) return;

// B3: Extend TTL when a client subscribes to prevent race between
// buffer expiry and replay delivery
const existingTimer = bufferTimers.get(runId);
if (existingTimer) {
clearTimeout(existingTimer);
const timer = setTimeout(() => {
runBuffers.delete(runId);
bufferTimers.delete(runId);
}, BUFFER_TTL_MS);
bufferTimers.set(runId, timer);
}

logDebug(`Replaying ${buf.length} buffered messages for run ${runId}`);
for (const msg of buf) {
sendToClient(ws, msg);
Expand Down
5 changes: 5 additions & 0 deletions src/hub/reconnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ export const createReconnector = (opts: ReconnectorOptions): Reconnector => {
let currentDelay = initialDelay;
let timer: ReturnType<typeof setTimeout> | null = null;
let stopped = false;
let running = false;

const attempt = async (): Promise<void> => {
if (stopped) return;

try {
await opts.onReconnect();
currentDelay = initialDelay;
running = false;
} catch (err) {
opts.onError?.(err);
timer = setTimeout(() => {
Expand All @@ -36,12 +38,15 @@ export const createReconnector = (opts: ReconnectorOptions): Reconnector => {

return {
start: () => {
if (running) return;
stopped = false;
running = true;
attempt();
},

stop: () => {
stopped = true;
running = false;
if (timer) {
clearTimeout(timer);
timer = null;
Expand Down