Repository navigation
feat(nudges): proactive progress nudges during long-running turns (ENG-16200) - #68
Conversation
…G-16200) While an agent turn exceeds a config-driven duration threshold, proactively post short "still working on X…" messages to the user's active channel (Slack/Teams/Boon UI) so a long batch/analysis never goes silent, capped by interval + a max count. On a failed/stalled run that had gone long, post one failure + next-step message instead of vanishing. Fast turns below the threshold get no nudge; completion is the normal final reply. Reuses the existing outbound layer (sendDurableMessageBatch + target:"last"), the agent-event bus (progressText = the "working on X" content), and the reply-run registry — no new per-channel send path. The scheduler mirrors startHeartbeatRunner: a self-rearming, unref'd poll loop with per-sessionKey bookkeeping and injectable deps for tests. - src/infra/progress-nudge-runner.ts: the runner (new). - reply-run-registry.ts: additive startedAt + resolveActiveReplyRunStartedAt + onReplyRunTerminal (single terminal signal so failure detection can't miss a fail() that clears the session key before the next poll). - config: agents.defaults.progressNudge block (default enabled:false — upgrade-safe), type + zod schema. - server-runtime-services.ts: start beside the heartbeat runner, composed into its handle so existing stop/updateConfig plumbing drives both. Tests: scheduler (threshold/interval/maxNudges/generic/stop/disabled/final-reply race/no-target), error-nudge (once/abort/completed/fast-fail), concurrent (per-session routing), config schema, registry hooks. All green; tsgo:core + oxlint clean. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…s DRY (ENG-16200) Code-review fixes: - progress-nudge-runner: the final-reply-race guard skipped ALL non-"running" phases, which wrongly suppressed nudges during memory_flushing / preflight_compacting — legitimate long waits that are exactly the silent gaps this feature targets. Now skips only TERMINAL phases (completed/failed/ aborted). Added a test that a nudge still fires during memory_flushing. - reply-run-registry: testing.resetReplyRunRegistry() now clears the terminal listener Set (mirrors resetAgentEventsForTest) so a runner a test forgot to stop() can't leak a listener across tests. Added a regression test. - zod-schema.agent-runtime: extracted the duplicated activeHours HH:MM validator into a shared ActiveHoursSchema used by both HeartbeatSchema and ProgressNudgeSchema (removes ~35 lines of copy-paste; error paths unchanged). tsgo:core + oxlint clean; affected suites green. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
There was a problem hiding this comment.
cubic analysis
3 issues found across 11 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="src/config/types.agent-defaults.ts">
<violation number="1" location="src/config/types.agent-defaults.ts:468">
P3: Extract the duplicated activeHours inline type into a shared ActiveHoursSchema type alias and reuse it for both heartbeat.activeHours and progressNudge.activeHours. This matches the PR description's stated intent and avoids drift if the shape changes later.</violation>
</file>
<file name="src/infra/progress-nudge-runner.ts">
<violation number="1" location="src/infra/progress-nudge-runner.ts:223">
P2: Long-running turns do not receive the required up-front acknowledgment: this runner explicitly returns until the threshold and has no start-time message path. According to linked Linear issue ENG-16200, the agent should acknowledge the task before waiting for the first progress threshold; wiring an acknowledgment into the run-start hook would satisfy that requirement without waiting 45 seconds.</violation>
<violation number="2" location="src/infra/progress-nudge-runner.ts:253">
P2: A progress nudge can race past the final reply: the terminal-phase check happens before an asynchronous target/send operation, and the send is not cancelled or revalidated afterward. If the run completes during that await, the nudge may arrive after the final response. Capturing a per-run generation and checking/cancelling it through delivery would keep terminal output ordered.</violation>
</file>
Linked issue analysis
Linked issue: ENG-16200: Agent progress nudges during long-running processes — keep the user posted, don't go silent
| Status | Acceptance criteria | Notes |
|---|---|---|
| ✅ | Long-running tasks are detected via a config-driven threshold (duration/step count) | The PR adds a progressNudge config block (thresholdSeconds) and the runner gates nudges on the configured threshold. Tests exercise threshold gating. |
| ✅ | Agent emits progress nudges at capped intervals/milestones during execution (interval config-driven, maxNudges cap) | The runner enforces interval and maxNudges and emits 'still working' messages; tests verify interval gating and maxNudges behavior. |
| Agent sends a clear completion nudge with the result on success | The PR documents that completion is delivered as the normal final reply (no separate completion message) rather than adding a distinct completion nudge. The runner focuses on interim 'still working' nudges and error nudges; there is no explicit new completion-message emission or tests asserting a separate completion nudge. | |
| ✅ | On mid-run error / stall / poisoned session, the agent proactively nudges the failure + next step (never goes silent) | The runner listens for terminal events and will send a single failure/next-step nudge for runs that had gone long. Tests validate error-nudge semantics and once-only behavior. |
| ✅ | Fast tasks below threshold do NOT get a 'still working' nudge | The runner suppresses nudges before the threshold and tests cover fast-failure/no-nudge cases. |
| Behavior is identical across Teams, Slack chat, and the Boon UI via existing messaging plumbing | The code reuses the existing heartbeat/delivery plumbing (resolveHeartbeatDeliveryTargetWithSessionRoute and sendDurableMessageBatch), which makes the feature channel-agnostic. Tests exercise delivery target resolution and a 'none' channel case, but do not explicitly assert identical UX on each named channel. | |
| ✅ | Reuse-not-rebuild: no new per-channel delivery path; hooks into existing task execution + message rendering | The runner hooks into the reply-run registry and agent-event bus and reuses the existing delivery/rendering plumbing rather than adding per-channel send paths. |
Tip: instead of fixing issues one by one fix them all with cubic
Re-trigger cubic
| } | ||
| entry.lastNudgeSentAtMs = nowMs; | ||
| entry.nudgeCount += 1; | ||
| await deliverNudge(sessionKey, renderProgressText(entry.progressText)); |
There was a problem hiding this comment.
P2: A progress nudge can race past the final reply: the terminal-phase check happens before an asynchronous target/send operation, and the send is not cancelled or revalidated afterward. If the run completes during that await, the nudge may arrive after the final response. Capturing a per-run generation and checking/cancelling it through delivery would keep terminal output ordered.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/infra/progress-nudge-runner.ts, line 253:
<comment>A progress nudge can race past the final reply: the terminal-phase check happens before an asynchronous target/send operation, and the send is not cancelled or revalidated afterward. If the run completes during that await, the nudge may arrive after the final response. Capturing a per-run generation and checking/cancelling it through delivery would keep terminal output ordered.</comment>
<file context>
@@ -0,0 +1,384 @@
+ }
+ entry.lastNudgeSentAtMs = nowMs;
+ entry.nudgeCount += 1;
+ await deliverNudge(sessionKey, renderProgressText(entry.progressText));
+ };
+
</file context>
There was a problem hiding this comment.
Considered and intentionally not adding a generation counter here. The in-turn nudge already has a pre-send terminal-phase guard (getRunPhase skips completed/failed/aborted), which closes the common race; a nudge that still slips through arrives a beat after the reply, which is acceptable for a 'still working' message. A full generation/cancel-through-delivery mechanism would diverge from the sibling heartbeat-runner (which has the same bounded-await shape and no such counter). Happy to add it if you feel strongly — flagging as a deliberate parity choice for a maintainer call.
| } | ||
| const elapsed = nowMs - startedAt; | ||
| // Fast-task suppression: nothing fires before the threshold. | ||
| if (elapsed < state.resolved.thresholdMs) { |
There was a problem hiding this comment.
P2: Long-running turns do not receive the required up-front acknowledgment: this runner explicitly returns until the threshold and has no start-time message path. According to linked Linear issue ENG-16200, the agent should acknowledge the task before waiting for the first progress threshold; wiring an acknowledgment into the run-start hook would satisfy that requirement without waiting 45 seconds.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/infra/progress-nudge-runner.ts, line 223:
<comment>Long-running turns do not receive the required up-front acknowledgment: this runner explicitly returns until the threshold and has no start-time message path. According to linked Linear issue ENG-16200, the agent should acknowledge the task before waiting for the first progress threshold; wiring an acknowledgment into the run-start hook would satisfy that requirement without waiting 45 seconds.</comment>
<file context>
@@ -0,0 +1,384 @@
+ }
+ const elapsed = nowMs - startedAt;
+ // Fast-task suppression: nothing fires before the threshold.
+ if (elapsed < state.resolved.thresholdMs) {
+ return;
+ }
</file context>
There was a problem hiding this comment.
Correct per the ticket, but the up-front acknowledgment is explicitly out of scope for this MVP (the PR description lists it as deferred). It needs a run-START hook (this runner is threshold-triggered by design), which is a separate wiring point. Tracked as a fast follow-up on the same runner. Leaving open for visibility.
…ix broken mocks (ENG-16200) Addresses #68 review + CI: - CI (check-test-types): adding required `startedAt` to ReplyOperation broke two pre-existing mock fixtures (agent-runner-execution/memory tests) — add startedAt:0. - CI (startup-health-runtime): the returned heartbeatRunner is now a composite of the heartbeat + progress-nudge runners; the test asserted exact-identity. Mock the nudge runner and assert the composed handle delegates stop()/updateConfig() to both. - P1 (failure between ticks): "went long" now derives from elapsed run time (terminal event's startedAt) instead of nudgeCount>0, so a run that crosses the threshold then fails BETWEEN poll ticks still gets its failure nudge. Added a regression test. - P2 (thread route): ReplyRunTerminalEvent now carries routeThreadId (+ startedAt), snapshotted at clear time; the terminal nudge delivers to that explicit route instead of a live registry lookup that returns undefined post-clear. - P2 (target:"none"): the terminal failure nudge is now gated on enabled && target !== "none", so a disabled delivery target suppresses it too. Added a test. tsgo:core + tsgo:core:test + oxlint clean; all affected suites green. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
There was a problem hiding this comment.
All reported issues were addressed across 7 files (changes from recent commits).
Reply with feedback, questions, or to request a fix.
Fix all with cubic | Re-trigger cubic
…(ENG-16200) handleTerminal computed elapsed with Date.now() directly, ignoring the runner's injected now() clock that the scheduler path already uses. A fake/custom-clock run could gate the error nudge differently from the rest of the runner. Use now() so terminal gating is clock-consistent and deterministic under test. #68 review (cubic P3). tsgo:core + oxlint clean; runner suites green. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…t double-nudge (ENG-16200) CI (checks-node-bundle-infra-small-3) caught a regression from the elapsed-based wentLong change: handleTerminal deleted the nudge bookkeeping entry right after firing the error nudge, but since wentLong is now elapsed-based (not entry- dependent), a second terminal event for the same session re-fired — the errorNudgeSent guard died with the deleted entry. Now the error-nudge path stamps and KEEPS the entry (creating one if the failure happened between ticks); the tick-prune reclaims it once the session is inactive. The common no-nudge terminal path still deletes immediately. Added a repeat-terminal regression test for the between-ticks case. (The `dispatch` job failure was downstream of this shard.) tsgo:core + oxlint clean; runner suites green (17/17). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
There was a problem hiding this comment.
Reviewed the full diff (ENG-16200). Approving.
What it does: self-rearming poll scheduler (progress-nudge-runner.ts, modeled on heartbeat-runner) that posts "still working on X…" nudges once a turn crosses a threshold, plus one failure+next-step nudge if a long run fails. Default off, upgrade-safe.
Strengths
- Cleanly observes the reply-run registry rather than wiring into the run lifecycle — can't leak a timer onto abort/restart paths. Good isolation.
- Reuses existing delivery (
sendDurableMessageBatch+ heartbeat target resolution) and the agent-event bus for progress text — no new per-channel send path, minimal surface. - Registry changes are purely additive (startedAt, resolveActiveReplyRunStartedAt, onReplyRunTerminal).
- Nice DRY: extracted shared
ActiveHoursSchemaso the 24:00 edge-case validation lives in one place for both heartbeat + nudge. - Terminal event carries startedAt + routeThreadId snapshot, so the failure gate is elapsed-based (catches a run that crosses threshold then fails between poll ticks) and stays attributable after the op leaves the registry.
- Fire-once error guard that deliberately outlives the handler; tick-prune reclaims it.
Tests — thorough on exactly the tricky edges: threshold suppression, interval cap, maxNudges, terminal-phase final-reply race, between-ticks failure, user-abort exclusion, target=none suppression (both in-turn + terminal), concurrent per-thread routing, listener cleanup, and full schema accept/reject cases.
CI: 106/106 checks green. No secrets in diff or history. No breaking migration (default enabled:false); rollout ordering (runtime before the gandalf-manager config PR) is correctly called out. Ship it.
Bump gateway + @openclaw/slack + @openclaw/msteams to 2026.6.11-boon.7 in lockstep (package.json + npm-shrinkwrap.json roots) and add the CHANGELOG entry. Ships the boon.7 train: #70 (ENG-16418 concise + A/B/C overlay for Claude), #68 (ENG-16200 progress nudges runtime, gated off by default), #69 (security dep bumps), #64 (ENG-16330 non-terminal recovered-tool-error badge). Base = 2026.6.11-boon.6. Only slack + msteams carry the -boon.N suffix; other extensions stay at plain 2026.6.11 (fork release does not run a blanket plugins:sync). Formatting proof: oxfmt --check clean on CHANGELOG.md; the six JSON files are oxfmt-excluded lockfile-class and byte-shape-identical to the boon.6 release commit. Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
Summary
While an agent turn runs long (multi-step sequence, big batch, long analysis), the agent now proactively posts short "still working on X…" messages to the user's active channel (Slack / Teams / Boon UI), so a long task never goes silent. On a long run that fails or stalls it posts one failure + next-step message instead of vanishing. Fast turns below the threshold get no nudge; completion is the normal final reply.
Implements ENG-16200. MVP scope — up-front acknowledgment and rich %/milestone progress are deferred to a follow-up.
Design
A new self-rearming poll scheduler
src/infra/progress-nudge-runner.ts, modeled onheartbeat-runner.ts. It reuses existing infrastructure rather than rebuilding delivery:sendDurableMessageBatch+resolveHeartbeatDeliveryTargetWithSessionRoute({ target: "last" })→ the user's active channel. No new per-channel send path.onAgentEvent, item/toolprogressText).It is deliberately not wired into the run lifecycle's control flow — it observes the registry, so it can't leak a timer onto the abort/restart paths.
Changes
src/infra/progress-nudge-runner.ts(new) — the scheduler.src/auto-reply/reply/reply-run-registry.ts— additive:startedAtonReplyOperation,resolveActiveReplyRunStartedAt, and anonReplyRunTerminallistener fired once per run fromclearReplyRunState(a poller can't observefailedreliably becausefail()clears the session key before the next tick).src/config/{types.agent-defaults,zod-schema.agent-runtime,zod-schema.agent-defaults}.ts— theagents.defaults.progressNudgeblock (defaultenabled: false— upgrade-safe; the fleet enables it via config, see the gandalf-manager PR). Extracted a sharedActiveHoursSchemareused by heartbeat + nudge.src/gateway/server-runtime-services.ts— starts the runner beside the heartbeat runner, composed into that handle so existing stop/reload plumbing drives both.Correctness notes
aborted_by_userandcompletednever error-nudge.completed/failed/aborted); legitimate long pre-run phases (memory_flushing,preflight_compacting) still nudge.Tests
src/infra/progress-nudge-runner.{scheduler,error-nudge,concurrent}.test.ts,reply-run-registry.progress-nudge-hooks.test.ts, and config-schema cases. All green;pnpm tsgo:core+ oxlint clean.Rollout ordering⚠️
This ships the runtime + config schema only (default off). The fleet enables it via config in a separate gandalf-manager PR, which must land only after this is released and rolled — an older gateway would reject the unknown config key on validation.
🤖 Generated with Claude Code
Summary by cubic
Adds proactive progress nudges for long-running agent turns so users see “still working on X…” updates; if a long run fails, sends a single failure + next‑step nudge. Off by default and reuses existing delivery; implements ENG-16200.
New Features
startProgressNudgeRunnerposts “still working” nudges after a threshold, spaced by an interval and capped bymaxNudges; usessendDurableMessageBatch+resolveHeartbeatDeliveryTargetWithSessionRoute({ target: "last" }).memory_flushing/preflight_compacting.startedAt, via the injected clock), so runs that cross the threshold and fail between ticks still get one; delivery uses the snapshottedrouteThreadId, and a fire‑once guard persists so duplicate terminal events can’t double‑nudge. Settingtarget: "none"suppresses both in‑turn and terminal nudges.startedAt,resolveActiveReplyRunStartedAt, andonReplyRunTerminal; terminal events carryrouteThreadId+startedAt. The runner is started beside the heartbeat runner and composed into its handle so existingstop/updateConfigdrive both; test resets now clear terminal listeners.Migration
agents.defaults.progressNudge.enabled: true(optionallythresholdSeconds,intervalSeconds,maxNudges,target,activeHours).progressNudgekey.Written for commit 3878416. Summary will update on new commits.