Skip to content

Inline Slack thread event context#97

Merged
kjgbot merged 5 commits into
mainfrom
fix/slack-thread-inline-event-context
Jun 5, 2026
Merged

Inline Slack thread event context#97
kjgbot merged 5 commits into
mainfrom
fix/slack-thread-inline-event-context

Conversation

@kjgbot

@kjgbot kjgbot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

User description

Summary

  • include Slack message/reply text, channel, thread ts, message ts, and user in injected integration-event system messages when the local Relayfile record is present
  • filter hidden/temp Relayfile mount files so local fallback watchers do not inject transient tmp paths
  • clarify integration guidance for event-file context when historical sync is disabled

Why

Logs showed Slack thread replies are received and injected, but agents only got a path-oriented notification. This makes thread commands actionable without requiring the agent to first read the mounted record, and avoids noisy tmp-file injections from local mount writes.

Test plan

  • node --experimental-strip-types --no-warnings --test src/main/tests/integration-event-bridge.test.ts
  • npm test
  • npm run build

CodeAnt-AI Description

Show Slack thread details directly in event notifications and ignore transient temp files

What Changed

  • Slack thread reply notifications now include the message text and key context such as channel, thread timestamp, message timestamp, and user when that information is available locally
  • Integration event messages now prefer inline event context first, so agents can act on Slack thread updates without opening the mounted record
  • Temporary and hidden relayfile paths are skipped, preventing noisy notifications from draft or temp writeback files
  • Guidance for integration events now tells agents to use inline event context and the event file path when historical records are not mounted

Impact

✅ Clearer Slack thread alerts
✅ Faster replies to thread requests
✅ Fewer noisy temp-file notifications

🔄 Retrigger CodeAnt AI Review

💡 Usage Guide

Checking Your Pull Request

Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.

Talking to CodeAnt AI

Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:

@codeant-ai ask: Your question here

This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.

Example

@codeant-ai ask: Can you suggest a safer alternative to storing this secret?

Preserve Org Learnings with CodeAnt

You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:

@codeant-ai: Your feedback here

This helps CodeAnt AI learn and adapt to your team's coding style and standards.

Example

@codeant-ai: Do not flag unused imports.

Retrigger review

Ask CodeAnt AI to review the PR again, by typing:

@codeant-ai: review

Check Your Repository Health

To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.

@codeant-ai

codeant-ai Bot commented Jun 5, 2026

Copy link
Copy Markdown

CodeAnt AI is reviewing your PR.

@coderabbitai

coderabbitai Bot commented Jun 5, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@kjgbot, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 14 minutes and 4 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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Free

Run ID: 505a8252-04d4-458b-ab98-8e7d1dc71ada

📥 Commits

Reviewing files that changed from the base of the PR and between ed8b961 and 073e1d5.

📒 Files selected for processing (6)
  • src/main/__tests__/integration-event-bridge.test.ts
  • src/main/integration-event-bridge.ts
  • src/main/integrations.catalog.ts
  • src/main/integrations.ts
  • src/renderer/src/components/settings/AccountSettings.tsx
  • src/renderer/src/components/settings/ProjectSettings.tsx
📝 Walkthrough

Walkthrough

Integration event bridge now augments Slack event messages with inline context extracted from local mount files or expanded event data. The change introduces context truncation, expands path filtering, and wires context lookups through the injection handlers while including new test coverage for thread-reply scenarios.

Changes

Slack Inline Event Context

Layer / File(s) Summary
Context extraction infrastructure
src/main/integration-event-bridge.ts
Adds MAX_INLINE_EVENT_TEXT_CHARS constant, truncateForSystemMessage helper for normalizing context text, and readFile import for local file-based context lookup.
Slack context detection and path filtering
src/main/integration-event-bridge.ts
Introduces helpers to detect Slack message/thread JSON context paths, parse Slack record JSON into labeled context lines with truncation, and fetch context via local-mount file reads with fallback to event.expand('full'). Extends Relayfile path filtering to skip dot-prefixed leaves and .tmp files.
Message formatting with context lines
src/main/integration-event-bridge.ts, src/main/integrations.ts
Updates formatIntegrationEventMessage to append context lines in the generated system message and revises embedded instructions to prefer inline context over .integrations path. Updates buildSystemMessageSnippet to clarify when to expect reliable notifications and how to choose between historical mounts vs. event context.
Event injection and context computation
src/main/integration-event-bridge.ts
Modifies injectEvent to accept localMountWorkspaceId, compute contextLines before formatting, and pass them to message construction. Updates both remote stream and local mount event handlers to provide handle.localMountWorkspaceId when calling injectEvent.
Test utilities and Slack thread reply scenarios
src/main/__tests__/integration-event-bridge.test.ts
Adds filesystem/temp utilities imports, introduces changeEventWithFullData builder for mocking expanded payloads, and waitForSent polling helper. Adds two integration tests verifying Slack thread-reply events include local or remote message text in the injected system message. Extends the ignore-temp-files test to also suppress .widgets files.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Poem

🐰 A slack thread now carries its whispered words,
Context pulled from local files unheard,
Or expanded data when mounts lag behind,
Every event enriched, no meaning unsigned,
Tests dance with replies—a feature so fine!


Note

🎁 Summarized by CodeRabbit Free

Your organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Pro by visiting https://app.coderabbit.ai/login.

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

@codeant-ai codeant-ai Bot added the size:L This PR changes 100-499 lines, ignoring generated files label Jun 5, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request enhances the integration event bridge to include local Slack message text and context (such as channel, timestamps, and user) directly within the injected system messages, while also filtering out temporary files from triggering notifications. The review identified two critical security vulnerabilities: an indirect prompt injection risk where unescaped Slack messages could prematurely close the event block, and a path traversal vulnerability in the path validation regex that could allow reading arbitrary local files.

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.

Comment on lines +117 to +120
function truncateForSystemMessage(text: string, maxChars = MAX_INLINE_EVENT_TEXT_CHARS): string {
const normalized = text.trim()
return normalized.length > maxChars ? `${normalized.slice(0, maxChars)}...` : normalized
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

security-high high

The Slack message text is injected directly into the system message within <integration-event> and </integration-event> tags. If a Slack message contains the closing tag </integration-event>, it can prematurely close the event block and inject arbitrary instructions to the LLM agent, leading to an Indirect Prompt Injection vulnerability.

To prevent this, sanitize the text by neutralizing or escaping any <integration-event> and </integration-event> tags before injecting them into the system message.

function truncateForSystemMessage(text: string, maxChars = MAX_INLINE_EVENT_TEXT_CHARS): string {
  const normalized = text.trim()
  const truncated = normalized.length > maxChars ? `${normalized.slice(0, maxChars)}...` : normalized
  return truncated
    .replace(/<\/integration-event>/gi, '[/integration-event]')
    .replace(/<integration-event>/gi, '[integration-event]')
}

Comment on lines +743 to +745
function slackEventContextPath(path: string): boolean {
return /^\/slack\/(?:channels|dms)\/[^/]+\/(?:messages|threads)\/.+\.json$/u.test(path)
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

security-high high

The slackEventContextPath function uses a wildcard .+ at the end of the regular expression, which can match path traversal sequences like ../../. Since the matched path is later used in localPathForRemoteRoot to resolve and read local files via readFile, this creates a Path Traversal vulnerability. A malicious event could exploit this to read arbitrary JSON files on the local system.

To mitigate this, explicitly reject any paths containing directory traversal segments (.. or . limiters).

Suggested change
function slackEventContextPath(path: string): boolean {
return /^\/slack\/(?:channels|dms)\/[^/]+\/(?:messages|threads)\/.+\.json$/u.test(path)
}
function slackEventContextPath(path: string): boolean {
if (path.split(/[\\/]/).some((seg) => seg === '..' || seg === '.')) return false
return /^\/slack\/(?:channels|dms)\/[^/]+\/(?:messages|threads)\/.+\.json$/u.test(path)
}

Comment thread src/main/integration-event-bridge.ts Outdated
Comment on lines +771 to +772
const localPath = localPathForRemoteRoot(localMountWorkspaceId, path)
const raw = await readFile(localPath, 'utf8').catch(() => null)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggestion: The local context file path is built directly from event.resource.path segments and then read from disk without validating path traversal segments. If an event path contains .. segments, join(...) can escape the workspace root and read unintended files. Reject any segment equal to .. (and other unsafe segments) before constructing the local path. [security]

Severity Level: Critical 🚨
- ❌ Integration event bridge can read arbitrary local JSON paths.
- ⚠️ Slack inline context may expose unintended workspace or system data.
Steps of Reproduction ✅
1. Set up an `IntegrationEventBridge` and reconcile a Slack integration so that
`reconcile()` in `src/main/integration-event-bridge.ts:153-259` subscribes to events and
associates a `localMountWorkspaceId` (as in the Slack inline-context test at
`src/main/__tests__/integration-event-bridge.test.ts:20-30`).

2. Cause a `ChangeEvent` to be emitted with `event.resource.provider === 'slack'` and a
path containing `..`, for example `event.resource.path =
'/slack/channels/C123/messages/../../../../../../etc/secret.json'`, which still matches
the `slackEventContextPath()` regex at `src/main/integration-event-bridge.ts:64-66`.

3. The subscription callback in `IntegrationEventBridge.reconcile()` at
`src/main/integration-event-bridge.ts:200-216` invokes `this.injectEvent(projectId, event,
specs, handle.localMountWorkspaceId)`, which in turn (after filtering and target
selection) calls `localEventContextLines(event, localMountWorkspaceId)` at
`src/main/integration-event-bridge.ts:335`.

4. Inside `localEventContextLines()` at `src/main/integration-event-bridge.ts:87-100`,
`localPath` is computed as `localPathForRemoteRoot(localMountWorkspaceId, path)` (line
771) which uses `pathSegments()` (lines 149-151) and `path.join()` in
`localPathForRemoteRoot()` (lines 64-66) without rejecting `..` segments; Node's `join()`
interprets `..` as parent-directory traversal, so `localPath` can resolve outside
`~/.agentworkforce/pear/relayfile/workspaces/<workspaceId>`, and `readFile(localPath,
'utf8')` (line 772) attempts to read that unintended file.

Fix in Cursor | Fix in VSCode Claude

(Use Cmd/Ctrl + Click for best experience)

Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** src/main/integration-event-bridge.ts
**Line:** 771:772
**Comment:**
	*Security: The local context file path is built directly from `event.resource.path` segments and then read from disk without validating path traversal segments. If an event path contains `..` segments, `join(...)` can escape the workspace root and read unintended files. Reject any segment equal to `..` (and other unsafe segments) before constructing the local path.

Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
👍 | 👎

@codeant-ai

codeant-ai Bot commented Jun 5, 2026

Copy link
Copy Markdown

CodeAnt AI finished reviewing your PR.

agent-relay-code Bot added a commit that referenced this pull request Jun 5, 2026
agent-relay-code Bot added a commit that referenced this pull request Jun 5, 2026
@kjgbot

kjgbot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor Author

Coordination note: a fix campaign is underway that touches this PR's area. Issue #82 (event/history sync overload — Tracks A–G, PR #98 open for Track A) and issue #99 (event delivery defects: doubled paths, tmp-file leaks, alias duplicate delivery, writeback self-echo) are being worked in parallel by dedicated agents. Relevant to this PR: the Slack thread inline event context work here intersects Track D (lazy context reads — event payloads carrying provider/resource/title context so agents don't need historical mounts). Fix notes will be posted on the issues as PRs land; rebase coordination is being handled in the agent-relay general channel.

@agent-relay-code

Copy link
Copy Markdown
Contributor

Reviewed PR #97 and made one targeted fix.

I found that the new Slack local inline-context fallback could map a Relayfile event path containing . or .. segments into a local filesystem read outside the intended workspace tree. I added a guard in integration-event-bridge.ts and a regression test in integration-event-bridge.test.ts.

Verified locally:
npm test -- src/main/__tests__/integration-event-bridge.test.ts
npm run build

Both passed locally. Build emitted existing Vite dynamic-import warnings, but no failures.

agent-relay-code Bot added a commit that referenced this pull request Jun 5, 2026
@agent-relay-code

Copy link
Copy Markdown
Contributor

pr-reviewer applied fixes — committed and pushed 5634a08 to this PR. The notes below describe what changed.

Reviewed PR #97 and made one targeted fix.

I found that the new Slack local inline-context fallback could map a Relayfile event path containing . or .. segments into a local filesystem read outside the intended workspace tree. I added a guard in integration-event-bridge.ts and a regression test in integration-event-bridge.test.ts.

Verified locally:
npm test -- src/main/__tests__/integration-event-bridge.test.ts
npm run build

Both passed locally. Build emitted existing Vite dynamic-import warnings, but no failures.

@agent-relay-code

Copy link
Copy Markdown
Contributor

Reviewed PR #97 against the current checkout. I didn’t find any reproducible breakage or stale bot-review items to fix, so I left the PR code unchanged.

Local verification passed:

  • npm test -- src/main/__tests__/integration-event-bridge.test.ts
  • npm run build

@agent-relay-code

Copy link
Copy Markdown
Contributor

ℹ️ 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.

Reviewed PR #97 against the current checkout. I didn’t find any reproducible breakage or stale bot-review items to fix, so I left the PR code unchanged.

Local verification passed:

  • npm test -- src/main/__tests__/integration-event-bridge.test.ts
  • npm run build

kjgbot pushed a commit that referenced this pull request Jun 5, 2026
kjgbot pushed a commit that referenced this pull request Jun 5, 2026
@kjgbot kjgbot force-pushed the fix/slack-thread-inline-event-context branch from 16278c0 to d115e53 Compare June 5, 2026 14:38
kjgbot pushed a commit that referenced this pull request Jun 5, 2026
@agent-relay-code

Copy link
Copy Markdown
Contributor

⚠️ pr-reviewer push failed (exit 1) — fixes were not applied to the PR. The notes below are advisory and were not pushed.

Fixed one validated issue in the current checkout: Slack local event record reads now reject ./.. path segments and verify the resolved file remains inside the relayfile workspace root before reading.

Added a regression in integration-event-bridge.test.ts where an escaped local file with stale webhook metadata must not suppress delivery or leak inline text.

Local validation passed:

  • npm test
  • npm run build

agent-relay-code Bot added a commit that referenced this pull request Jun 5, 2026
@agent-relay-code

Copy link
Copy Markdown
Contributor

pr-reviewer applied fixes — committed and pushed 8d4eadc to this PR. The notes below describe what changed.

Fixed a confirmed traversal issue in the Slack event bridge: local Slack event records now reject ./.. path segments before any local file read, including the live/backfill filtering path.

Updated the regression test so an escaped local file would suppress delivery if it were read, proving the guard applies before filtering as well as before inline context injection.

Validated locally:
node --experimental-strip-types --no-warnings --test src/main/__tests__/integration-event-bridge.test.ts
npm test
npm run build

kjgbot pushed a commit that referenced this pull request Jun 5, 2026
kjgbot pushed a commit that referenced this pull request Jun 5, 2026
kjgbot pushed a commit that referenced this pull request Jun 5, 2026
@kjgbot kjgbot force-pushed the fix/slack-thread-inline-event-context branch from 8d4eadc to 6992350 Compare June 5, 2026 14:46
kjgbot pushed a commit that referenced this pull request Jun 5, 2026
kjgbot pushed a commit that referenced this pull request Jun 5, 2026
kjgbot pushed a commit that referenced this pull request Jun 5, 2026
@kjgbot kjgbot force-pushed the fix/slack-thread-inline-event-context branch from 6992350 to b59a633 Compare June 5, 2026 14:55
@kjgbot kjgbot force-pushed the fix/slack-thread-inline-event-context branch from b59a633 to 073e1d5 Compare June 5, 2026 14:56
@kjgbot kjgbot merged commit 4ec4a71 into main Jun 5, 2026
3 checks passed
@kjgbot kjgbot deleted the fix/slack-thread-inline-event-context branch June 5, 2026 15:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L This PR changes 100-499 lines, ignoring generated files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant