Skip to content

fix: handle accountId in session key parsing for send policy and Discord exec approvals#27842

Closed
scz2011 wants to merge 1 commit into
openclaw:mainfrom
scz2011:fix/pr-27750-session-key-regressions
Closed

fix: handle accountId in session key parsing for send policy and Discord exec approvals#27842
scz2011 wants to merge 1 commit into
openclaw:mainfrom
scz2011:fix/pr-27750-session-key-regressions

Conversation

@scz2011

@scz2011 scz2011 commented Feb 26, 2026

Copy link
Copy Markdown

Summary

Fixes two regressions introduced by PR #27750 which changed the session key format for group/channel keys to include accountId.

Problem

PR #27750 changed the session key format:

  • Old format: agent:<agentId>:<channel>:<peerKind>:<peerId>
  • New format: agent:<agentId>:<channel>:<accountId>:<peerKind>:<peerId>

This broke two critical features:

1. Channel derivation in send policy (deriveChannelFromKey)

  • Expected parts[1] to be peerKind (group/channel)
  • Now parts[1] is accountId, causing channel-scoped deny rules to be skipped
  • Impact: First-use sessions with group/channel keys bypass channel-based send policies

2. Discord exec approvals channel extraction (extractDiscordChannelId)

  • Regex /discord:(?:channel|group):(\d+)/ no longer matches new format
  • New format: discord:<accountId>:channel:<id>
  • Impact: Channel-targeted approval workflows cannot resolve channelId and silently fall back to DM-only behavior

Solution

Updated deriveChannelFromKey

  • Now checks both parts[1] and parts[2] for peerKind markers
  • Supports both old and new session key formats
  • Correctly extracts channel from both formats

Updated extractDiscordChannelId

  • Changed regex to /discord:(?:[^:]+:)?(?:channel|group):(\d+)/
  • Optionally matches accountId segment: [^:]+:
  • Works with both old and new formats

Testing

Added comprehensive test cases:

  • Old format session keys (backward compatibility)
  • New format session keys with accountId
  • Channel-scoped send policy rules
  • Discord channel ID extraction for both formats

All tests passing.

…ord exec approvals

PR openclaw#27750 changed session key format for group/channel keys to include accountId:
- Old: agent:<agentId>:<channel>:<peerKind>:<peerId>
- New: agent:<agentId>:<channel>:<accountId>:<peerKind>:<peerId>

This broke two critical features:

1. deriveChannelFromKey in send-policy.ts expected parts[1] to be peerKind,
   but it's now accountId. This caused channel-scoped deny rules to be
   skipped for group/channel keys, especially on first-use sessions.

2. extractDiscordChannelId regex /discord:(?:channel|group):(\d+)/ no longer
   matched the new format discord:<accountId>:channel:<id>. This broke
   channel-targeted approval workflows.

Fixes:
- Updated deriveChannelFromKey to check both parts[1] and parts[2] for
  peerKind, supporting both old and new formats
- Updated extractDiscordChannelId regex to optionally match accountId segment
- Added comprehensive tests for both old and new session key formats
@openclaw-barnacle openclaw-barnacle Bot added channel: discord Channel integration: discord size: S labels Feb 26, 2026
@greptile-apps

greptile-apps Bot commented Feb 26, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

Fixes two regressions from PR #27750's session key format change that added accountId to group/channel keys.

Changes:

  • Updated deriveChannelFromKey in send-policy.ts to check both positions for peerKind markers (group/channel), handling both old format (<channel>:<peerKind>:<peerId>) and new format (<channel>:<accountId>:<peerKind>:<peerId>)
  • Updated extractDiscordChannelId regex in exec-approvals.ts from /discord:(?:channel|group):(\d+)/ to /discord:(?:[^:]+:)?(?:channel|group):(\d+)/ to optionally match the accountId segment
  • Added comprehensive test coverage verifying both formats work correctly

Impact:

  • Restores channel-scoped send policy rules for first-use sessions
  • Fixes Discord exec approval channel-targeted workflows

Confidence Score: 5/5

  • Safe to merge with minimal risk - focused regression fix with backward compatibility
  • Fixes are minimal, targeted, and correct. Both functions now properly handle old and new session key formats. Comprehensive test coverage verifies backward compatibility and edge cases including thread suffixes, non-Discord channels, and DM sessions. Changes are isolated to two parsing functions with clear logic.
  • No files require special attention

Last reviewed commit: 2893c61

@thewilloftheshadow

Copy link
Copy Markdown
Member

Superceded by existing commits on main

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: discord Channel integration: discord size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants