mirror of
https://github.com/bitbaum/loki.git
synced 2026-12-04 10:07:19 +01:00
fix(orchestration): emit task_completed alongside input_requested on ready sentinel
Lifecycle telemetry was half-wired. Across all time the orchestration_events
table had:
task_started: 336
input_requested: 352
continue_requested: 146
close_requested: 2
task_completed: 0 ← the gap
`task_completed` was a defined OrchestrationEventType in contract.ts but
no code ever wrote it. Every dispatch landed a task_started row, then
either an input_requested (when the agent signaled ready) or nothing
(stalled / closed / etc.) — leaving every started task in an indeterminate
end-state. Pair queries like "how many tasks completed in the last hour"
or "which started tasks never finished" weren't answerable.
Root cause in collectRuntimeLifecycleEvents: when runtime.readyAt fires
it only pushed input_requested. Semantically the "ready" sentinel means
TWO things simultaneously — the agent is done with the current task AND
is waiting for the next input. Emit both events from the same timestamp
so the lifecycle pair closes:
• input_requested → drives the UI ready-banner via deriveLifecycleState
(existing consumer, unchanged)
• task_completed → closes the started/completed pair for queries
shouldPersistLifecycleEvent dedupes per-type so we won't double-write
on subsequent control polls — the second emit is no-op once the table
has a row. No code consumes task_completed yet, so this is forward-only
instrumentation: future commits can answer dispatch-success rate, MTTR
on agent runs, etc., without bookkeeping changes elsewhere.
Cost: doubles the row count for the readyAt code path (~336 lifetime
events → ~672). Trivial.
tsc + eslint + build clean.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 file changed
+12
@@ -65,7 +65,19 @@ export function collectRuntimeLifecycleEvents(runtime: RuntimeLifecycleFacts): R
|
||||
const events: RuntimeEventCandidate[] = [];
|
||||
|
||||
if (runtime.readyAt !== null) {
|
||||
// The "ready" sentinel means the agent is done with the current task
|
||||
// AND is waiting for the next input. Both terms are true at the same
|
||||
// instant, so emit both events from the single sentinel:
|
||||
// • input_requested — what the UI ready-banner / deriveLifecycleState consume
|
||||
// • task_completed — closes the task_started lifecycle pair so
|
||||
// orchestration_events queries can count
|
||||
// started vs. completed without double-bookkeeping
|
||||
// Prior to this, task_completed was a defined event type in the
|
||||
// contract but never written — across all-time the table had 336
|
||||
// task_started rows and zero task_completed, leaving every dispatch
|
||||
// in an indeterminate end-state from a telemetry POV.
|
||||
events.push({ type: "input_requested", at: runtime.readyAt, source: "runtime-sentinel" });
|
||||
events.push({ type: "task_completed", at: runtime.readyAt, source: "runtime-sentinel" });
|
||||
}
|
||||
if (runtime.closingAt !== null) {
|
||||
events.push({ type: "close_requested", at: runtime.closingAt, source: "runtime-sentinel" });
|
||||
|
||||
Reference in new issue
Block a user