Issue 365 Bell Credited The Wrong Person - edmozley/freeitsm GitHub Wiki
🔔 #365 The bell credited a change to someone who never made it
GitHub #365, reported by @duongtuanan · Notifications · fixed in 5.8.0 (#3022) · diagnosed with debug tool D021 (#3021)
What you saw
The bell said "Handed to your team by Nguyễn" about a ticket belonging to Company A and Team A - but Nguyễn works for Company B, in Team B, and had never touched the ticket. Other rows named other people from the wrong team the same way.
This was the second report on #365. The first (5.4.1, #362/#365) gave those rows their missing wording; this one is about the name.
What was wrong
A bell row does not store its sentence. It stores an event type and a copy of a name, and the browser builds "Handed to your team by {actor}" when the bell opens. That name came from one place - notificationsCurrentActor() in includes/notifications_router.php:
// Up to 5.7.0
function notificationsCurrentActor(): array
{
$id = isset($_SESSION['analyst_id']) ? (int)$_SESSION['analyst_id'] : 0;
$name = isset($_SESSION['analyst_name']) ? (string)$_SESSION['analyst_name'] : '';
return [$id, $name !== '' ? $name : null];
}
Whoever was signed in for the web request - full stop. That is right when a person changes a ticket. It is wrong whenever something else changes it inside their request:
- a workflow with Assign to team - it makes its change as
Workflow(the ticket history says System), but it runs inside whatever request set it off; - new mail fetched because somebody's inbox was open - every ticket, reply and routing it causes ran in their session.
So a workflow routing a Company A ticket to Team A, set off by something Nguyễn did (or by his open inbox fetching mail), was announced as "Handed to your team by Nguyễn".
And a second fault hid behind it: the same session id drives the "never tell me about my own action" rule. If Nguyễn was himself in the receiving team, he was left out of a notification about a change he never made.
How it was confirmed
Not from the report alone - the bell could have been telling the truth. A new debug tool, D021 - Notification bell: did that person really do it?, puts a ticket's bell rows beside its history (Audit) and the workflows that ran on it. On a test install: a workflow on priority changed that assigns Team A; an analyst changes the priority through the inbox's own endpoint. Before the fix:
Bell says : ZZ Nguyen (Company B)
History says : System (automatic - a workflow or the system)
Workflow runs near then: "ZZ 365 route to Team A"
VERDICT : AUTOMATIC CREDITED TO A PERSON
A hand assignment by the same analyst gave MATCH - the positive control.
The fix
1. Whatever acts says so. A new helper, NotificationActor (includes/notification_actor.php), holds who or what is acting. The workflow engine wraps every run in it; the mailbox import marks its whole request; the router asks it first and falls back to the request only when nothing has said:
// workflow/includes/engine.php - run()
return NotificationActor::run(
['kind' => 'workflow', 'id' => null, 'name' => (string)($wf['name'] ?? ''), 'source' => 'workflow', 'workflow_id' => $wfId],
fn() => self::runInner($wf, $event, $payload, $isManual, $dryRun)
);
The fallback order: an API key (acting as its analyst), a signed-in analyst, a portal user, otherwise FreeITSM itself (a scheduled job).
2. The bell says what it was. "Handed to your team by the workflow "Route Company A"", "Raised by email", "... by FreeITSM" - or a person's name when a person did it.
3. "Your own action" means a person's. Only an analyst (or their API key) counts; a workflow's surroundings never suppress anyone's notification.
4. Each row now records what made it - so the next time a name looks wrong, it can be checked instead of reasoned about:
| Column | Holds |
|---|---|
actor_kind |
analyst, portal_user, workflow, system, api |
actor_analyst_id |
the analyst, when a person (or their API key) did it - analyst ids only, on the leavers list as history |
source |
screen, portal, api, workflow, mail_import, scheduled |
workflow_id / api_key_id |
which workflow, which key |
When an unread row is merged with a later event on the same ticket ("3 updates"), the actor columns are updated with the event - a merged row describes its latest event, never the newest name beside the first event's kind.
📁 Files
| File | Change |
|---|---|
🟢 includes/notification_actor.php |
New - who or what is acting |
🟣 includes/notifications_router.php |
Takes the actor from NotificationActor; passes the detail to the row |
🟣 includes/services/notifications.php |
Stores the actor columns, on insert and on merge; sends actor_kind / source to the bell |
🟡 workflow/includes/engine.php |
Each run, and a form's own action list, acts as itself |
🟡 api/tickets/check_mailbox_email.php |
The import acts as FreeITSM (mail_import) |
🟡 assets/js/notification-bell.js |
Names a workflow, email or FreeITSM instead of a person |
⚪ database/freeitsm.sql, includes/db_verify_schema.php, includes/analyst_lifecycle.php |
The five columns |
⚪ lang/*/common.php |
notifications.actor_workflow, actor_system, actor_email |
🟢 tests/notification-actor.php |
18 checks over HTTP |
🟢 api/system/debug-tools/D021_bell_vs_history.php |
The debug tool |
How it was verified
tests/notification-actor.php (18 checks, test install, real endpoints): a workflow inside an analyst's request records kind workflow, its id and name, and the analyst - a member of the team - is told; a hand assignment records the analyst and source screen; a REST change records kind api with the key; your own action is still not news to you while a watcher hears of it credited to you; the mailbox import acts as FreeITSM with a workflow inside it still naming itself; a merged row carries the latest event's actor. The same reproduction run through D021 after the fix: MATCH, and the real bell reads Handed to your team by the workflow "ZZ 365 route to Team A" (checked in a browser). Existing notification, watcher, workflow and leaver tests all still pass.
What is not proven
- Mail import was checked in code and by the helper's own test, not by fetching real mail on the test install.
- Rows written before 5.8.0 keep the name they were given; they cannot be corrected, because they never recorded what made the change. D021 says so for those rows and pairs them by time.
What this means for you
Update to 5.8.0 and run System → Database Verification (it adds the columns). New notifications name what really made the change. To check an older one, run System → Debug tools → D021 with its ticket number.
Related: Notifications · Notifications - Developer Guide · Bugs resolved