Skip to content

Fix clientId usage to follow LiveStore best practices#209

Merged
rgbkrk merged 3 commits intomainfrom
fix/clientid-follows-livestore-best-practices
Sep 3, 2025
Merged

Fix clientId usage to follow LiveStore best practices#209
rgbkrk merged 3 commits intomainfrom
fix/clientid-follows-livestore-best-practices

Conversation

@rgbkrk
Copy link
Member

@rgbkrk rgbkrk commented Sep 3, 2025

This PR fixes the incorrect usage of clientId in the runt runtime agent system.

Problem

Previously, the system was setting clientId = userId, which goes against LiveStore's design principles. According to the LiveStore docs and guidance from the maintainer @schickling:

  • clientId should identify device/app instances, not users
  • Multiple devices/tabs from the same user should have different clientIds
  • User identification should be handled separately in the sync payload

Solution

  1. Modified discoverUserIdentity() to return both user info and generate a proper clientId using the pattern userId-{uniqueId}

  2. Updated authentication flow to:

    • Generate unique clientId for each runtime instance
    • Pass userId separately in sync payload for authorization
    • Maintain backward compatibility with existing auth patterns
  3. Updated schema documentation to reflect correct LiveStore patterns

  4. Fixed all tests to include the required userId parameter

Changes

  • packages/pyodide-runtime-agent/src/auth.ts: Enhanced to return both userId and generated clientId
  • packages/lib/src/types.ts: Added userId to RuntimeAgentOptions
  • packages/lib/src/config.ts: Added userId to RuntimeConfig
  • packages/lib/src/runtime-agent.ts: Added userId to sync payload
  • packages/schema/mod.ts: Updated authentication pattern documentation
  • All test files: Added userId parameter to RuntimeConfig instances

- Generate clientId using userId prefix + unique identifier instead of using userId directly
- Add userId to sync payload for proper authorization
- Update authentication pattern to separate client identification from user identification
- clientId now identifies device/app instances, userId identifies users for auth
- Update all tests and schema documentation to reflect new pattern

Fixes the issue where clientId was incorrectly set to userId, which goes against
LiveStore's design where clientId should identify unique client instances.
- Update Logger class default from ERROR to INFO
- Update pyodide runtime agent log level parsing defaults
- Ensure INFO is used when RUNT_LOG_LEVEL environment variable is not set
- Matches documented behavior that default is INFO
- Tests continue to explicitly set ERROR level so remain unaffected
- Remove anonymous user clientId pattern from schema documentation
- Change default notebook ownerId fallback from 'anonymous' to 'unknown'
- Runt system is designed for authenticated users only, no anonymous access
@rgbkrk rgbkrk merged commit 6209fcc into main Sep 3, 2025
7 checks passed
@rgbkrk rgbkrk deleted the fix/clientid-follows-livestore-best-practices branch September 3, 2025 14:58
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