Commit cd0b4a6
authored
fix(events): stand by instead of exiting when the event runtime socket is owned (#561)
* fix(events): stand by instead of exiting when the event runtime socket is owned
A generated MCP server exited before answering `initialize` whenever another
process from the same plugin install already owned the event runtime socket
(`Event runtime endpoint already has a live server.`), so every session after
the first launched from one install root got no server at all.
`createEventRuntimeServer` gains `whenOwned: 'fail' | 'standby'` (default
`'fail'`, unchanged). Under `'standby'` a live owner is not fatal: the server
resolves in the `standby` role and a scope-bound fiber probes the endpoint
every ~1 s (jittered) and runs the existing `openServer` path the moment it is
free; the claim lock lets exactly one standby win. `EventRuntimeServer` exposes
`role()` and `onRoleChange()`. The generated runtime passes `'standby'` and
announces both the standby start and the takeover on stderr only.
Closes #559
* fix(events): hold the claim across teardown; report standby failures; guard role listeners
Self-review findings on #561 (752879a):
- close() now takes the endpoint claim before it stops listening and holds it
through the identity-checked removal, so no standby can bind a new socket at
the path — possibly on the inode the kernel just freed — before the old
owner's identity check runs. Standbys wait out the claim (bounded retries).
- The standby loop only swallows "still owned"; every other takeover failure
keeps it standing by but is reported through the new
`onStandbyError` option, which the generated runtime writes to stderr at one
line per distinct message per 30 s.
- Role listeners run in their own guards: a throwing listener is reported via
`onStandbyError` and never stops the remaining listeners or the transition.
* fix(events): never let a throwing onStandbyError reporter end the standby loop or skip role listeners
Every onStandbyError invocation goes through one guarded helper that
swallows a reporter throw, so the standby keeps probing and the remaining
role listeners still run (second-pass self-review finding on 43a85a1).1 parent d88cc10 commit cd0b4a6
9 files changed
Lines changed: 988 additions & 96 deletions
File tree
- .changeset
- packages/agent-bundle
- src
- events
- test
- tests
- website/docs
- en/guide/authoring
- zh/guide/authoring
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
32 | | - | |
| 32 | + | |
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| |||
731 | 731 | | |
732 | 732 | | |
733 | 733 | | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
| 758 | + | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
734 | 763 | | |
735 | 764 | | |
736 | 765 | | |
| |||
878 | 907 | | |
879 | 908 | | |
880 | 909 | | |
| 910 | + | |
| 911 | + | |
| 912 | + | |
| 913 | + | |
| 914 | + | |
| 915 | + | |
| 916 | + | |
| 917 | + | |
| 918 | + | |
881 | 919 | | |
882 | 920 | | |
883 | 921 | | |
| |||
888 | 926 | | |
889 | 927 | | |
890 | 928 | | |
891 | | - | |
| 929 | + | |
| 930 | + | |
| 931 | + | |
| 932 | + | |
892 | 933 | | |
893 | 934 | | |
894 | 935 | | |
| |||
966 | 1007 | | |
967 | 1008 | | |
968 | 1009 | | |
| 1010 | + | |
| 1011 | + | |
| 1012 | + | |
| 1013 | + | |
969 | 1014 | | |
| 1015 | + | |
| 1016 | + | |
| 1017 | + | |
| 1018 | + | |
| 1019 | + | |
| 1020 | + | |
| 1021 | + | |
| 1022 | + | |
970 | 1023 | | |
971 | 1024 | | |
972 | 1025 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
551 | 551 | | |
552 | 552 | | |
553 | 553 | | |
554 | | - | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
555 | 559 | | |
556 | 560 | | |
557 | 561 | | |
| |||
0 commit comments