refactor(session): remove request-scoped access grants (#5238)

This commit is contained in:
chengyongru authored and GitHub committed 2026-08-05 10:18:46 +08:00
1 parent 858f6d96a6
commit 6e9ae5bd05
12 files changed
+124 -230

No files matched your search

+2 -14
View File
@@ -20,11 +20,7 @@ from websockets.asyncio.server import ServerConnection, serve, unix_serve
from websockets.exceptions import ConnectionClosed
from websockets.http11 import Request as WsRequest
from nanobot.bus.events import (
INBOUND_META_SESSION_READ_SCOPE,
OUTBOUND_META_AGENT_UI,
OutboundMessage,
)
from nanobot.bus.events import OUTBOUND_META_AGENT_UI, OutboundMessage
from nanobot.bus.outbound_events import (
GoalStateSyncEvent,
GoalStatusEvent,
@@ -81,7 +77,6 @@ from nanobot.webui.metadata import (
WEBUI_TURN_METADATA_KEY,
)
from nanobot.webui.session_access import (
SessionAccessScope,
SessionMention,
WebuiSessionAccess,
session_mentions_runtime_context,
@@ -921,8 +916,6 @@ class WebSocketChannel(BaseChannel):
metadata["webui"] = True
metadata.update(self._transcripts.client_turn_metadata(envelope.get("turn_id")))
trusted_webui = metadata.get("webui") is True and connection in self._webui_connections
if trusted_webui:
metadata[INBOUND_META_SESSION_READ_SCOPE] = f"{self.name}:"
cli_apps = normalize_cli_app_mentions(envelope.get("cli_apps"))
if cli_apps:
metadata["cli_apps"] = cli_apps
@@ -937,12 +930,7 @@ class WebSocketChannel(BaseChannel):
session_mentions = await asyncio.to_thread(
self._session_access.normalize_mentions,
envelope.get("session_mentions"),
SessionAccessScope(
current_session_key=f"{self.name}:{cid}",
session_key_prefix=f"{self.name}:",
project_path=scope.project_path,
restrict_to_workspace=scope.restrict_to_workspace,
),
exclude_session_key=f"{self.name}:{cid}",
)
if session_mentions:
metadata["session_mentions"] = session_mentions
@@ -13,7 +13,6 @@ from websockets.exceptions import ConnectionClosed
from websockets.frames import Close
from nanobot.bus.events import (
INBOUND_META_SESSION_READ_SCOPE,
OUTBOUND_META_AGENT_UI,
OutboundMessage,
)
@@ -416,7 +415,6 @@ async def test_webui_message_envelope_marks_inbound_metadata(bus: MagicMock) ->
assert msg.channel == "websocket"
assert msg.chat_id == "chat-1"
assert msg.metadata["webui"] is True
assert INBOUND_META_SESSION_READ_SCOPE not in msg.metadata
assert msg.metadata["webui_turn_id"] == "turn-1"
assert msg.metadata["_wants_stream"] is True
lines = read_transcript_lines("websocket:chat-1")
@@ -15,11 +15,11 @@ from unittest.mock import AsyncMock, MagicMock, patch
import pytest
from nanobot.bus.events import INBOUND_META_SESSION_READ_SCOPE
from nanobot.channels.websocket.runtime import (
WebSocketChannel,
WebSocketConfig,
)
from nanobot.runtime_context import RUNTIME_CONTEXT_INPUT_META
from nanobot.session import webui_turns as wth
from nanobot.session.manager import SessionManager
from nanobot.webui.gateway_services import build_gateway_services
@@ -219,13 +219,12 @@ async def test_webui_message_forwards_verified_session_mentions(tmp_path) -> Non
channel._handle_message.assert_awaited_once()
metadata = channel._handle_message.call_args.kwargs["metadata"]
assert metadata[INBOUND_META_SESSION_READ_SCOPE] == "websocket:"
assert metadata["session_mentions"] == [{
"name": "pricing",
"session_key": "websocket:pricing",
"title": "Pricing",
}]
[block] = metadata["_runtime_context_blocks"]
[block] = metadata[RUNTIME_CONTEXT_INPUT_META]
assert block.source == "session_mentions"
assert "websocket:pricing" in block.content