Commit Graph

105 Commits

Author SHA1 Message Date
Vincent Koc 742f00c53b test(agents): preserve output across process polls (#122664)
Punchcard-Session: brisk-willow-summit-z9
2026-08-12 23:19:26 +08:00
Peter Steinberger 7b076155d0 refactor: clarify message channel validation (#120872) 2026-08-08 21:30:22 -07:00
licheer-zte 42500d13b1 fix(hooks): target hook-triggered heartbeat wakes at the hook agent/session (#119808) (#119817)
* fix(hooks): allow scoped hook wakes for unscheduled targets; keep announce wake aligned with queued session

- heartbeat-wake-policy: add isTargetedImmediateHookWake so a scoped hook
  wake (source=hook, reason=hook:*) counts as an immediate targeted wake;
  a known agent without a recurring heartbeat schedule can now be woken
  once so its queued hook event gets consumed instead of sitting unread.
- scheduler + execution: accept the hook wake in the allowsUnscheduledTarget
  gate alongside notifications-event wakes; unconfigured agents stay rejected.
- hooks announce path: only pass agentId when the hook explicitly named an
  agent; an unnamed hook resolves its event session from fresh config at
  announce time, so pairing the dispatch-time default agent with that
  session could wake a stale agent after a default-agent reload.
- regression tests: targeted hook wake for an unscheduled agent runs once;
  unconfigured hook targets rejected; announce wake omits default agentId
  for unnamed hooks.

* test(infra): split hook-wake heartbeat tests out of scheduler test file

Keep heartbeat-runner.scheduler.test.ts inside the oxlint max-lines budget
(1045 -> 995 effective lines) by moving the two hook-source wake targeting
tests into heartbeat-runner.hook-wake.test.ts. No production code changes.

* fix(gateway): target global-scope hook wakes at the fresh default agent

Global session scope resolves hook event keys to the unscoped "global"
sentinel, which carries no agent identity. The scheduler refuses to
resolve a target from it, so announce and failure wakes for unnamed
hooks left the queued event unread.

Carry the fresh default agent alongside the global key on both paths
(announce and failure), mirroring the enqueue-wake path. Non-global
unnamed-hook wakes are unchanged: their session key embeds the agent,
and pairing a frozen default agent could wake a stale agent after a
default-agent reload.

* fix(gateway): target recovered global failure wakes at the explicit or fresh default agent

The failure-wake agent selection gated both branches on hookEventSessionKey.
When initial event-key resolution fails (early config failure), that key is
absent even though recovery still yields the unscoped "global" sentinel; the
wake then carried no agentId and the queued failure event sat unread.

Use the recovered session key for the sentinel check and attach the explicit
agent, or the fresh default agent, so the global failure event is consumed.
Non-global unnamed-hook wakes are unchanged: their session key embeds the
agent, and pairing a frozen default agent could wake a stale agent after a
default-agent reload.

* fix(gateway): preserve agent identity for global hook wakes

Signed-off-by: sallyom <somalley@redhat.com>

* test(infra): allow seeding a heartbeat session without delivery fields

The new hook-wake test seeds an empty session for the hooks agent, which
has no real delivery context. Relax seedSessionStore's seed type to
Partial so empty seeds typecheck.

* fix(gateway): keep global hook wakes on the dispatch-time agent

The announce and failure wake paths resolved the default agent from
fresh config at queue-execution time. If a default-agent reload happened
between dispatch and execution, a global-scope wake retargeted at the new
default while the isolated run used the accepted agent, so the event
produced under one agent was consumed by another. Freeze the accepted
agent at dispatch (acceptedHookAgentId) and prefer it in both wake paths;
fresh resolution remains the fallback for pre-acceptance failures. Adds
announce + failure reload regressions (default main -> work mid-queue).

* test(hooks): annotate reload fixtures as OpenClawConfig

The default-agent reload fixtures widened session.scope to string and
fixed agents.entries to the first assignment's shape, breaking
check-test-types. Annotate both fixtures so each reload conforms to the
config contract.

* fix(hooks): partition global-scope hook events by owning agent

Global-scope hook announce and failure events all land in the shared
literal `global` system-event queue while each wake targets a single
agent, so concurrent hook completions can cross-consume each other's
events: the first targeted wake drains every agent's queued result or
failure into one prompt.

Give transient system events an ownerAgentId set by the hook dispatch
paths (announce, failure, and wake-only enqueues) whenever the event
lands on the unscoped sentinel queue, and filter the heartbeat preflight
peek to the running agent's owned events. The store's literal global
session row stays shared; unowned events remain visible to every agent,
so non-hook global events are unchanged.

Add a two-agent concurrent regression proving the first targeted wake
leaves the other agent's event queued for its owner.

* fix(hooks): isolate global events by agent

Signed-off-by: sallyom <somalley@redhat.com>

* fix(infra): unexport internal targeted-wake helpers

isTargetedImmediateSystemEventWake and isTargetedImmediateHookWake are
only consumed by isTargetedImmediateUnscheduledWake within the same
module; keep them module-private so knip deadcode stops flagging the
unused exports.

---------

Signed-off-by: sallyom <somalley@redhat.com>
Co-authored-by: sallyom <somalley@redhat.com>
2026-08-08 23:03:50 -04:00
xin zhuang 2f76ec387a fix: process poll leaves notify-on-exit completion queued (#120585)
* fix(exec): acknowledge notify-on-exit after process poll

* test(exec): mock completion event enqueue

* fix: retire stale exec heartbeat wakes

Prevent acknowledged process completions from turning their queued wake into an unrelated heartbeat. Preserve coalesced task work and keep stale wakes out of scheduler cadence and commitment follow-up.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* test: isolate stale exec heartbeat coverage

Keep existing heartbeat suites below the max-lines ratchet while retaining coverage for stale wake coalescing, scheduler bookkeeping, and commitment fan-out.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* fix(heartbeat): preserve scheduled cadence for stale exec wakes

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* test(heartbeat): keep stale wake coverage within lint limits

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* fix(heartbeat): retire stale exec wakes before busy gates

Preserve scheduled cadence and cron work when coalesced exec wakes are acknowledged, while retiring stale wakes before retryable busy checks.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* fix(heartbeat): accept inferred wake sources

Allow stale-wake preflight to handle the optional source produced by reason inference without weakening the exec-event check.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-08-08 16:23:47 -05:00
clawsweeper[bot] 0f43212fb4 fix(process): disclose omitted retained output in finished polls (#120583)
* fix(process): disclose omitted retained output in finished polls

* fix(process): disclose capped pending poll output

Co-authored-by: clawsweeper <274271284+clawsweeper[bot]@users.noreply.github.com>

---------

Co-authored-by: clawsweeper <274271284+clawsweeper[bot]@users.noreply.github.com>
Co-authored-by: Peter Steinberger <steipete@gmail.com>
2026-08-08 13:45:40 -07:00
Peter Steinberger 7c6eba5467 fix(agents): reject cancelled foreground commands (#115694)
Co-authored-by: 赵旺0668001248 <zhao.wang1@xydigit.com>
2026-07-29 04:22:31 -04:00
Peter Steinberger 855659a1dd refactor(agents): privatize state reset seams (#108285)
* refactor(agents): privatize state reset seams

* chore(deadcode): shrink agents state seam baseline
2026-07-15 05:09:45 -07:00
Peter Steinberger 4ed28c3559 refactor(agents): trim shell and tool-loop exports (#107695)
* refactor(agents): trim shell and session exports

* refactor(agents): trim loop and model exports

* chore(deadcode): refresh unused export baseline
2026-07-14 10:34:39 -07:00
Peter Steinberger d1684f48a3 refactor: delete dead infra and config exports (#106019)
* refactor: delete dead infra and config exports

* refactor: preserve live infra and config contracts

* refactor(config): remove obsolete file-store lifecycle APIs

* refactor(infra): finish current-main dead export cleanup
2026-07-13 12:00:47 -07:00
Peter Steinberger 2a7132a43f refactor(agents): trim exec approval exports (#106401) 2026-07-13 06:03:41 -07:00
Peter Steinberger 1b313dc4d4 chore(tooling): enforce indexed access in core tests (#105375)
* test(tooling): enforce indexed access in core tests

* test(tui): constrain theme environment overrides

* test(doctor): enforce indexed access in migration fixtures
2026-07-12 14:29:52 +01:00
Peter Steinberger 204d2b176a refactor(agents): compress model prompts and tool instructions (#105095)
* refactor(agents): compress model prompt instructions

* test(agents): align compact prompt assertions

* test(gateway): align compact message prompt assertion

* chore(plugin-sdk): refresh prompt overlay API baseline

* docs(changelog): note prompt instruction compaction

* test(agents): align compact prompt contracts

* test(agents): align CLI prompt contracts

* style(agents): format CLI prompt tests

* fix(qa): prioritize shadow trial workflow

* test(agents): refresh rebased prompt snapshots
2026-07-12 09:45:30 +01:00
Peter Steinberger 9b1c36d23c fix: prevent exec approval revocation races (#103515)
* fix(security): serialize exec approval mutations

* fix(security): preserve additive approval writes

* test(cli): expect normalized approval shape

* fix(security): preserve exec approval compatibility

* test(security): exercise locked approval initialization

* test(security): mock serialized approval helpers

* test(exec): derive enforced command path from plan

* fix(gateway): always return approval CAS conflicts

* fix(macos): serialize exec approvals writes

* fix(security): repair approval build errors

* fix(security): serialize exec approval mutations

* fix(security): fail closed on approval persistence errors

* test(security): cover detached approval persistence failures

* fix(security): harden exec approval state

* style(macos): format exec approval sources

* fix(security): complete exec approval hardening

Co-authored-by: Coy Geek <65363919+coygeek@users.noreply.github.com>

* fix(macos): preserve approved login-shell semantics

* fix(macos): keep login shell approvals one-shot

* fix(security): linearize exec authorization

Co-authored-by: Coy Geek <65363919+coygeek@users.noreply.github.com>

* fix(security): preserve durable approval basis

Co-authored-by: Coy Geek <65363919+coygeek@users.noreply.github.com>

* fix(security): bind exec grants to current policy

Co-authored-by: Coy Geek <65363919+coygeek@users.noreply.github.com>

* test(security): fix exec revocation fixtures

* test(security): align gateway approval fixtures

* fix(macos): return approval decisions

* chore(i18n): sync native approval strings

* test(security): align approval hardening fixtures

* test(node): authorize completed event fixture

* test(security): fix approval decision fixtures

* test(security): await durable approval visibility

* fix(exec): preserve concurrent approval grants

* fix(exec): address exact-head CI failures

* fix(exec): preserve concurrent approval promotions

* fix(exec): make Swift shutdown state explicit

* test(macos): handle approval read failures

* fix(macos): harden approval socket paths

* fix(macos): preserve exact shell payload bytes

* test(macos): make approval fixtures explicit

* test(macos): fix approval suite compilation

* fix(macos): bound approval socket JSONL reads

* chore: move exec approval note to release process

* chore: move exec approval note to release process

---------

Co-authored-by: Coy Geek <65363919+coygeek@users.noreply.github.com>
2026-07-10 21:35:05 +01:00
Vincent Koc 92b283da84 refactor(process): remove unused orphan reconciliation API 2026-06-23 01:13:13 +08:00
Vincent Koc 23589d9e7c agents: notify chat exec empty-success completions (#93525)
Co-authored-by: openclaw-clownfish[bot] <280122609+openclaw-clownfish[bot]@users.noreply.github.com>
Co-authored-by: wenkang.xie <58462870+wenkang-xie@users.noreply.github.com>
2026-06-16 14:37:59 +08:00
Peter Steinberger d2d2dfd9f2 docs: document process tool controls 2026-06-04 06:21:15 -04:00
Peter Steinberger 22cb7fb6b7 chore(lint): enable no-promise-executor-return 2026-05-31 23:06:13 +01:00
Peter Steinberger a053ae5d65 test: align release CI expectations 2026-05-31 18:13:02 +01:00
Peter Steinberger 1af4c035e4 refactor: move delivery queues to SQLite (#88665)
* refactor: move delivery queues to sqlite

* fix: satisfy delivery queue sqlite boundaries

* test: remove stale reasoning replay assertion

* fix: migrate failed delivery queue entries

* test: stabilize exec shell snapshot mocks

* fix: clean legacy delivery queue markers
2026-05-31 17:43:03 +01:00
samzong 5b310a7b27 fix(agents): release abandoned provider streams
Fix streamed provider cleanup so abandoned managed fetch bodies no longer keep undici sockets open, and cancel Anthropic/Gemini SSE readers deterministically when parsing exits early.

Keep the FinalizationRegistry abort path as a last-resort GC safety net for unmanaged/abandoned responses, while parser-owned paths cancel readers explicitly on thrown errors or malformed events.

Also records the browser-only Control UI redactor alias in the optional deadcode allowlist and keeps mocked exec supervisor tests off shell snapshot wrapping after the branch was rebased onto default shell snapshots.

Fixes #67461

Verification:
- node scripts/run-vitest.mjs src/agents/provider-transport-fetch.test.ts src/agents/anthropic-transport-stream.test.ts extensions/google/transport-stream.test.ts src/agents/bash-tools.test.ts src/agents/bash-tools.exec.path.test.ts test/scripts/test-live-shard.test.ts
- pnpm check:test-types
- node scripts/run-oxlint-shards.mjs --threads=8
- .agents/skills/autoreview/scripts/autoreview --mode branch --base origin/main --parallel-tests "node scripts/run-vitest.mjs src/agents/provider-transport-fetch.test.ts src/agents/anthropic-transport-stream.test.ts extensions/google/transport-stream.test.ts src/agents/bash-tools.test.ts src/agents/bash-tools.exec.path.test.ts test/scripts/test-live-shard.test.ts"
- git diff --check origin/main...HEAD
- PR CI on a1db789652

Co-authored-by: samzong <samzong.lu@gmail.com>
Signed-off-by: samzong <samzong.lu@gmail.com>
2026-05-31 17:17:53 +01:00
Ninty ee6eab8143 fix(agents): clean up exec abort listener after completion (#83022)
Clean up completed exec tool-call abort listeners so normal foreground completion and background-yield no longer retain the exec run/session context through AbortSignal listener state.

The listener cleanup now lives beside the exec listener registration and runs when the foreground process settles, rejects, or the tool returns a background running result. Existing abort/timeout/background behavior remains owned by the process supervisor and process registry.

Verification:
- gh pr checks 83022
- gh api repos/openclaw/openclaw/commits/fe86528ecb2043b6febef5c2eec53f9124be5543/check-runs
- git merge-tree --write-tree origin/main refs/remotes/pr/83022
- git diff --check origin/main...refs/remotes/pr/83022
- node AbortSignal add/remove listener probe

Thanks @c19354837.

Co-authored-by: Ninty <c19354837@hotmail.com>
2026-05-29 09:15:07 +01:00
Super Zheng b77f36fb1c fix(exec): protect pathPrepend against posix login-shell RC overrides (#81403)
Merged via squash.

Prepared head SHA: 874fa90aa9
Co-authored-by: medns <1575008+medns@users.noreply.github.com>
Co-authored-by: odysseus0 <8635094+odysseus0@users.noreply.github.com>
Reviewed-by: @odysseus0
2026-05-21 13:19:41 -07:00
Peter Steinberger 02182d5a30 refactor: remove sender owner tool gating 2026-05-21 15:14:48 +01:00
Peter Steinberger c0fe7ab34a fix: keep queued system event authority structured
Keep queued system-event owner downgrades as structured runtime metadata while rendering the model-visible prompt as plain `System:` lines.

This preserves least-privilege wakeups for webhook/node/exec/cron/reaction/hook producers, keeps legacy `trusted: false` compatibility for installed plugins and older hosts, and updates representative gateway, agent, cron, plugin, and OpenGrep coverage.
2026-05-15 12:24:27 +01:00
Peter Steinberger be7ac231b8 test: guard agent auth bash mock calls 2026-05-12 08:42:59 +01:00
Shakker 2013700753 test: assert noop exec completion event 2026-05-12 02:14:59 +01:00
Peter Steinberger 2e7d9e2290 test: use immediate for bash abort turn 2026-05-11 18:38:32 +01:00
Peter Steinberger 864899d1b0 test: tighten exec notify assertions 2026-05-09 16:32:11 +01:00
Shakker 0517b54942 test: tighten agents array assertions 2026-05-09 05:46:22 +01:00
Peter Steinberger ff4d5541a2 test: simplify bash tools command splitting 2026-05-09 00:09:25 +01:00
Peter Steinberger 9ef37d1907 test: tighten assertions and harness coverage 2026-05-08 05:28:12 +01:00
Peter Steinberger e5f8c5195f fix(plugins): detect stale persisted registry metadata 2026-05-02 23:00:04 +01:00
Peter Steinberger 9180173f9a fix: preserve exec event routing and sanitize tool XML 2026-05-02 09:16:11 +01:00
Peter Steinberger 2c814d33e6 perf(test): slim bash tool imports 2026-04-20 12:26:39 +01:00
Peter Steinberger cef82adf19 test: speed up bash tool wait loops 2026-04-18 23:34:49 +01:00
Peter Steinberger 4852935e8e perf: speed exec event test waits 2026-04-18 16:23:00 +01:00
Peter Steinberger f57ce21d73 test: trim process-backed agent assertions 2026-04-17 07:15:27 +01:00
Vincent Koc 156ee544ed test(agents): share notify heartbeat wake helper 2026-04-12 16:43:39 +01:00
Josh Lehman 29142a9d47 fix: preserve Telegram topic routing for exec completions (#64580)
* clawdbot-a2c: pin exec completion delivery context

Regeneration-Prompt: |
  Fix a Telegram forum topic misroute where delayed exec completion or similar async completion text could be delivered into the wrong topic after the session's stored route drifted. Keep the patch surgical. Preserve immutable origin deliveryContext when background exec completion events are queued, thread that context from the exec tool's ambient channel/session defaults into the process session, and ensure the queued system event carries it instead of relying on later heartbeat fallback to mutable session lastTo/lastThreadId data. Add one focused unit assertion that notifyOnExit events keep the original Telegram topic delivery context and one heartbeat regression that proves work started in topic 47 still delivers back to topic 47 even if the session store later points at topic 2175.

* fix: note Telegram exec topic routing

Regeneration-Prompt: |
  Prepare PR #64580 after review-pr with no blocking findings. The only required prep change was the workflow-mandated changelog entry under CHANGELOG.md -> Unreleased -> Fixes. Preserve the review conclusion that the code change is already acceptable, do not widen scope beyond the changelog, and include the PR number plus thanks attribution in the changelog line for the Telegram exec forum-topic completion routing fix.
2026-04-11 15:47:53 -07:00
Chunyue Wang 574bab80e5 fix(exec): disable onUpdate after run settlement to prevent gateway crash (#62821)
Squash-merged via maintainer prepare workflow.

Prepared head SHA: 431381ae1e

Co-authored-by: openperf <16864032@qq.com>
2026-04-10 23:33:25 +08:00
Devin Robison 48a3511233 fix: lower trust background runtime output is injecte (#327) (#62111)
* fix: lower trust background runtime output is injecte (#327)

* fix: lower trust background runtime output is injecte (#327)

---------

Co-authored-by: OpenClaw Dummy Agent <octriage-dummy@example.invalid>
2026-04-06 15:14:52 -06:00
Chunyue Wang b682202016 fix: stop emitting post-background exec updates (#61627) (thanks @openperf)
* fix(exec ): stop emitting tool updates after session is backgrounded

When an exec session is backgrounded (background: true), the owning
agent run resolves its tool-call promise and may finish.  The stdout
handler's emitUpdate() closure, however, kept invoking opts.onUpdate(),
delivering tool_execution_update events to a listener whose active run
had already ended.  This surfaced as an unhandled rejection and crashed
the gateway process.

Guard emitUpdate() with a session.backgrounded || session.exited check
so that post-background output is still captured via appendOutput() but
no longer forwarded to the (now-stale) agent-loop callback.

Fixes #61592

* style: trim exec backgrounding comments

* fix: stop emitting post-background exec updates (#61627) (thanks @openperf)

* fix: place exec changelog entry at end of fixes (#61627) (thanks @openperf)

---------

Co-authored-by: Ayaan Zaidi <hi@obviy.us>
2026-04-06 09:47:30 +05:30
Peter Steinberger bff55b55cb style: normalize import ordering and wrapping 2026-04-05 09:26:39 +01:00
rstar327 43fe68f9ef fix(exec): keep notifyOnExit heartbeat wakes on exec-event (#41479)
Co-authored-by: Vincent Koc <vincentkoc@ieee.org>
2026-04-05 09:25:12 +01:00
Vincent Koc 6f2e804182 fix(agents): prefer background completion wake over polling (#60877)
* fix(agents): prefer completion wake over polling

* fix(changelog): note completion wake guidance

* fix(agents): qualify quiet exec completion wake

* fix(agents): qualify disabled exec completion wake

* fix(agents): split process polling from control actions
2026-04-05 03:17:10 +09:00
Vincent Koc b742909dca fix(agents): prefer cron for deferred follow-ups (#60811)
* fix(agents): prefer cron for deferred follow-ups

* fix(agents): gate cron scheduling guidance

* fix(changelog): add scheduling guidance note

* fix(agents): restore exec approval agent hint
2026-04-04 21:11:27 +09:00
scoootscooob 5d81b64343 fix(exec): fail closed when sandbox is unavailable and harden deny followups (#56800)
* fix(exec): fail closed when sandbox is unavailable and harden deny followups

* docs(changelog): note exec fail-closed fix
2026-03-28 22:20:49 -07:00
Peter Steinberger e001e8f2f8 test: isolate exec foreground failure coverage 2026-03-23 04:47:12 +00:00
Peter Steinberger f8731b3d9d fix: finish exec tool failure landing (#52508) (thanks @martingarramon) 2026-03-22 19:19:07 -07:00
Martin Garramon 22c75a55b0 fix(exec): return plain-text tool result on failure instead of raw JSON
When an exec command fails (e.g. timeout), the tool previously rejected
with an Error, which the tool adapter caught and wrapped in a JSON object
({ status, tool, error }). The model then received this raw JSON as the
tool result and could parrot it verbatim to the user.

Now exec failures resolve with a proper tool result containing the error
as human-readable text in content[], matching the success path structure.
The model sees plain text it can naturally incorporate into its reply.

Also fixes a pre-existing format issue in update-cli.test.ts.

Fixes #52484

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-22 19:19:07 -07:00