Skip to content

fix(ai): use actorEmail for isYou in get_activity - #1324

Merged
2witstudios merged 2 commits into
masterfrom
pu/activity-tool
May 13, 2026
Merged

2witstudios merged 2 commits into
masterfrom
pu/activity-tool

Conversation

@2witstudios

@2witstudios 2witstudios commented May 13, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • get_activity was setting isYou: true based on activity.userId === userId, but userId (the session owner FK) and actorEmail (the denormalized actor snapshot) can diverge — most notably when an AI agent runs in the user's session under their userId but with a distinct actorEmail
  • This caused the LLM to say "you trashed X" when a collaborator (or agent with its own identity) actually did it; the UI activity log showed the correct actor because it reads actorEmail directly
  • Fix: look up the current user's email at tool execution time and compare activity.actorEmail === currentUserEmail, consistent with how the UI identifies actors

Test plan

  • Ask AI for a workspace update in a shared drive where a collaborator recently made changes — confirm it no longer attributes their actions to "you"
  • Verify your own recent activities still say "you" correctly
  • Run pnpm test:unit

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Refactor
    • Improved accuracy of activity tracking by identifying the current user via email for AI-generated activities; human (non-AI) activity attribution remains based on user ID.

Review Change Stack

Review Change Stack

userId and actorEmail can diverge (e.g. AI agent
activities logged under the session owner's userId but
with a distinct actorEmail). The UI identifies actors
by actorEmail; isYou now uses the same field so the
LLM no longer attributes others' actions to the user.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented May 13, 2026 •

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 5dbd7d3c-f768-4897-893c-b2342e98008a

📥 Commits

Reviewing files that changed from the base of the PR and between 8dfece6 and 769ef2b.

📒 Files selected for processing (1)
  • apps/web/src/lib/ai/tools/activity-tools.ts

📝 Walkthrough

Walkthrough

The activity tool switches actor identification from userId-based comparison to email-based comparison. It imports the users table, queries the current user's email during activity fetching, and uses email equality instead of userId equality to mark actors as "isYou".

Changes

Activity Actor Identification by Email

Layer / File(s) Summary
Activity actor identification by email
apps/web/src/lib/ai/tools/activity-tools.ts
The get_activity tool adds a users table import, queries the current user's email row during execution, and replaces the userId equality check with an actorEmail vs currentUserEmail comparison to determine isYou status for each activity actor.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • 2witstudios/PageSpace#216: Both PRs modify apps/web/src/lib/ai/tools/activity-tools.ts's actor identification logic around excluding or marking "own" activity—this PR switches identification from userId equality to actorEmail comparison.

Poem

🐰 An email arrives to tell the tale,
No more user IDs pale and frail—
We check the sender's address true,
And whisper gently: "That one's you!" 📧

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and clearly summarizes the main change: using actorEmail instead of userId for the isYou comparison in the get_activity function, which is the core fix described in the PR objectives.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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 pu/activity-tool

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.

❤️ Share

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

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8dfece6028

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Use userId for human activities (stable across email
changes) and actorEmail for AI-generated activities
(agents log under a distinct email even when running
in the user's session, so userId alone would wrongly
say 'you' for agent actions).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@2witstudios

Copy link
Copy Markdown
Owner Author

Re: Codex P2 — email change regression

Addressed in 769ef2b. The isYou logic now splits on isAiGenerated:

  • Human activities → use userId (stable across email changes ✓)
  • AI-generated activities → use actorEmail (agents log under a distinct email even when running in the session owner's context, so userId alone would incorrectly say "you" for agent actions ✓)

This handles both the original reported bug and preserves correct self-attribution after email changes.

@2witstudios
2witstudios merged commit 3793a18 into master May 13, 2026
3 checks passed
@2witstudios
2witstudios deleted the pu/activity-tool branch May 13, 2026 15:47
2witstudios added a commit that referenced this pull request May 15, 2026
* fix(ai): use actorEmail for isYou in get_activity

userId and actorEmail can diverge (e.g. AI agent
activities logged under the session owner's userId but
with a distinct actorEmail). The UI identifies actors
by actorEmail; isYou now uses the same field so the
LLM no longer attributes others' actions to the user.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* fix(ai): preserve isYou across email changes

Use userId for human activities (stable across email
changes) and actorEmail for AI-generated activities
(agents log under a distinct email even when running
in the user's session, so userId alone would wrongly
say 'you' for agent actions).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
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.

1 participant