From b12f522ca21af194cbaa70bd23949e31cd5b353e Mon Sep 17 00:00:00 2001 From: Hide_D Date: Sat, 27 Dec 2025 02:51:39 +0000 Subject: [PATCH] =?UTF-8?q?=EB=AC=B8=EC=84=9C=20=EC=88=98=EC=A0=95:=20?= =?UTF-8?q?=ED=84=B4=20=EB=8B=A4=EC=9D=B4=EC=95=84=EB=AA=AC=EB=93=9C=20?= =?UTF-8?q?=EC=83=9D=EB=AA=85=EC=A3=BC=EA=B8=B0=20=EB=AC=B8=EC=84=9C?= =?UTF-8?q?=EC=97=90=20API=20=EC=9A=94=EC=B2=AD=20=EC=B2=98=EB=A6=AC=20?= =?UTF-8?q?=EB=B0=8F=20=EC=9D=BC=EC=8B=9C=20=EC=A0=95=EC=A7=80/=EC=9E=AC?= =?UTF-8?q?=EA=B0=9C=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/architecture/turn-daemon-lifecycle.md | 23 +++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/docs/architecture/turn-daemon-lifecycle.md b/docs/architecture/turn-daemon-lifecycle.md index da47257..14f957d 100644 --- a/docs/architecture/turn-daemon-lifecycle.md +++ b/docs/architecture/turn-daemon-lifecycle.md @@ -36,12 +36,29 @@ Idle -> Running -> Flushing -> Idle ## Main Loop Sketch +The daemon interleaves API request handling between scheduled turn executions. +API requests are drained until the next turn time is reached; once the turn +starts, incoming requests are queued and processed after the run. + ```ts while (!stopping) { - await waitForNextTrigger(nextTurnTime, wakeSignal); + const signal = await waitForNextSignal(nextTurnTime, wakeSignal); + if (signal.type === 'pause') { + paused = true; + } + if (signal.type === 'resume') { + paused = false; + } if (paused || running) { continue; } + + await drainApiRequestsUntil(nextTurnTime); + + if (now() < nextTurnTime && signal.type !== 'run') { + continue; + } + running = true; try { await runUntil(now(), budget); @@ -53,6 +70,10 @@ while (!stopping) { } ``` +- `drainApiRequestsUntil()` processes queued user/admin requests and applies + them to in-memory state until the next scheduled turn time is reached. +- During `running`, new API requests are enqueued and handled after the run. + ## Run Budget and Checkpoints Replace PHP `max_execution_time` with explicit limits to allow partial progress: