Skip to content

WIP: feat(session): add account namespace policy and shared sessions#1356

Open
qin-ctx wants to merge 2 commits intomainfrom
feat/account-namespace-shared-sessions
Open

WIP: feat(session): add account namespace policy and shared sessions#1356
qin-ctx wants to merge 2 commits intomainfrom
feat/account-namespace-shared-sessions

Conversation

@qin-ctx
Copy link
Copy Markdown
Collaborator

@qin-ctx qin-ctx commented Apr 10, 2026

Description

Implement the account-level namespace policy matrix and switch sessions to account-shared storage, so filesystem visibility, retrieval filters, session ownership, and message actor semantics all resolve from the same canonical namespace rules.

This PR also updates the session message contract:

  • trusted / ROOT / ADMIN may explicitly pass role_id
  • USER requests must derive role_id from request context
  • ADMIN may reuse X-OpenViking-User / X-OpenViking-Agent within its own account to simulate user view

Related Issue

Fixes #1351

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactoring (no functional changes)
  • Performance improvement
  • Test update

Changes Made

  • Add AccountNamespacePolicy plus namespace resolver helpers, and use canonical URI + (owner_user_id, owner_agent_id) tuples across VikingFS, context, vector indexing, retrieval filtering, and directory initialization.
  • Move sessions to account-shared viking://session/{session_id} paths, extend message persistence with role_id, track session participants, and enforce new auth semantics for ROOT / ADMIN / USER message writes.
  • Update admin APIs, Python clients, CLI/console flows, and add examples/multi_tenant/shared_session_role_id_http.py for one-shot setup of the four policy combinations and end-to-end verification of multi-user and normal-user scenarios.

Testing

  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have tested this on the following platforms:
    • Linux
    • macOS
    • Windows

Checklist

  • My code follows the project's coding style
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

Screenshots (if applicable)

N/A

Additional Notes

Demo script usage:

python examples/multi_tenant/shared_session_role_id_http.py \
  --url http://127.0.0.1:1933 \
  --root-key <root-key>

Optional flags:

  • --name-prefix demo-team to control generated account names
  • --run-id custom1234 to control generated account/session suffixes
  • --effective-agent-a / --effective-agent-b / --normal-user-agent to override demo agents

Notes:

  • I did not run the full test suite in this environment.
  • The commit passed the repository's ruff and ruff format pre-commit hooks.

Unify namespace resolution across filesystem, indexing, and session storage.
Add account-shared session paths, role_id auth semantics, and an HTTP demo
script for the four namespace-policy combinations.
@github-actions
Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 4 🔵🔵🔵🔵⚪
🏅 Score: 85
🧪 PR contains tests
🔒 No security concerns identified
✅ No TODO sections
🔀 Multiple PR themes

Sub-PR theme: Add account namespace policy resolution

Relevant files:

  • openviking/core/namespace.py
  • openviking/core/directories.py
  • openviking/storage/viking_vector_index_backend.py
  • openviking/storage/viking_fs.py

Sub-PR theme: Shared sessions and role_id semantics

Relevant files:

  • openviking/session/session.py
  • openviking/server/routers/sessions.py
  • tests/server/test_api_sessions.py

Sub-PR theme: Demo script and documentation

Relevant files:

  • examples/multi_tenant/shared_session_role_id_http.py
  • docs/design/account-namespace-shared-session-design.md

⚡ Recommended focus areas for review

Missing License Header

New file in openviking/ directory does not contain the required AGPL-3.0 license header.

"""Namespace policy helpers for account/user/agent/session URIs."""
Broad Exception Catch

_ensure_container_directory uses bare except Exception: without logging, which hides real errors.

try:
    await self._get_viking_fs().mkdir(uri, exist_ok=True, ctx=ctx)
except Exception:
    pass

@qin-ctx qin-ctx changed the title feat(session): add account namespace policy and shared sessions wip:feat(session): add account namespace policy and shared sessions Apr 10, 2026
@qin-ctx qin-ctx changed the title wip:feat(session): add account namespace policy and shared sessions wip feat(session): add account namespace policy and shared sessions Apr 10, 2026
@github-actions
Copy link
Copy Markdown

PR Code Suggestions ✨

No code suggestions found for the PR.

@qin-ctx qin-ctx changed the title wip feat(session): add account namespace policy and shared sessions feat(session): add account namespace policy and shared sessions Apr 10, 2026
@qin-ctx qin-ctx changed the title feat(session): add account namespace policy and shared sessions WIP: feat(session): add account namespace policy and shared sessions Apr 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

[Feature]: Account 级 User / Agent 命名空间策略与共享 Session 模型

1 participant