Repository navigation
feat(session): add a delete API for native session journals - #3613
Closed
ningmao-hlyz wants to merge 5 commits into
Closed
ningmao-hlyz wants to merge 5 commits into
ningmao-hlyz wants to merge 5 commits into
Conversation
ningmao-hlyz
force-pushed
the
feat/delete-session-api
branch
2 times, most recently
from
October 16, 2026 13:13
c7437cf to
dfc709e
Compare
agentscope-ai#3567 records two leftovers of the session-history backend switch. This implements the deletion side, which is the urgent one for the 2.0.5 line: the journal storage lands there via the agentscope-ai#3441 backport and the gap blocks retention and privacy-compliance use cases. - SessionLogStore.delete(SessionKey, RuntimeContext) and AtomicSessionStorage.deletePaths(prefix), both optional like list. - LocalSessionStorage deletes the prefix subtree on POSIX, deepest first and refusing symlinked subtrees wholesale; SqliteSessionStorage deletes the prefix row range in one statement; InMemorySessionLogStore drops the session store. - HarnessAgent.deleteSession(rc) / (userId, sessionId), symmetric with clearContext: acquires the writer lease, so an active execution rejects the deletion, then removes the whole SessionKey namespace including the inbox and writer seals and drops the local caches. The lease record lives inside the deleted namespace and is deliberately not released. - Retention is intentionally not part of this change; explicit deletion is the primitive it would be built on. clearContext stays as-is and both are documented as distinct: clearing resets the model-visible context and appends a context_cleared checkpoint while the journal itself remains. Addresses agentscope-ai#3567
ningmao-hlyz
force-pushed
the
feat/delete-session-api
branch
from
October 16, 2026 13:25
dfc709e to
c08bf6f
Compare
ningmao-hlyz
force-pushed
the
feat/delete-session-api
branch
from
October 16, 2026 13:50
8125f5d to
d7ba95d
Compare
SqliteSessionStorage opened a fresh JDBC connection (plus a CREATE TABLE round-trip) for every read, list, compareAndSet and delete. Replaying a hundred-event journal therefore paid hundreds of connection setups, which dominates session-list traversal on Windows (measured: 17 sessions x 100 events went from ~2.8s to ~0.5s when each session opened its own storage instance, and to ~0.35s with one shared storage). The storage now keeps one long-lived connection per instance and holds the instance monitor for every operation, so in-process writers serialize exactly as SQLite file locks serialize them across processes. A failed operation closes and rebuilds the connection. LocalSessionStorage and the per-root cache in LocalFilesystem forward close so the database file is no longer held open once the caller is done; the read-early-return semantics are unchanged (reading an unwritten namespace still creates no database file).
This reverts commit bcfe398.
ningmao-hlyz
marked this pull request as draft
October 31, 2026 23:49
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
resolves #3612
AgentScope-Java Version
2.1.0-SNAPSHOT (main)
Description
Addresses the deletion half of #3567 (the issue owner is splitting it into separate deliverables;
the migration side is planned for 2.1 by the team, this one targets the 2.0.5 line where the
journal storage lands via the #3441 backport and the gap blocks retention and privacy-compliance
use cases).
Background
After the JEV switch, native session history lives in a protected namespace under
.agentscope-runtime/(local files or SQLite). There is no official way to delete one: thecontract layer has no delete primitive (
SessionLogStoreonly opens and lists;AtomicSessionStorageonly reads, lists and compare-and-sets), and users cannot reach the filesthemselves.
clearContextis not a substitute — it resets the model-visible context and appends acontext_clearedcheckpoint while the journal stays on disk.Changes
SessionLogStore.delete(SessionKey, RuntimeContext)andAtomicSessionStorage.deletePaths(String prefix), both optional (UnsupportedOperationbydefault, like
list).LocalSessionStoragedeletes the prefix subtree on POSIX, deepest first, refusing symlinkedsubtrees wholesale instead of deleting around them;
SqliteSessionStoragedeletes the prefixrow range in one statement (the DB file is not created by a delete);
InMemorySessionLogStoredrops the per-session store.
HarnessAgent.deleteSession(RuntimeContext)anddeleteSession(String userId, String sessionId),symmetric with
clearContext. It acquires the writer lease first, so an active execution rejectsthe deletion, then removes the whole
SessionKeynamespace — events, checkpoints, the inbox andwriter seals — and drops the local caches. The lease record lives inside the deleted namespace
and is deliberately not released.
event removal would break chain semantics, while the
SessionKeynamespace is self-contained.A tombstone + physical-reclaim two-phase mode can be discussed for audit-sensitive deployments
and is not part of this change.
How to test
Covers: namespace removal with sibling sessions untouched, restart-from-fresh on the deleted
session, rejection while an external writer holds the lease (and deletion succeeding after
release), the legacy-mode guard, SQLite row-range and file-subtree deletion, missing-prefix no-op,
and symlink refusal (the file-subtree deletion is two-phase: the whole subtree is scanned for
symlinks before anything is removed, so a refused deletion deletes nothing). Both new suites and
the full
agentscope-core+agentscope-harnesssuites pass locally.Two notes on scope: the remote store-backed storage does not implement
deletePathsyet, sodeleteSessionthrows on distributed deployments until that backend adds support — the localfile and SQLite backends, which the 2.0.5 line targets, are covered. The user-facing documentation
(
docs/v2/en/docs/building-blocks/context.md) gains a "Deleting a session" section next to theclearContextone, stating the difference and the writer-lease behavior.Checklist
Please check the following items before code is ready to be reviewed.
mvn spotless:applymvn test)