Skip to content

feat(event): add reactive runtime event plumbing#28

Merged
omarluq merged 6 commits into
mainfrom
feat/ro-runtime-events
May 19, 2026
Merged

feat(event): add reactive runtime event plumbing#28
omarluq merged 6 commits into
mainfrom
feat/ro-runtime-events

Conversation

@omarluq
Copy link
Copy Markdown
Owner

@omarluq omarluq commented May 19, 2026

Summary

  • expose additional assistant lifecycle payloads on the runtime event stream
  • publish context/usage events through the shared event naming path
  • add coverage around lifecycle ordering updates

Validation

  • mise exec -- task ci

Note: this is intended to stack after #23; GitButler would not attach the branch to the stack locally due to the current base segment state.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 19, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 9def230f-f9c2-49bd-af4e-f10f33e507df

📥 Commits

Reviewing files that changed from the base of the PR and between 191fc11 and e853469.

📒 Files selected for processing (5)
  • internal/assistant/client.go
  • internal/assistant/lifecycle.go
  • internal/assistant/runtime.go
  • internal/assistant/runtime_lifecycle_test.go
  • internal/assistant/usage_events.go
✅ Files skipped from review due to trivial changes (1)
  • internal/assistant/client.go
🚧 Files skipped from review as they are similar to previous changes (3)
  • internal/assistant/runtime_lifecycle_test.go
  • internal/assistant/usage_events.go
  • internal/assistant/lifecycle.go

📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • Added a context-build lifecycle event exposing session context details such as message counts and token estimates.
  • Improvements

    • Standardized the token-usage field name across lifecycle events.
    • Enhanced token estimation output to include per-role message counts and estimated token breakdowns.
  • Tests

    • Updated tests to assert the new context-build lifecycle event in success and error flows.

Walkthrough

Adds a jsonUsageKey constant, updates usage emission and turn-end payload to use it, introduces a context_build lifecycle event with payload and helpers, calls the dispatch during model response handling, and updates tests to assert the new event.

Changes

Lifecycle Event and Usage Key Standardization

Layer / File(s) Summary
Usage key constant and refactoring
internal/assistant/client.go, internal/assistant/usage_events.go, internal/assistant/lifecycle.go
Introduce jsonUsageKey constant and replace hardcoded "usage" references in usage emission and the turn-end lifecycle payload.
Context-build lifecycle event dispatch and payload
internal/assistant/lifecycle.go, internal/assistant/runtime.go
Add Runtime.dispatchContextBuild and contextBuildLifecyclePayload (message counts, token estimates, per-role counts, usage), and invoke dispatch from modelResponse.
Context-build event test coverage
internal/assistant/runtime_lifecycle_test.go
Register context_build in the Lua lifecycle test extension and verify it appears in ordered event sequences for both success and error scenarios.

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • omarluq/librecode#23: Prior PR introducing session/turn lifecycle emission and turn-end payloads; this change builds on that lifecycle emission structure.

"A rabbit in the code did pry,
Added keys and watched events fly,
Tokens counted, contexts made,
Tests hop in to mark the parade. 🐇✨"

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: adding reactive runtime event plumbing to expose lifecycle payloads on the event stream.
Description check ✅ Passed The description is directly related to the changeset, outlining the three main objectives of exposing lifecycle payloads, publishing events through shared paths, and adding test coverage.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/ro-runtime-events

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@internal/assistant/lifecycle.go`:
- Around line 129-139: The new dispatchContextBuild, and its helper
contextBuildLifecyclePayload, are never called (dead code), so wire
runtime.dispatchContextBuild(...) into the context construction/execution path
where the active prompt and messages are assembled (the same place that
currently builds systemPrompt, messages []database.MessageEntity, sessionID, cwd
and usage before executing the prompt). Locate the routine that prepares the
prompt context (e.g., the method that constructs or executes the prompt for
Runtime), and after assembling sessionID, cwd, systemPrompt, messages and usage,
call runtime.dispatchContextBuild(ctx, sessionID, cwd, systemPrompt, messages,
usage) so the context_build lifecycle event is emitted; ensure you pass the same
values used for prompt execution and keep the existing runtime.dispatchLifecycle
usage intact (it will reuse dispatchContextBuild’s payload via
contextBuildLifecyclePayload).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: fa7fad34-5f54-4919-9ee7-fdbafe4500d8

📥 Commits

Reviewing files that changed from the base of the PR and between 44ebeb9 and 191fc11.

📒 Files selected for processing (4)
  • internal/assistant/client.go
  • internal/assistant/lifecycle.go
  • internal/assistant/runtime_lifecycle_test.go
  • internal/assistant/usage_events.go

Comment thread internal/assistant/lifecycle.go
@omarluq omarluq force-pushed the feat/ro-runtime-events branch from 191fc11 to e853469 Compare May 19, 2026 04:23
@sonarqubecloud
Copy link
Copy Markdown

@codecov-commenter
Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.29630% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 57.36%. Comparing base (44ebeb9) to head (e853469).

Files with missing lines Patch % Lines
internal/assistant/usage_events.go 50.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #28      +/-   ##
==========================================
+ Coverage   57.29%   57.36%   +0.06%     
==========================================
  Files         160      160              
  Lines       15758    15782      +24     
==========================================
+ Hits         9029     9053      +24     
  Misses       5767     5767              
  Partials      962      962              
Flag Coverage Δ
unittests 57.36% <96.29%> (+0.06%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@omarluq omarluq merged commit 89c3f14 into main May 19, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants