Skip to content

feat(session): durable save/resume via FileSessionStore - #92

Merged
divo12 merged 6 commits into
mainfrom
feat/session-save-resume
Aug 9, 2026
Merged

divo12 merged 6 commits into
mainfrom
feat/session-save-resume

Conversation

@divo12

@divo12 divo12 commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

User description

Summary

Typed FileSessionStore / SessionSnapshot (transcript + tool-call records + cost) under DreamPaths.sessions_dir, wired through Session.snapshot / restore_from_snapshot and Harness.save_session / resume_session for cross-process resume.

Snapshots are private by construction — they contain full transcripts, so they're written atomic_write_text(..., mode=0o600) rather than at the default umask.

Resume also restores the session's shape, not just its messages: SessionSnapshot persists max_turns and JSON-compatible metadata, and resume_session rebuilds SessionOptions from them when the caller passes none. response_format and non-JSON metadata values are deliberately not serialized (they aren't JSON-representable) — the resume_session / Session.snapshot docstrings state that callers must pass those explicitly.

Type

  • Bug fix
  • Feature
  • Refactor / docs / chore

Checklist

  • Tests added or updated for behaviour changes
  • tests/test_public_api.py updated if the public API changed
  • CHANGELOG.md updated for user-visible changes
  • No secrets, .env.local, or credentials in the diff
  • Scope stays within dream (org/company features belong in sibling repos)

Test plan

Link to Devin session: https://app.devin.ai/sessions/4f7deb4af0914056a24a4d660a661713
Requested by: @divo12


CodeAnt-AI Description

Save and resume sessions across process restarts

What Changed

  • Sessions can be saved to disk and resumed later with their transcript, tool calls, usage costs, and conversation state intact
  • Resumed sessions create a fresh engine and continue from the saved conversation
  • Model, system prompt, turn limits, and JSON-compatible metadata are restored automatically when no options are supplied
  • Snapshots are written atomically with restricted file permissions, and unsafe session IDs are rejected

Impact

✅ Sessions survive process restarts
✅ Tool calls remain connected to their results
✅ Continued conversations retain prior history and usage costs

💡 Usage Guide

Checking Your Pull Request

Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.

Talking to CodeAnt AI

Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:

@codeant-ai ask: Your question here

This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.

Example

@codeant-ai ask: Can you suggest a safer alternative to storing this secret?

Preserve Org Learnings with CodeAnt

You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:

@codeant-ai: Your feedback here

This helps CodeAnt AI learn and adapt to your team's coding style and standards.

Example

@codeant-ai: Do not flag unused imports.

Retrigger review

Ask CodeAnt AI to review the PR again, by typing:

@codeant-ai: review

Check Your Repository Health

To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.

Persist typed SessionSnapshot (transcript, tool-call records, cost) under
sessions_dir so Harness.resume_session can continue after process death.

Co-authored-by: Cursor <cursoragent@cursor.com>
@codeant-ai

codeant-ai Bot commented Aug 7, 2026

Copy link
Copy Markdown

🤖 CodeAnt AI — Review Status

Status Commit Started (UTC) Finished (UTC)
✅ Incremental review completed a91922b Aug 08, 2026 · 09:42 09:42
✅ Reviewed your PR 19d48f9 Aug 07, 2026 · 09:43 09:46

@codeant-ai

codeant-ai Bot commented Aug 7, 2026

Copy link
Copy Markdown

Thanks for using CodeAnt! 🎉

We're free for open-source projects. if you're enjoying it, help us grow by sharing.

Share on X ·
Reddit ·
LinkedIn

@codeant-ai codeant-ai Bot added the size:XXL This PR changes 1000+ lines, ignoring generated files label Aug 7, 2026
Comment thread docs/specs/session-layer-plan.html Outdated
Comment thread src/dream/harness.py
Comment thread src/dream/services/session_store.py Outdated
divo12 and others added 2 commits August 7, 2026 10:42
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@divo12

divo12 commented Aug 8, 2026

Copy link
Copy Markdown
Contributor Author

@greptileai please review

@greptile-apps

greptile-apps Bot commented Aug 8, 2026

Copy link
Copy Markdown

Greptile Summary

The PR adds durable, private session snapshots and harness APIs for saving and resuming conversations across process restarts.

  • Serializes transcripts, paired tool-call records, usage cost, effective turn limits, and JSON-compatible metadata.
  • Restores snapshots into newly created session engines while preserving conversation history and cost.
  • Rejects unsafe session IDs and writes snapshot files atomically with owner-only permissions.
  • Prevents snapshots during an active send and preserves the engine’s effective turn limit when no explicit session limit exists.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains; the effective turn-limit and snapshot-consistency issues from the previous review are addressed by persisting the bound engine’s resolved limit and synchronously rejecting snapshots while a send is active.

Important Files Changed

Filename Overview
src/dream/session.py Adds consistent snapshot creation and restoration, including effective turn-limit persistence, transcript sanitization, metadata filtering, and active-send rejection.
src/dream/harness.py Adds configurable file-store resolution and high-level save/resume APIs that bind restored state to a fresh engine.
src/dream/services/session_store.py Implements typed snapshot serialization, strict JSON decoding, safe session paths, atomic private writes, tool-call extraction, and cost conversion.
tests/test_services/test_session_store.py Covers persistence, permissions, traversal rejection, option restoration, active-send rejection, tool-call integrity, cost restoration, and resumed execution.
tests/evals/eval_session_save_resume.py Exercises cross-process transcript, tool-call, cost, and metadata restoration as an end-to-end correctness evaluation.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart LR
    A[Active Session] -->|snapshot when idle| B[SessionSnapshot]
    B -->|atomic JSON write, mode 0600| C[FileSessionStore]
    C -->|load by safe session ID| D[SessionSnapshot]
    D -->|restore options, transcript, and cost| E[Fresh Session Engine]
    E --> F[Continued Conversation]
Loading

Reviews (3): Last reviewed commit: "fix(session): stabilize snapshots for sa..." | Re-trigger Greptile

Comment thread src/dream/session.py Outdated
Comment thread src/dream/session.py
Remove the planning HTML artifact; session save/resume changes stay in code and specs.

Co-authored-by: Cursor <cursoragent@cursor.com>
@codeant-ai

codeant-ai Bot commented Aug 8, 2026

Copy link
Copy Markdown

Thanks for using CodeAnt! 🎉

We're free for open-source projects. if you're enjoying it, help us grow by sharing.

Share on X ·
Reddit ·
LinkedIn

@codeant-ai codeant-ai Bot added size:XXL This PR changes 1000+ lines, ignoring generated files and removed size:XXL This PR changes 1000+ lines, ignoring generated files labels Aug 8, 2026
divo12 and others added 2 commits August 8, 2026 15:16
Combine session save/resume notes with the merged Level-2 tool stack
entries; drop stale edit_file changelog line superseded by apply_patch.

Co-authored-by: Cursor <cursoragent@cursor.com>
Persist the engine's effective max_turns when SessionOptions omits it,
reject snapshot/save while send is in flight, and sanitize transcript
messages at the snapshot boundary so resumed sessions keep the same
turn budget and consistent tool-call history.

Co-authored-by: Cursor <cursoragent@cursor.com>
@divo12
divo12 merged commit 3679881 into main Aug 9, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XXL This PR changes 1000+ lines, ignoring generated files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant