Skip to content

refactor(agents): centralize typed activity event emission - #122188

Merged
vincentkoc merged 1 commit into
mainfrom
refactor/agent-activity-event-emitter
Aug 11, 2026
Merged

vincentkoc merged 1 commit into
mainfrom
refactor/agent-activity-event-emitter

Conversation

@vincentkoc

@vincentkoc vincentkoc commented Aug 11, 2026 •

Copy link
Copy Markdown
Member

What Problem This Solves

Agent activity emission duplicated the same shared-bus plumbing across four semantic wrappers. That repeated run/session forwarding, payload casting, and bus dispatch while making stream/payload pairing depend on which wrapper a caller happened to choose.

Why This Change Was Made

The agent activity owner now exposes one mapped-discriminated-union emitter. Its stream literal selects the exact allowed payload type, all existing callers use that canonical path, and the four duplicate wrappers are removed. Callback emissions remain separate because their best-effort failure semantics differ from the global bus.

Architectural closeout:

  • Root cause: four wrappers duplicated one invariant and encoded type pairing indirectly.
  • Owner: src/infra/agent-activity-events.ts.
  • Canonical fix: emitAgentActivityEvent({ runId, sessionKey?, stream, data }).
  • Removed paths: item, approval, command-output, and patch wrapper functions.
  • Production LOC: +41/-69 (net -28).
  • Tests: +105/-0.
  • Contracts unchanged: stream strings, payload identity, truthy-only session omission, event sequencing/context enrichment, callback paths, config, protocol, SDK, and dependencies.

User Impact

No user-visible behavior change. Agent item, approval, command-output, and patch events keep the same payloads, ordering, session routing, and operator-visible activity.

Evidence

Exact head: 1a11c684cdd861fdfd5befbba1d7450aa756830e

Local focused proof:

  • Owner, handler, and fast-mode integration: 229 tests passed across 3 shards.
  • pnpm check:test-types: core, extension, and root test programs passed.
  • Touched-path formatting and git diff --check: passed.
  • Autoreview: clean at 0.99 confidence with no actionable finding.

Remote proof:

  • Changed gate: Blacksmith Testbox tbx_01kzs162ctntwq15j2ygwx11zw, Actions run 31522684684, exit 0.
  • Focused exact-head Testbox: lease tbx_01kzs43kk7hqjwzrxmxsb5c3na, Actions run 31527072635, job 93897908795; 229 focused tests and pnpm check:test-types passed, workflow conclusion success.
  • AWS Crabbox: lease cbx_cbff05a9e647, run run_5f1849151da8, exit 0. The private-QA packaged build passed; the built emitAgentActivityEvent helper emitted ordered item, approval, command_output, and patch events with sequence 1-4, session omission, and payload identity preserved; built CLI and launcher version smoke passed.
  • ClawSweeper exact-head review: run 31526043249; no code findings. Its proof-only rank-up move is satisfied by the fresh green focused Testbox and AWS helper-level runtime proof above.

@clawsweeper

clawsweeper Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@vincentkoc vincentkoc self-assigned this Aug 11, 2026
@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: M maintainer Maintainer-authored PR labels Aug 11, 2026
@vincentkoc
vincentkoc force-pushed the refactor/agent-activity-event-emitter branch from a3cda68 to 1a11c68 Compare August 11, 2026 18:23
@vincentkoc

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 11, 2026
@clawsweeper

clawsweeper Bot commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 11, 2026, 4:09 PM ET / 20:09 UTC.

ClawSweeper review

What this changes

The PR replaces four internal agent-activity event wrappers with one stream-discriminated typed emitter, migrates their callers, and adds owner-level event-bus coverage.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

No blocking correctness finding: current main still has the duplicated activity wrappers, while this maintainer-owned PR cleanly centralizes them. Wait for the remaining exact-head checks before landing.

Priority: P3
Reviewed head: 1a11c684cdd861fdfd5befbba1d7450aa756830e
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A clean, net-negative owner-boundary refactor with focused real-bus and packaged-runtime evidence; final required checks remain a merge gate.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The PR body provides exact-head focused test/type evidence and packaged runtime output showing all four event streams, ordering, payload identity, and empty-session behavior after the refactor.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The PR body provides exact-head focused test/type evidence and packaged runtime output showing all four event streams, ordering, payload identity, and empty-session behavior after the refactor.
Evidence reviewed 6 items Canonical owner preserves dispatch behavior: The unified emitter forwards the same run ID, stream, payload cast, and truthy-only session-key omission as the deleted wrappers.
All production callers retain their literal stream and callback ordering: Item, approval, command-output, and patch callers now select their existing stream explicitly; completion keeps its callback emissions after the shared-bus emission.
Owner-boundary test covers observable bus invariants: The added test uses the real event bus to verify all four streams, sequence ordering, payload identity, and empty-session omission, plus the stream/payload type relation.
Findings None None.
Security None None.

How this fits together

Agent tool and run lifecycle code emits item, approval, command-output, and patch activity to a shared event bus. The gateway then enriches, sequences, and dispatches those events to subscribers and operator-facing activity surfaces.

flowchart LR
  A[Tool and run lifecycle] --> B[Typed activity emitter]
  B --> C[Shared agent event bus]
  C --> D[Sequence and context enrichment]
  D --> E[Gateway subscribers]
  E --> F[Operator activity surfaces]
Loading

Decision needed

Question Recommendation
Should this maintainer-owned cleanup land after the remaining exact-head checks complete? Land after checks: Merge once the remaining exact-head required checks are successful because no correctness or security defect was found.

Why: The PR author is a repository member and the item carries the maintainer label, so automated cleanup must not close or merge it without maintainer judgment.

Before merge

  • Resolve merge risk (P1) - The supplied check snapshot still has exact-head jobs in progress; merge after they complete successfully on the reviewed head.
  • Complete next step (P2) - This member-authored, maintainer-labelled PR needs ordinary maintainer review and completion of exact-head checks, not an automated repair job.
Agent review details

Security

None.

PR surface

Source -28, Tests +105. Total +77 across 6 files.

View PR surface stats
Area Files Added Removed Net
Source 5 41 69 -28
Tests 1 105 0 +105
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 6 146 69 +77

Review metrics

Metric Value Why it matters
Production versus test LOC production +41/-69 (net -28); tests +105/-0 The refactor removes duplicated production wrappers while adding focused owner-boundary coverage.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Land the canonical typed emitter once exact-head required checks are green, preserving the event-bus sequencing and callback boundaries already exercised by the focused proof.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Land the canonical typed emitter once exact-head required checks are green, preserving the event-bus sequencing and callback boundaries already exercised by the focused proof.

Do we have a high-confidence way to reproduce the issue?

Not applicable: this PR refactors an existing internal event-emission path rather than repairing a reported user-facing failure.

Is this the best way to solve the issue?

Yes: the map-discriminated emitter sits at the shared event owner, removes duplicate wrapper policy, and retains the existing event-bus contract at every caller.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 09c39e0ec528.

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient. The PR body provides exact-head focused test/type evidence and packaged runtime output showing all four event streams, ordering, payload identity, and empty-session behavior after the refactor.

Label justifications:

  • P3: This is a behavior-preserving internal cleanup with no reported user-visible regression.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body provides exact-head focused test/type evidence and packaged runtime output showing all four event streams, ordering, payload identity, and empty-session behavior after the refactor.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body provides exact-head focused test/type evidence and packaged runtime output showing all four event streams, ordering, payload identity, and empty-session behavior after the refactor.

Evidence

What I checked:

  • Canonical owner preserves dispatch behavior: The unified emitter forwards the same run ID, stream, payload cast, and truthy-only session-key omission as the deleted wrappers. (src/infra/agent-activity-events.ts:77, 1a11c684cdd8)
  • All production callers retain their literal stream and callback ordering: Item, approval, command-output, and patch callers now select their existing stream explicitly; completion keeps its callback emissions after the shared-bus emission. (src/agents/embedded-agent-subscribe.handlers.tools.completion.ts:451, 1a11c684cdd8)
  • Owner-boundary test covers observable bus invariants: The added test uses the real event bus to verify all four streams, sequence ordering, payload identity, and empty-session omission, plus the stream/payload type relation. (src/infra/agent-activity-events.test.ts:20, 1a11c684cdd8)
  • Downstream dispatch remains generic: The gateway records and dispatches each agent event without adding stream-specific behavior for this refactor; sequencing and context enrichment stay owned by the event bus. (src/gateway/server-runtime-subscriptions.ts:282, 1a11c684cdd8)
  • Current-main and ownership provenance: Current main still contains the four wrappers, and blame attributes their introduction to the recent agent activity work by Peter Steinberger. (src/infra/agent-activity-events.ts:61, 76ab9a751a12)
  • Reported exact-head runtime proof: The PR body records successful exact-head focused tests, type checks, and a packaged AWS Crabbox run that observed ordered item, approval, command-output, and patch events with preserved payload identity and session omission. (1a11c684cdd8)

Likely related people:

  • Peter Steinberger: Commit 76ab9a7 introduced the activity owner and the migrated callers; current-main blame attributes the wrapper lines to that work. (role: recent area contributor and activity-wrapper author; confidence: high; commits: 76ab9a751a12; files: src/infra/agent-activity-events.ts, src/agents/embedded-agent-subscribe.handlers.tools.completion.ts)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (2 earlier review cycles)
  • reviewed 2026-08-11T19:02:45.593Z sha 1a11c68 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-11T19:08:30.034Z sha 1a11c68 :: needs maintainer review before merge. :: none

@vincentkoc
vincentkoc marked this pull request as ready for review August 11, 2026 19:59
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Aug 11, 2026
@vincentkoc
vincentkoc merged commit 13823c8 into main Aug 11, 2026
192 of 194 checks passed
@vincentkoc
vincentkoc deleted the refactor/agent-activity-event-emitter branch August 11, 2026 20:16
@vincentkoc

Copy link
Copy Markdown
Member Author

Merged via squash.

vincentkoc added a commit to tangtaizong666/openclaw that referenced this pull request Aug 11, 2026
…-prep

* commit 'edb7a1692e58d78ff7e196db39ea8eff297b2e19': (1351 commits)
  fix(telegram): expose live location updates to hooks (openclaw#122185)
  fix(ui): remove the pre-creation session row (openclaw#122259)
  fix(openai): surface failed realtime response outcomes (openclaw#121177)
  fix(logging): publish diagnostics ZIP through staged atomic overwrite (openclaw#122130)
  test(cli): trim duplicate MCP probe process cases (openclaw#122260)
  feat(agents): replay persisted native video (openclaw#122257)
  fix(test): serialize default e2e runner (openclaw#122203)
  fix(ui): always show full assistant responses (openclaw#122207)
  feat(mcp): per-requester OAuth for MCP servers (openclaw#122166)
  fix(ui): preserve focus on composer accessory clicks (openclaw#122243)
  fix(backup): exclude state temp files (openclaw#122250)
  fix(browser): let attached workers exit after CDP use (openclaw#122103)
  test(cli): trim duplicate Claw authoring process cases (openclaw#122248)
  refactor(outbound): inline delivery diagnostics (openclaw#122219)
  refactor: eliminate final wrapper-shadowing hazards (openclaw#122157)
  fix(ui): keep new-session identity anchored (openclaw#122242)
  test(cli): trim duplicate gateway process cases (openclaw#122240)
  fix(media): decode local file URLs safely (openclaw#122192)
  refactor(agents): centralize typed activity event emission (openclaw#122188)
  fix(ui): effort slider matches selected level after model switches (openclaw#122125)
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling maintainer Maintainer-authored PR P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant