Skip to content

Signal: after a restart, a changed reaction leaves the old emoji on the message too - #819

Closed
itz4blitz wants to merge 1 commit into
mainfrom
issue/739-signal-reaction-restart
Closed

itz4blitz wants to merge 1 commit into
mainfrom
issue/739-signal-reaction-restart

Conversation

@itz4blitz

Copy link
Copy Markdown
Collaborator

What changed and why

A Signal reaction is kept per message and person in a file the Signal adapter owns. After chatd restarts, or after the in-memory cap drops an entry, a new emoji from that person replaces the old one instead of leaving both on the message. Incoming reactions and the user's own reactions use that record.

Type

  • feature
  • fix
  • perf
  • refactor
  • chore
  • docs

Platforms

  • windows
  • macos
  • linux
  • android
  • ios

Proof

Scenario: e2e/scenarios/signal-reaction-restart

Lab run: not run

Compatibility

No protocol change and no store schema change. Reactions on a message are still a count. An older client still shows them. The who-reacted list is unchanged.

Risk and rollback

A bad record can remove the wrong emoji when someone reacts again. The message text is untouched. Revert this commit to undo it. The reaction file can be deleted; the next reaction then starts fresh.

Release note

A changed Signal reaction replaces the previous emoji after a restart.

Tested

cargo test -p chatd --test signal --no-default-features reaction, which restarts chatd on the same store between two reactions from the same person, and the existing reaction test. cargo clippy -p chatd --no-default-features --all-targets.

Not tested: no live Signal account, and the lab was not run.

Closes #739

@github-actions

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Tiny Code Review

⚠️ Code review unavailable · run

the AI provider rate-limited the request

This is advice, not a gate. Re-run with the agent:review label or a /review comment.

@unRekable unRekable left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Code Review

🟡 2 findings (0 blocking).

The diff keeps each person's last Signal reaction in a per-account file under signal/, next to the existing .state files, so a new emoji after a restart or an eviction still answers the emoji it replaces. The path is built from an is_aci-validated UUID, there is no protocol or store schema change, and the regression test fails on main. Two things keep the record from being trustworthy as written: the write truncates the file in place with every error swallowed, and the file grows without bound from peer reactions while every reaction event re-reads and rewrites all of it under the Live mutex both adapter threads share.

Residual risk

  • The record outlives sign-out: without() still returns None and nothing deletes signal/.reactions, so the person, message and emoji rows stay plaintext on disk after the account is gone. The same data already sits in chat.sqlite, so this is one more copy rather than a new exposure class.
  • A crash between live.react's file write and the caller's store update leaves the file ahead of the store; the next reaction then removes an emoji the store does not have and the old emoji lingers on the message until a later change. The PR body acknowledges this class of stale record.
  • The removal a stale row triggers is scoped to (message, person) and drives only local store updates, never a send, so a wrong record cannot remove another person's reaction or reach the network.

Comment thread crates/chatd/src/adapters/signal.rs Outdated
let Ok(bytes) = serde_json::to_vec(&rows) else {
return;
};
let _ = std::fs::write(path, bytes);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

⚠️ Major: This file is the only carrier of the fix across a restart, but it is written by truncating in place with every error swallowed: chatd being killed mid-write leaves JSON that read_reactions treats as empty, and an unwritable disk silently reverts the fix with no log line. Write to a sibling temp file and rename it over the target, and log a warn when that fails.

Suggested change
let _ = std::fs::write(path, bytes);
let temp = path.with_extension("tmp");
if std::fs::write(&temp, bytes).and_then(|()| std::fs::rename(&temp, path)).is_err() {
tracing::warn!("chatd: Signal: the reaction record could not be kept");
}

Comment thread crates/chatd/src/adapters/signal.rs Outdated
}
None => self.reactions.remove(&key),
};
write_reactions(&self.reactions_path, &book);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

⚠️ Major: The file takes one row per (message, person) any peer ever reacts to and never prunes it: the RAM map is capped at REACTIONS_KEPT but the file, as the new comment says, is not, and its row strings come straight off Signal's JSON with no length check. Every reaction event re-reads and re-serializes all of it while holding the Live mutex both adapter threads share, so years of use make each event pay a full read, parse and rewrite of an ever-growing file. Bound it the way the RAM map is bounded: record an order or timestamp per row, prune the book to REACTIONS_KEPT here before writing, and skip the read when the file is oversized.

@itz4blitz

Copy link
Copy Markdown
Collaborator Author

Superseded by and merged in #903 (d387971 — Release 2026-11-20 combined PR).

@itz4blitz itz4blitz closed this Nov 21, 2026
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.

Signal: after a restart, a changed reaction leaves the old emoji on the message too

2 participants