feat!: migrate personas to the relay SDK AgentEvent (Unit C, agents codemod)#56
Conversation
…odemod)
Paired with @agentworkforce/runtime v4, which delivers the relay SDK AgentEvent
to handlers instead of the old { source, type, payload } shape.
Per-persona migration:
- cron-only (hn-monitor, spotify-releases, vendor-monitor): event.source==='cron'
→ isCronTickEvent(event)
- granola: event.payload → (await event.expand('full')).data
- repo-hygiene / review: event.source guard dropped (narrowed by triggers);
event.type checks now provider-qualified (github.pull_request.opened, …);
payload read once via expand and passed to the existing unknown-typed helpers
- linear-slack: source guard → event.type.startsWith('slack.'); payload via expand
- linear: handleLinearEvent expands once and threads the payload through its
helpers; all linear.* type strings provider-qualified
- cloud-team-{implementer,reviewer}: source/type logging off the SDK event
- tests: linear/linear-slack event fixtures rebuilt via envelopeToAgentEvent
Bumps @agentworkforce/{runtime,persona-kit} to ^4.0.0. Verified: tsc --noEmit
clean (0 errors — the new define-agent narrowing turned the formerly-silent
event.type suffix mismatches into compile errors) and all 60 persona tests pass
against the v4 runtime.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Your free trial PR review limit of 300 PRs has been reached. Please upgrade your plan to continue using CodeAnt AI. |
|
Warning Review limit reached
More reviews will be available in 33 minutes and 10 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (13)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
pr-reviewer could not complete review for #56 in AgentWorkforce/agents. |
|
ℹ️ pr-reviewer: review only — no file changes were applied to the PR (nothing to commit after review). The notes below are advisory and were not pushed. pr-reviewer could not complete review for #56 in AgentWorkforce/agents. |
There was a problem hiding this comment.
Code Review
This pull request upgrades the workspace agents to version 4.0.0 of the @agentworkforce/runtime and @agentworkforce/persona-kit packages. Key changes include migrating from synchronous event.payload to asynchronous event.expand('full') for retrieving provider payloads, replacing WorkforceProviderEvent with WorkforceEvent, and updating event source and type checks to use provider-qualified prefixes or the isCronTickEvent helper. Feedback on these changes suggests adding optional chaining when accessing event.resource.provider in unexpected event handlers to prevent potential runtime crashes, and optimizing the Linear event handler by verifying the event type before invoking the asynchronous expand call.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| eventId: event.id, | ||
| source: event.source, | ||
| type: 'type' in event ? event.type : undefined | ||
| source: isCronTickEvent(event) ? 'cron' : event.resource.provider, |
There was a problem hiding this comment.
Since handleUnexpectedEvent is specifically designed to handle unexpected or malformed events, we should not assume that event.resource is defined or has a provider property. Accessing event.resource.provider directly could throw a TypeError and crash the logging/handling flow. Use optional chaining to safely access the provider.
| source: isCronTickEvent(event) ? 'cron' : event.resource.provider, | |
| source: isCronTickEvent(event) ? 'cron' : event.resource?.provider, |
| eventId: event.id, | ||
| source: event.source, | ||
| type: 'type' in event ? event.type : undefined | ||
| source: isCronTickEvent(event) ? 'cron' : event.resource.provider, |
There was a problem hiding this comment.
Since handleUnexpectedEvent is specifically designed to handle unexpected or malformed events, we should not assume that event.resource is defined or has a provider property. Accessing event.resource.provider directly could throw a TypeError and crash the logging/handling flow. Use optional chaining to safely access the provider.
| source: isCronTickEvent(event) ? 'cron' : event.resource.provider, | |
| source: isCronTickEvent(event) ? 'cron' : event.resource?.provider, |
| // v4: the provider payload is reached via expand (no sync `event.payload`). | ||
| const payload = (await event.expand('full')).data; | ||
| ctx.log?.('info', 'linear event', { | ||
| eventId: event.id, | ||
| type: event.type, | ||
| payloadKeys: payloadKeys(event.payload), | ||
| recordKeys: payloadKeys(linearRecordPayload(event.payload)), | ||
| hasIssueId: Boolean(readIssueId(event.payload, event.type)), | ||
| hasSessionId: Boolean(readSessionId(event.payload)), | ||
| payloadKeys: payloadKeys(payload), | ||
| recordKeys: payloadKeys(linearRecordPayload(payload)), | ||
| hasIssueId: Boolean(readIssueId(payload, event.type)), | ||
| hasSessionId: Boolean(readSessionId(payload)), | ||
| }); | ||
|
|
||
| if (event.source !== 'linear') { | ||
| if (!event.type.startsWith('linear.')) { | ||
| logSkip(ctx, event, 'non-linear event source'); | ||
| return; | ||
| } |
There was a problem hiding this comment.
The event is expanded via await event.expand('full') before checking if the event is actually a Linear event. For non-Linear events (such as cron or other providers), this performs an unnecessary and potentially expensive network/database call to expand the event, and then logs attributes that might not exist or make sense. Moving the type check to the top of the function avoids this overhead.
| // v4: the provider payload is reached via expand (no sync `event.payload`). | |
| const payload = (await event.expand('full')).data; | |
| ctx.log?.('info', 'linear event', { | |
| eventId: event.id, | |
| type: event.type, | |
| payloadKeys: payloadKeys(event.payload), | |
| recordKeys: payloadKeys(linearRecordPayload(event.payload)), | |
| hasIssueId: Boolean(readIssueId(event.payload, event.type)), | |
| hasSessionId: Boolean(readSessionId(event.payload)), | |
| payloadKeys: payloadKeys(payload), | |
| recordKeys: payloadKeys(linearRecordPayload(payload)), | |
| hasIssueId: Boolean(readIssueId(payload, event.type)), | |
| hasSessionId: Boolean(readSessionId(payload)), | |
| }); | |
| if (event.source !== 'linear') { | |
| if (!event.type.startsWith('linear.')) { | |
| logSkip(ctx, event, 'non-linear event source'); | |
| return; | |
| } | |
| if (!event.type.startsWith('linear.')) { | |
| logSkip(ctx, event, 'non-linear event source'); | |
| return; | |
| } | |
| // v4: the provider payload is reached via expand (no sync event.payload). | |
| const payload = (await event.expand('full')).data; | |
| ctx.log?.('info', 'linear event', { | |
| eventId: event.id, | |
| type: event.type, | |
| payloadKeys: payloadKeys(payload), | |
| recordKeys: payloadKeys(linearRecordPayload(payload)), | |
| hasIssueId: Boolean(readIssueId(payload, event.type)), | |
| hasSessionId: Boolean(readSessionId(payload)), | |
| }); |
|
pr-reviewer could not complete review for #56 in AgentWorkforce/agents. |
|
ℹ️ pr-reviewer: review only — no file changes were applied to the PR (nothing to commit after review). The notes below are advisory and were not pushed. pr-reviewer could not complete review for #56 in AgentWorkforce/agents. |
|
pr-reviewer could not complete review for #56 in AgentWorkforce/agents. |
1 similar comment
|
pr-reviewer could not complete review for #56 in AgentWorkforce/agents. |
|
ℹ️ pr-reviewer: review only — no file changes were applied to the PR (nothing to commit after review). The notes below are advisory and were not pushed. pr-reviewer could not complete review for #56 in AgentWorkforce/agents. |
|
pr-reviewer could not complete review for #56 in AgentWorkforce/agents. |
|
ℹ️ pr-reviewer: review only — no file changes were applied to the PR (nothing to commit after review). The notes below are advisory and were not pushed. pr-reviewer could not complete review for #56 in AgentWorkforce/agents. |
Regenerated against the published v4 line (4.0.1, which includes the no-trigger narrowing fix). Pulls in @agent-relay/events as a transitive runtime dep. Verified against the real published packages: tsc --noEmit clean (0 errors), all 60 persona tests pass. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Your free trial PR review limit of 300 PRs has been reached. Please upgrade your plan to continue using CodeAnt AI. |
|
pr-reviewer could not complete review for #56 in AgentWorkforce/agents. |
1 similar comment
|
pr-reviewer could not complete review for #56 in AgentWorkforce/agents. |
|
pr-reviewer could not complete review for #56 in AgentWorkforce/agents. |
3 similar comments
|
pr-reviewer could not complete review for #56 in AgentWorkforce/agents. |
|
pr-reviewer could not complete review for #56 in AgentWorkforce/agents. |
|
pr-reviewer could not complete review for #56 in AgentWorkforce/agents. |
Paired with
@agentworkforce/runtimev4 (AgentWorkforce/workforce#220), which delivers the relay SDKAgentEventto handlers instead of the old{ source, type, payload }shape.Per-persona migration
event.source==='cron'→isCronTickEvent(event)event.payload→(await event.expand('full')).dataevent.typechecks now provider-qualified (github.pull_request.opened, …); payload expanded once and passed to the existingunknown-typed helpersevent.type.startsWith('slack.'); payload via expandhandleLinearEventexpands once and threads payload through helpers; alllinear.*type strings provider-qualifiedenvelopeToAgentEventBumps
@agentworkforce/{runtime,persona-kit}to^4.0.0.Verification
tsc --noEmit: 0 errors — the newdefine-agentnarrowing turned the formerly-silentevent.typesuffix mismatches into compile errors (caught every site).🤖 Generated with Claude Code
Summary by cubic
Migrates all personas to the relay SDK
AgentEventin@agentworkforce/runtimev4. Handlers now use provider-qualifiedevent.type, read payload viaawait event.expand('full'), and useisCronTickEvent(event)for schedules.Migration
github.pull_request.opened,slack.message.created,linear.issue.create).(await event.expand('full')).dataand thread through helpers (granola, linear, repo-hygiene, review).linear.comment.create,linear.AppUserNotification.issueCommentMention).event.type.startsWith('slack.')gate; payload via expand.isCronTickEvent(event)(hn-monitor, spotify-releases, vendor-monitor).event.resource.provider(cron fallback).envelopeToAgentEvent.Dependencies
@agentworkforce/runtimeand@agentworkforce/persona-kitto v4 (resolves to 4.0.1; pulls in@agent-relay/events).Written for commit b86f6da. Summary will update on new commits.