Commit ff5fe2e
authored
fix(roomlog): self means this device, not this account (#94)
Closes #93, found during the first live session of an agent following a
room.
An agent and the person it works for share one Matrix account. `self`
compared the sender to the configured `user_id`, so it was true for both
of them:
```json
{"seq": 6, "type": "m.text", "sender": "@user:example.org", "self": true, "text": "… hey, claude? liest du mit?"}
{"seq": 7, "type": "reaction", "sender": "@user:example.org", "self": true, "text": "… reacted 👀"}
```
One of those is the human, one is the agent, and the flag that exists to
tell them apart says the same thing about both.
## Why it is not cosmetic
The flag is what an agent uses to avoid answering itself. As it stood:
- trusting it means ignoring the person addressing you
- ignoring it means answering yourself, which with autonomous replies
enabled is a loop with a homeserver in it
Neither shows up in a quiet room.
## The fix
A decrypted event carries `sender_key`, the curve25519 key of the
*device* that encrypted it, and the daemon knows its own via
`client.olm.account.identity_keys["curve25519"]`. `self` is now that
comparison.
An unencrypted room carries no `sender_key`. There the account
comparison is the only answer available, so the record also carries
`self_basis` — `"device"` or `"account"` — and a caller can tell which
question was actually answered instead of assuming the stronger one.
Own-device lines render as `Name (agent)`. The log is read by the agent
that wrote part of it, and same account means same display name.
## Verification
6 new tests, 41 in the file, including the two that carry the change:
the human's device on the same account is **not** self, and a missing
`sender_key` falls back to the account while saying so.
Live, against a running daemon in `#test`:
```json
{"seq": 3, "self": true, "self_basis": "device", "text": "[11:25] Sebastian Mendel (agent): 🤖 Prüfung: erkennt der Log jetzt sein eigenes Gerät?"}
```
**The negative case is covered by tests only.** Confirming it live needs
a message typed from the human's own device while the fixed daemon runs,
which this session could not produce on its own. Saying so rather than
implying the live check covered both.3 files changed
Lines changed: 121 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
60 | 65 | | |
61 | 66 | | |
62 | 67 | | |
| |||
74 | 79 | | |
75 | 80 | | |
76 | 81 | | |
77 | | - | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
78 | 108 | | |
| 109 | + | |
79 | 110 | | |
80 | 111 | | |
81 | 112 | | |
| |||
87 | 118 | | |
88 | 119 | | |
89 | 120 | | |
90 | | - | |
| 121 | + | |
| 122 | + | |
91 | 123 | | |
92 | 124 | | |
93 | 125 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
301 | 301 | | |
302 | 302 | | |
303 | 303 | | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
304 | 379 | | |
305 | 380 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
122 | 122 | | |
123 | 123 | | |
124 | 124 | | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
125 | 129 | | |
126 | 130 | | |
127 | 131 | | |
| |||
167 | 171 | | |
168 | 172 | | |
169 | 173 | | |
| 174 | + | |
170 | 175 | | |
171 | 176 | | |
172 | 177 | | |
| |||
194 | 199 | | |
195 | 200 | | |
196 | 201 | | |
| 202 | + | |
197 | 203 | | |
198 | 204 | | |
199 | 205 | | |
| |||
377 | 383 | | |
378 | 384 | | |
379 | 385 | | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
380 | 392 | | |
381 | 393 | | |
382 | 394 | | |
| |||
0 commit comments