Skip to content

Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors

Rust

fix(handoff): extend the create_on_session_end opt-out to OpenCode turn checkpoints

AkitaOnRails7dada68e0359
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4382e748..b080842a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -61,7 +61,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added `[handoff].create_on_session_end` (default `true` - unchanged
behavior). When set to `false`, unmanaged session ends write the session
summary page and enqueue consolidation as usual, but skip creating an
- automatic open handoff for the next session. Explicit handoffs created via
+ automatic open handoff for the next session; OpenCode turn checkpoints
+ refresh the page without a baton too. Explicit handoffs created via
`memory_handoff_begin` and managed workstream runs remain unaffected.
Server-wide: applies to every operator on this server. (#1043)
- Added a default-quit prompt after a successful interactive managed run so the
diff --git a/crates/ai-memory-hooks/src/router.rs b/crates/ai-memory-hooks/src/router.rs
index 23d74858..8400a110 100644
--- a/crates/ai-memory-hooks/src/router.rs
+++ b/crates/ai-memory-hooks/src/router.rs
@@ -3523,8 +3523,12 @@ async fn process_authorized(
// Other harnesses are not gated: Claude Code also sets `agent_type` on
// a top-level `--agent` session, which still owns its baton.
let child_session = env.agent == AgentKind::OpenCode && body_is_subagent(&env.raw);
+ // The opt-out covers both automatic batons: a session's end and an
+ // OpenCode root-turn checkpoint, which is OpenCode's only baton since
+ // a plugin unload no longer ends its sessions. The checkpoint still
+ // refreshes the summary page.
let should_create_handoff =
- !managed && !child_session && (turn_checkpoint || state.create_handoff_on_session_end);
+ !managed && !child_session && state.create_handoff_on_session_end;
let handoff = should_create_handoff.then(|| {
build_auto_handoff(
page_ws,
@@ -11390,6 +11394,77 @@ mod tests {
);
}
+ async fn end_direct_codex_session(
+ state: &HookState,
+ tmp: &TempDir,
+ managed_run: Option<String>,
+ ) {
+ let session = SessionId::new();
+ for event in ["session-start", "user-prompt", "session-end"] {
+ let envelope = HookEnvelope::from_query_and_body(
+ HookQuery {
+ event: event.into(),
+ agent: Some("codex".into()),
+ cwd: Some(tmp.path().to_string_lossy().into_owned()),
+ workspace: Some("default".into()),
+ project: Some("scratch".into()),
+ managed_run: managed_run.clone(),
+ ..Default::default()
+ },
+ serde_json::json!({
+ "session_id": session.to_string(),
+ "cwd": tmp.path(),
+ "prompt": "Ship the parser fix",
+ }),
+ );
+ process(state, envelope, None, Vec::new()).await.unwrap();
+ }
+ }
+
+ #[tokio::test]
+ async fn session_end_opt_out_leaves_managed_runs_unchanged() {
+ let tmp = TempDir::new().unwrap();
+ let mut state = make_state(&tmp).await;
+ state.create_handoff_on_session_end = false;
+ end_direct_codex_session(&state, &tmp, Some(ManagedRunId::new().to_string())).await;
+ assert!(
+ !session_pages(&state).await.is_empty(),
+ "a managed session end still writes its summary page"
+ );
+ assert!(!open_handoff_exists(&state).await);
+ }
+
+ /// OpenCode's root-turn checkpoint is its baton (a plugin unload no longer
+ /// ends the session), so the opt-out must cover it too. The checkpoint
+ /// still refreshes the summary page.
+ #[tokio::test]
+ async fn opencode_turn_checkpoint_honours_create_on_session_end_opt_out() {
+ let tmp = TempDir::new().unwrap();
+ let mut state = make_state(&tmp).await;
+ state.create_handoff_on_session_end = false;
+ let session = SessionId::new();
+ let text = "Implemented the opt-out turn";
+ process(
+ &state,
+ opencode_turn_event(&session.to_string(), "user-prompt", text),
+ None,
+ Vec::new(),
+ )
+ .await
+ .unwrap();
+ let mut stop = opencode_turn_event(&session.to_string(), "stop", text);
+ crate::assistant_capture::apply_assistant_backstop(&mut stop, true);
+ process(&state, stop, None, Vec::new()).await.unwrap();
+ assert!(
+ !session_pages(&state).await.is_empty(),
+ "the checkpoint still refreshes the summary page"
+ );
+ assert!(
+ !open_handoff_exists(&state).await,
+ "create_on_session_end = false must not write a checkpoint baton"
+ );
+ }
+
#[tokio::test]
async fn session_end_with_create_on_session_end_enabled_creates_handoff() {
let tmp = TempDir::new().unwrap();
diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md
index 3ca42214..4c6dd2e7 100644
--- a/docs/ARCHITECTURE.md
+++ b/docs/ARCHITECTURE.md
@@ -200,7 +200,8 @@ metadata-only notice naming the exact handoff id and leaves the row open for
an explicit `memory_handoff_accept`; the managed event range is still claimed.
With server-wide `[handoff].create_on_session_end = false`, session end writes
the summary page and enqueues consolidation but skips creating an automatic
-baton (#1043). Manual handoffs take precedence;
+baton, and an OpenCode root-turn checkpoint refreshes the page without one
+(#1043). Manual handoffs take precedence;
otherwise the newest cwd-eligible automatic handoff is delivered, and that
same transaction expires older eligible automatic handoffs while preserving
manual and sibling-directory work. Insertion also expires prior open automatic
@@ -815,7 +816,7 @@ per_user = false # shared + own slots in agent context
[handoff] # optional server-wide handoff policy
claim_on_session_start = true # false offers metadata; explicit accept claims
-create_on_session_end = true # false stops automatic handoff creation at session end
+create_on_session_end = true # false stops automatic handoffs at session end and OpenCode turn checkpoints
[consolidation] # LLM consolidation prompt sizing
max_input_tokens = 100000 # approximate whole-input target; min 6000
diff --git a/docs/usage.md b/docs/usage.md
index 573c50a7..764d648c 100644
--- a/docs/usage.md
+++ b/docs/usage.md
@@ -113,7 +113,7 @@ By default, every unmanaged session end creates an open handoff for the next ses
create_on_session_end = false
```
-When set to `false`, `SessionEnd` writes `sessions/<id>.md` and queues consolidation as usual, but skips creating an open handoff row (#1043). Explicit batons created with `memory_handoff_begin` and managed workstream runs remain unaffected. Like `claim_on_session_start`, this setting is server-wide.
+When set to `false`, `SessionEnd` writes `sessions/<id>.md` and queues consolidation as usual, but skips creating an open handoff row (#1043). OpenCode's per-turn checkpoint, which stands in for its session end, likewise refreshes the summary page without creating or refreshing a baton. Explicit batons created with `memory_handoff_begin` and managed workstream runs remain unaffected. Like `claim_on_session_start`, this setting is server-wide.
## Compaction recovery