Commit a600b79
authored
Fix Agents send principal attribution (#4604)
Fixes Electric Agents sends from the CLI and web UI by removing
client-supplied legacy `from` attribution. CLI requests now always
include a useful default `Electric-Principal` header
(`system:cli-<os-username>`), so the server can keep deriving sender
attribution from the authenticated principal.
## Root Cause
The Agents send endpoint validates that any request body `from` value
matches the authenticated `Electric-Principal`. Current clients could
still send stale/display-level attribution (`from: "user"` in the UI
repro, and the CLI's identity string), which does not match the server
principal and produced `400 Request from must match Electric-Principal`.
## Approach
- Stop sending `from` in `electric-ax agents send`; the request body now
contains only `payload` and optional `type`.
- Give the CLI a default principal header of `system:cli-<os-username>`
when `ELECTRIC_AGENTS_PRINCIPAL` is not set.
- Stop the web UI send helper from resolving and posting a `from` value;
optimistic local rendering still uses the active principal locally,
while server writes are attributed by the server.
- Keep server validation strict instead of adding backward-compatible
aliases.
## Key Invariants
- Request body `from`, when present, must match the authenticated
principal.
- First-party clients should not post `from` for normal user sends.
- Server-side attribution remains the source of truth for persisted
inbox messages.
## Non-goals
- No compatibility shim for old clients that still send `from: "user"`.
- No changes to server-side authorization or principal validation
semantics.
## Trade-offs
I initially considered accepting `from: "user"` server-side as a
compatibility alias, but that weakens the clarity of the send invariant.
Since backwards compatibility is not required here, updating the current
clients keeps the contract simpler.
## Verification
```bash
cd packages/electric-ax
pnpm exec vitest run test/cli.test.ts
cd ../agents-server-ui
pnpm run typecheck
```
Also ran the changeset checker:
```bash
GITHUB_BASE_REF=main node scripts/check-changeset.mjs
```
## Files changed
- `.changeset/fix-cli-principal-send.md` — patch changeset for
`electric-ax` and `@electric-ax/agents-server-ui`.
- `packages/electric-ax/src/index.ts` — default CLI principal header and
no `from` field in sends.
- `packages/electric-ax/test/cli.test.ts` — coverage for default CLI
principal and send request body.
- `packages/agents-server-ui/src/lib/sendMessage.ts` — remove send-body
principal resolution and `from` posting.
---
Fixes #46021 parent e6171a9 commit a600b79
4 files changed
Lines changed: 54 additions & 52 deletions
File tree
- .changeset
- packages
- agents-server-ui/src/lib
- electric-ax
- src
- test
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
8 | | - | |
9 | | - | |
10 | | - | |
11 | | - | |
12 | | - | |
| 7 | + | |
13 | 8 | | |
14 | | - | |
15 | 9 | | |
16 | 10 | | |
17 | 11 | | |
| |||
309 | 303 | | |
310 | 304 | | |
311 | 305 | | |
312 | | - | |
313 | 306 | | |
314 | 307 | | |
315 | 308 | | |
| |||
320 | 313 | | |
321 | 314 | | |
322 | 315 | | |
323 | | - | |
324 | 316 | | |
325 | 317 | | |
326 | | - | |
327 | | - | |
328 | | - | |
329 | | - | |
330 | 318 | | |
331 | 319 | | |
332 | 320 | | |
| |||
339 | 327 | | |
340 | 328 | | |
341 | 329 | | |
342 | | - | |
343 | 330 | | |
344 | 331 | | |
345 | 332 | | |
| |||
381 | 368 | | |
382 | 369 | | |
383 | 370 | | |
384 | | - | |
385 | | - | |
386 | | - | |
387 | | - | |
388 | | - | |
389 | | - | |
390 | | - | |
391 | | - | |
392 | | - | |
393 | | - | |
394 | | - | |
395 | | - | |
396 | | - | |
397 | | - | |
398 | | - | |
399 | | - | |
400 | | - | |
401 | | - | |
402 | | - | |
403 | | - | |
404 | | - | |
405 | | - | |
406 | | - | |
407 | | - | |
408 | | - | |
409 | | - | |
410 | | - | |
411 | 371 | | |
412 | 372 | | |
413 | 373 | | |
| |||
455 | 415 | | |
456 | 416 | | |
457 | 417 | | |
458 | | - | |
459 | 418 | | |
460 | 419 | | |
461 | 420 | | |
| |||
464 | 423 | | |
465 | 424 | | |
466 | 425 | | |
467 | | - | |
468 | | - | |
469 | | - | |
470 | | - | |
471 | 426 | | |
472 | 427 | | |
473 | 428 | | |
474 | 429 | | |
475 | | - | |
476 | 430 | | |
477 | 431 | | |
478 | 432 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
134 | 134 | | |
135 | 135 | | |
136 | 136 | | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
137 | 141 | | |
138 | 142 | | |
139 | 143 | | |
| |||
167 | 171 | | |
168 | 172 | | |
169 | 173 | | |
| 174 | + | |
170 | 175 | | |
171 | 176 | | |
172 | 177 | | |
173 | 178 | | |
174 | 179 | | |
175 | 180 | | |
176 | 181 | | |
177 | | - | |
| 182 | + | |
178 | 183 | | |
179 | 184 | | |
180 | 185 | | |
| |||
571 | 576 | | |
572 | 577 | | |
573 | 578 | | |
574 | | - | |
575 | 579 | | |
576 | 580 | | |
577 | 581 | | |
| |||
825 | 829 | | |
826 | 830 | | |
827 | 831 | | |
828 | | - | |
| 832 | + | |
829 | 833 | | |
830 | 834 | | |
831 | 835 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
132 | 132 | | |
133 | 133 | | |
134 | 134 | | |
135 | | - | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
136 | 147 | | |
137 | 148 | | |
138 | 149 | | |
| |||
351 | 362 | | |
352 | 363 | | |
353 | 364 | | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
354 | 392 | | |
355 | 393 | | |
356 | 394 | | |
| |||
0 commit comments