fix: gate session goal audits on live child activity

Re-checks authoritative session status after the quiet window
Skips auditing while a direct child session is still busy or retrying
Retries the quiet window when live status data is unavailable
This commit is contained in:
Bohdan Triapitsyn
2026-07-14 10:31:23 +03:00
parent 4c27f1753d
commit fb98edda45
3 changed files with 210 additions and 0 deletions
@@ -78,6 +78,13 @@ before touching the filesystem). Rationale: metadata rides every
a goal on an idle session emits no status transition.
3. On fire (`tick`), gated by the `sessionGoalEnabled` setting:
- fetch session (skip sub-agent sessions), require an `active` goal;
- authoritative live-activity check after the quiet window: re-read the
session status map, bail if the parent resumed, then list direct child
sessions and bail while any child is `busy`/`retry`. A background
subagent leaves its parent idle, then injects its result into the parent
when done; that parent `busy` → `idle` cycle re-arms the loop without
polling. Status/children fetch failure is unknown, not empty, so it skips
the audit and retries after another quiet window;
- quiescence check via the message tail (trailing user message or
unfinished assistant reply → bail; the next idle transition re-arms);
- token accounting as a SNAPSHOT of the latest completed assistant turn: