Skip to content

fix: accept agent_id from params in registry channel join for register-on-join flow - #70

Merged
ihorkatkov merged 2 commits into
mainfrom
fix/registry-join-agent-id-fallback
Apr 7, 2026
Merged

ihorkatkov merged 2 commits into
mainfrom
fix/registry-join-agent-id-fallback

Conversation

@ihorkatkov

Copy link
Copy Markdown
Contributor

Summary

  • Fixes agent_id_required error when plugins join registry channels after using the register-on-join WebSocket flow
  • Root cause: Phoenix channels have isolated socket assigns per channel process — the agent_id assigned during agent:register join is not visible to subsequent registry:{token} channel joins on the same socket connection
  • Fix: Accept agent_id from join params as a fallback when socket.assigns.agent_id is nil; authorize_registry_join/2 still validates the agent exists and belongs to the registry

Changes

Server (lib/viche_web/channels/agent_channel.ex)

Registry join handler now falls back to params["agent_id"] when socket assigns are empty. Security is preserved — authorize_registry_join/2 validates agent membership.

Client (channel/opencode-plugin-viche/service.ts)

Passes { agent_id: agentId } when joining registry channels after registration.

Tests (test/viche_web/channels/agent_channel_test.exs)

  • New: register-on-join → registry join with agent_id in params succeeds
  • New: registry join still returns agent_id_required when neither assigns nor params contain agent_id

…r-on-join flow

Phoenix channels have isolated socket assigns per channel process.
When using the register-on-join flow (connect without agent_id, then
join agent:register), the agent_id assigned during registration is
not visible to subsequent registry channel joins. This caused
'agent_id_required' errors when plugins tried to join registry
channels after registering.

Accept agent_id from join params as a fallback when socket assigns
are empty. The existing authorize_registry_join/2 call ensures the
agent exists and belongs to the requested registry.
Plugin stderr bleeds into the OpenCode TUI input area, creating
visual noise. Remove informational lifecycle logs (connected,
disconnected, recovered) while keeping error/failure logs that
indicate actual problems.
@ihorkatkov
ihorkatkov merged commit 46367ee into main Apr 7, 2026
3 checks passed
@ihorkatkov
ihorkatkov deleted the fix/registry-join-agent-id-fallback branch April 7, 2026 21:48
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.

1 participant