Support for persistent sessions using local and remote (LaunchIT) MariaDB - #168
Support for persistent sessions using local and remote (LaunchIT) MariaDB#168amarathe84 wants to merge 5 commits into
Conversation
| SSL_KW = {} | ||
|
|
||
| # Create sync engine (SSL required by server; skip cert verification because tunnel is trusted) | ||
| try: |
There was a problem hiding this comment.
using the global namespace to run this code is problematic. uvicorn uses fork and so sometimes these objects are not preserved well. The engines need to be created lazily in a function context
There was a problem hiding this comment.
To address this, engine creation is now lazy and happens with get_async_engine() rather than at module import time. The module-level globals are only placeholders and are not constructed engine objects. Let me know if this looks good
There was a problem hiding this comment.
engine is still assigned in the global context...
There was a problem hiding this comment.
please also refactor this lengthy code into a function
There was a problem hiding this comment.
These were due to incorrect force-push from another branch and conflict resolution which didn't go as planned. Both of these (local cache instead of global context and refactor) have been handled now.
| with sync_engine.connect() as _conn: | ||
| _conn.execute(text('SELECT 1')) | ||
|
|
||
| # Also create async engine for compatibility |
There was a problem hiding this comment.
The sync engine functionality was initially added for CLI/debugging at my end with a couple of standalone test scripts to check consistency of database, functionality flow etc.. I’ve removed the sync engine since it isn’t used (the tests scripts are not part of this PR). I have a separate branch where I'm keeping the functionality required for debugging.
There was a problem hiding this comment.
I can still see it above. Is there a merge conflict?
There was a problem hiding this comment.
Yes, I had messed it up with the last push. I've correctly merged and pushed from my local branch
| sidebar_state: Mapped[Optional[str]] = mapped_column(JSON, nullable=True) | ||
|
|
||
| # Experiment context | ||
| experiment_context: Mapped[Optional[str]] = mapped_column(Text, nullable=True) |
There was a problem hiding this comment.
why is this Text and not JSON?
There was a problem hiding this comment.
FIxed this. experiment_context is now JSON based. Was originally plaintext for readability but I've switched to JSON
|
|
||
|
|
||
| # Pydantic models | ||
| class ExperimentData(BaseModel): |
There was a problem hiding this comment.
this repeats what we have in database/models, but looks better? Consolidate the two classes please
There was a problem hiding this comment.
Yes makes sense. Now these are combined into schemas.py. Code in projects.py imports and uses the shared schema definitions instead of redefining mapping classes locally.
| with sync_engine.connect() as _conn: | ||
| _conn.execute(text("SELECT 1")) |
There was a problem hiding this comment.
only one process will execute this!
There was a problem hiding this comment.
Good catch, silly mistake (based on my incorrect scope understanding earlier). New update to the code takes out eager validation and startup time DB side effect issue.
- Add db_backend/ package with SQLAlchemy models, schemas, and REST API routers for projects and sessions (CRUD + auto-save/restore) - Add useSessionPersistence hook for frontend auto-checkpoint logic - Update App.tsx with experiment persistence, restore-on-reload, and problemType fallback when DB row is not yet populated - Update project_sidebar.tsx with save/checkpoint UI controls - Update useProjectData.ts to integrate with the new DB backend - Add db_config.py for database connection configuration - Add .env.example with all required environment variables - Update mock_server.py with session save/restore, immediate persist on compute start, and background checkpoint support - Update .gitignore with Python, env, and build artifact patterns - Add sqlalchemy to requirements.txt
Description
This PR adds database-backed session persistence to the Flask Copilot:
Minor code hardening:
-Add automatic connection retry in case of network connection failure or stalled session. Also added a timeout for the overall experiment
-Fix the SSL configuration (no more
fake_flag_to_enable_tlsused previously)main()Unit/integration testing:
Checkpoint Creation & Updates
Checkpoint Persistence
5. Test checkpoint persists correct node count after disconnect
6. Test checkpoint persists correct edge count after disconnect
7. Test serverSessionId is correctly stored in checkpoint
8. Test isComputing flag is set to false in checkpoint after disconnect
9. Test checkpoint contains all required state fields (smiles, problemType, etc.)
10. Test checkpoint timestamp is updated on each save
Checkpoint Restoration
11. Test checkpoint restoration via /sessions/latest endpoint
12. Test checkpoint restoration via /sessions/{id} endpoint
13. Test resumed computation continues from checkpoint
Some Corner Case Handling
14. Test checkpoint handles malformed node data gracefully
15. Test checkpoint with maximum depth computation (compute complete and restore)