Skip to content

Restore sessions from Docker container metadata after server restart#142

Merged
Yashb404 merged 4 commits intochore/upgrade-depfrom
copilot/sub-pr-141
Feb 13, 2026
Merged

Restore sessions from Docker container metadata after server restart#142
Yashb404 merged 4 commits intochore/upgrade-depfrom
copilot/sub-pr-141

Conversation

Copy link
Copy Markdown

Copilot AI commented Feb 13, 2026

After the Axum upgrade, the in-memory SessionMap is cleared on restart. Pre-existing Docker containers remain running but become inaccessible because their session metadata is lost.

Changes

Session metadata persistence via Docker labels

  • Added labels to containers: session_id, owner_id, project_owner_id, project_slug, shell, container_type
  • Applied to both viewer and builder container creation flows

Session restoration on startup

  • restore_sessions_from_containers() queries Docker API for all running TryCli containers
  • Rebuilds SessionContext from container labels
  • Preserves accurate container age using Docker's creation timestamp

Lazy restoration on reconnection

  • restore_specific_session() handles WebSocket connections to sessions not yet restored
  • Filters Docker containers by session_id label for targeted restoration

Security hardening

  • Generic error messages sent to clients (prevents Docker internals leakage)
  • Detailed errors logged server-side via tracing framework

Example

// Container labels now include session metadata
let labels = create_container_labels(
    &session_id,
    owner_id,
    project_owner_id,
    project_slug.as_deref(),
    &shell,
    "viewer",
);

// On startup, sessions are restored from running containers
pub async fn restore_sessions_from_containers(state: &AppState) {
    // Query Docker for containers with managed_by=TryCli Studio
    // Recreate SessionContext from labels
    // Preserve accurate timing from container.created timestamp
}

Backward Compatibility

Containers created before this change lack the new labels and won't be automatically restored. They follow existing cleanup behavior: reaped after 30s of inactivity.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 3 commits February 13, 2026 11:25
- Add metadata labels to containers (session_id, owner_id, shell, etc.)
- Restore sessions on server startup from existing containers
- Attempt session restoration on WebSocket reconnection
- Update container creation to include comprehensive labels
- Fix pre-existing containers accessibility after upgrade

Co-authored-by: Yashb404 <139128977+Yashb404@users.noreply.github.com>
- Replace detailed Docker/bollard errors with generic messages
- Keep detailed error logging server-side for debugging
- Prevent leaking internal operational details to clients

Co-authored-by: Yashb404 <139128977+Yashb404@users.noreply.github.com>
- Fix timer reset issue: preserve container age on restoration
- Replace println!/eprintln! with tracing::info!/error!
- Use container creation timestamp for accurate session age tracking

Co-authored-by: Yashb404 <139128977+Yashb404@users.noreply.github.com>
Copilot AI changed the title [WIP] Upgrade server dependencies for enhanced functionality Restore sessions from Docker container metadata after server restart Feb 13, 2026
Copilot AI requested a review from Yashb404 February 13, 2026 11:33
@Yashb404 Yashb404 marked this pull request as ready for review February 13, 2026 12:09
@Yashb404 Yashb404 merged commit 0280311 into chore/upgrade-dep Feb 13, 2026
@Yashb404
Copy link
Copy Markdown
Member

@copilot

the issue is still there , for the containers created before the dependency upgrade they are unable to connect , they do not load in the window.

in the terminal , an attempting to connect and then it fails with

[!] Failed to start viewer container. Please try again later.

[!] Connection Closed.

meanwhile the container was created in background but never connected to the screen

Server listening on port 3000...
Cleaning up session: 1ebcc645-b441-4e09-8b85-d718c838f829
Reaper: Killing Abandoned Session a5c5f89f-aabd-4df8-94d4-b9fe0dbd1360 (Never connected)

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.

2 participants