Skip to content

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

Rust

Merge remote-tracking branch 'origin/main' into integ/main

AkitaOnRails601b4b58a1ff
diff --cc CHANGELOG.md
index a484dd38,18dc1ec9..6c8f84bb
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@@ -8,134 -8,69 +8,193 @@@ and this project adheres to [Semantic V
## [Unreleased]
### Fixed
+- Fixed Gemini CLI's `run_shell_command` and `read_many_files` tools being
+ classified as unknown, so `[capture] ignore_paths` never checked them and a
+ call reading an ignored file still had its output written to the local hook
+ spool and sent to the server, which then discarded it. `run_shell_command` is
+ now a shell tool, read like `Bash` and resolved from its `dir_path`, and
+ `read_many_files` is a file tool: the call is dropped when any of its
+ `include` globs names or could expand into an ignored path, and glob syntax
+ the matcher cannot evaluate makes it metadata-only. Gemini's
+ `list_directory` and the legacy `search_file_content` name are now search
+ tools, dropped under an active policy like `grep_search` and `glob`. A shell
+ command whose `**` glob could recurse into an ignored directory (zsh, or bash
+ with `globstar`) is now dropped too. A `read_many_files` entry naming a
+ directory above an ignored path (`docs`, `.`), which Gemini reads
+ recursively, is dropped as well. GitHub Copilot CLI's `view`, `create` and
+ `str_replace_editor` are now file tools, checked against `ignore_paths` like
+ `Read` and `Write`. Under an active or invalid policy, tools that read back
+ output of an earlier command (Claude Code `BashOutput`/`TaskOutput`, Codex
+ `write_stdin`, Hermes and OpenClaw `process`, Copilot CLI `read_bash` and
+ `write_bash`) and shell commands using brace expansion or a bracket class
+ are now metadata-only, since the matcher cannot prove they miss an ignored
+ path; upgrade the server before the clients, because an older server drops
+ those events. A script quoted inside a string-form shell command (an
+ `sh -c` argument, a command substitution in double quotes) is now read like
+ the rest of the command line, the path in a git object name (`REV:path`) is
+ checked, Antigravity's `run_command` resolves its arguments from its `Cwd`,
+ and ANSI-C strings and backslash-escaped letters are read the way the shell
+ reads them. Inline interpreter code (`python3 -c`, `node -e` and similar)
+ and further glob syntax the matcher does not evaluate (zsh glob groups,
+ extglobs, encoded escapes) are now metadata-only under an active policy.
+ Line continuations, parameter defaults, values glued to short flags,
+ `file:` URLs, `~+`, PowerShell and cmd escape characters, and shell or
+ interpreter options placed before the script or code are now read too, and
+ more script runners and interpreters are recognized. A path under a
+ directory only the running shell knows (`~-`, `~name`) makes the call
+ metadata-only, and on macOS paths match without regard to case, as its
+ default filesystem does, including non-ASCII letters and decomposed accents.
+ A checkout's `ignore_paths` now also hold for a file, search/list or shell
+ tool call made from another checkout or from an unmarked directory that
+ reaches one of its files, including through glob syntax in a directory
+ name, a search's path or file filter, or the files an `apply_patch` names.
+ Glob directories outside the event's own checkout are followed through the
+ directories on disk within fixed bounds of count and time; past them, or for
+ glob syntax that cannot be followed, the call is metadata-only, and so is a
+ file tool whose target cannot be read. A glob inside the event's own
+ checkout is not walked, so ordinary monorepo commands over many packages
+ (`cat packages/*/package.json`, `du -sh packages/*`) keep their output with
+ or without a marker, and neither are a large brace expansion that cannot
+ leave it (`touch test/file{1..200}.txt`) or the checkout's own subtree under
+ a `**` that starts above it. Each directory's marker is looked up once, so
+ many paths in a deep tree stay within the hook's time budget, and a
+ dotfiles `.git` in the home directory no longer counts as every project's
+ own checkout. A `..` after a `**`, a dot glob that older bash
+ expands to the parent directory (POSIX classes and extglobs included), a
+ brace expansion, a zsh glob group, an ANSI-C escape (also inside a
+ double-quoted `bash -c` or `eval` script), an indented `apply_patch` header
+ and Hermes `search_files`' `file_glob` filter can no longer hide which
+ checkout a call reaches. A broken
+ marker makes a search metadata-only, as it does a file or shell call.
+ Reading back a file a harness saved an earlier tool's output to
+ (Claude Code's saved large results and background task output, OpenCode's
+ and Pi's truncated output files), or a glob that could match one, is
+ metadata-only under an active or invalid policy, like `BashOutput`; an
+ ordinary log glob (`tail -n 50 log/*.log`, `cat /tmp/*.log`) is not taken
+ for one. A `file:` URL's query or fragment is no longer
+ read as part of its path, a parameter default nested deeper than the matcher
+ reads is metadata-only, and a backslash escape inside a default is read. A
+ quoted `~` (`git commit -m "fix ~approx"`) is no longer treated as a home
+ or user directory, so such commands are kept again.
+ This applies to the native hook, the server, and the
+ generated TypeScript integrations. (GHSA-gcpc-88hm-3xqr)
+- Fixed `ai-memory backfill`, including the automatic first-boot import, and
+ the `ai-memory run` workstream ledger not applying `[capture] ignore_paths`
+ to the harness transcripts they import, so the arguments and output of a
+ tool call on an ignored file could be stored even though live hooks drop
+ them. Both now apply the same decision as the live hook to every imported
+ tool call and its result: an excluded call is not imported at all, one the
+ policy cannot prove safe keeps only its tool family, and prompts and
+ assistant messages are imported as before, and under allowlist capture
+ mode a checkout without a marker imports nothing. Results recorded without an id
+ linking them to their call take the strictest decision of their turn.
+ A call the transcript names differently from the hook (Codex's shell tool) is
+ judged under the hook's name, each event is judged from the working directory
+ its own record names, and a call or event the live hook would deliver to
+ another checkout is imported only when that checkout would capture it and
+ sends to the same server and project; events recorded in, or calls reaching
+ into, a checkout of another project are left out instead of being filed
+ under the importing project, and so are events from a different
+ subdirectory of the same repository, which the server files under a
+ project of their own. The output of a Claude Code `!` shell command,
+ which live capture never receives, is no longer imported. Claude Code's
+ background-task notifications (a monitored command's output, a finished
+ background command or agent) are no longer imported as prompts, whatever the
+ case or spacing of their opening tag, and its compaction summary is
+ imported as a compaction record instead of a prompt.
+ A tool ai-memory does not recognize, such as an MCP tool, is imported as a
+ record that it ran without its arguments, output or name, which is all live
+ capture stores for it, and so is a result whose call is not in the
+ transcript. (GHSA-gcpc-88hm-3xqr)
+- Fixed a web page open in the operator's browser being able to act on an
+ unauthenticated server (the loopback default, no token), such as claiming a
+ project's pending handoff or starting admin jobs. With auth off, the machine
+ and admin routes now refuse browser requests that come from another site or
+ that are not script calls from a page, such as links and images; hooks, the
+ CLI, MCP clients and the built-in web UI are unaffected, and servers with a
+ bearer token are unchanged. Images in wiki pages rendered by the web UI are
+ also limited to relative paths that stay inside the UI. When an
+ unauthenticated server is reached through a non-loopback host name in its
+ allowlist (a LAN address or name, or `host.docker.internal`), where browsers
+ do not send the request metadata the check relies on, the session-start
+ handoff fetch now also requires an `X-AI-Memory-Client` header that every
+ ai-memory hook, CLI command and generated integration sends; the same holds
+ for a request that arrives through a forwarding proxy or CDN (any of the
+ common forwarding headers, including `CF-Connecting-IP`, `True-Client-IP`
+ and `X-Forwarded-Proto`), even one that rewrites
+ the host to the loopback address. Hooks on such a
+ server must be re-staged with `ai-memory install-hooks` (or
+ `ai-memory upgrade`); loopback installs need nothing.
+ (GHSA-6mc4-46pr-w82w)
+- Fixed `POST /auth/login` and `POST /auth/recovery` accepting request bodies
+ that are not declared as JSON, which a page on another site could use to
+ sign the operator's browser in or to try passwords when human sign-in is
+ enabled. Both routes now answer 415 unless the body is `application/json`;
+ the built-in login page and the documented `curl` recovery already send
+ that. (GHSA-6mc4-46pr-w82w)
- - Fixed approving or rejecting an unknown pending write
- (`POST /admin/pending-writes/{id}/approve` or `/reject`) answering 500 instead
- of 404. An id outside the given workspace and project now answers 404 too.
- (#1205)
+ - Fixed the cross-project profile harvester treating pages the auto-improve
+ scheduler auto-approved as curated human input: model output nobody
+ reviewed fed the profile like a hand-written rule. A page stamped from an
+ auto-improve proposal is now skipped when the proposal's decider is the
+ scheduler's auto-approve actor; a page a human approved still counts, and a
+ page whose proposal id resolves to no row (legacy or imported) stays
+ curated. (#1211)
+ - Fixed the zero-LLM session page staying silent about abrupt endings. The
+ rule-based synthesis now adds a deterministic terminal-state line reusing
+ the automatic handoff's heuristics: "Session ended without a normal stop;
+ the final prompt was never answered." when the log ends on an unanswered
+ question, the equivalent line when file activity was never followed by a
+ stop, and a mid-task-exit line when a stop was recorded but no session
+ end arrived. A session with a normal stop and end gets no line. (#1221)
+ - Fixed consolidation dropping the tail of a session from the compiled
+ page. The single and batch prompts now carry explicit rules: say so when
+ the observation log ends on an unanswered prompt or without a normal
+ stop, and record in-flight work (background jobs, watchers, timers) as
+ pending state; when a later observation corrects an earlier "done"
+ milestone, state only the final state with the superseded claim as
+ history at most; preserve the last reported metrics of in-flight work
+ (sizes, rates, counts, ETAs) verbatim; carry operator "run X when Y"
+ instructions verbatim, with their preconditions, into a
+ Next steps / Pending section; and, for sessions that operated on
+ external systems, emit an "Access and verification" section — hosts,
+ the per-host auth mechanism (never secrets or tokens themselves),
+ job-state marker locations, staged-script paths — grounded only in what
+ the observations show. (#1221)
+ - Softened the consolidation prompts' wikilink quota that pushed models to
+ invent links. The single, batch and bootstrap prompts told the model "2-5
+ well-chosen links per page beat exhaustive linking; zero links should be
+ rare", which
+ pressured it to add links just to hit the number. They now state that zero
+ links is fine when nothing in the input genuinely relates, require a genuine
+ reason visible in the input for every link, and forbid padding a page with
+ links to hit a number; the #1207 restriction on cross-scope links whose
+ target is not visible in the input is unchanged. The validated
+ `consolidation.max_input_tokens` floor moved from 6,000 to 6,500 tokens so
+ the larger prompts still leave room for observation evidence at the minimum.
+ (#1219)
+ - Fixed consolidation still writing invented `[[_global:…]]` / `[[project:…]]`
+ wikilinks when a model ignored the #1207 prompt wording. The single-page,
+ batch and bootstrap apply paths now resolve every cross-scope wikilink
+ target against the store with no-create lookups before the write and
+ rewrite an unresolvable one to its plain label text (an unresolvable
+ `relations:` frontmatter entry is dropped), so a missing target
+ can no longer mint the dangling cross-project edge that `ai-memory lint`
+ reports as `broken_link`. Resolved cross-scope links survive
+ byte-identical, and same-project pending links stay untouched by design.
+ A link into a restricted project is always de-linked, so the result never
+ reveals which pages exist there. (#1218)
+ - Fixed consolidation inventing `[[_global:…]]` and `[[project:…]]` wikilinks to
+ pages that never existed, which `ai-memory lint` then reported as
+ `broken_link`. The single, batch and bootstrap prompts told the model that a
+ missing link target was acceptable and gave it no list of cross-scope pages,
+ so it invented targets to meet the 2-5 link guidance. They now allow a
+ `project:` or `_global:` link only when the exact wiki page path appears in
+ the input, which reduces but does not eliminate such links; a missing
+ same-project target stays a pending link. (#1207)
+ - Fixed the web UI answering HTTP 500 when a signed-in viewer opened a project
+ or page by a name that two projects answer to. The page and project routes
+ now return a 400 that names the clash, matching the API and MCP surfaces.
+ (#1204)
- Fixed the Jev choice reranker adapter silently fabricating scores from a
malformed judge response: `docs/examples/jev-reranker-adapter/jev_rerank_shim_choice.py`
defaulted missing or misnamed `probabilities` entries to `0.0`, so an HTTP
@@@ -158,10 -93,58 +217,60 @@@
`[capture] ignore_paths` would drop the event, so an exclusion that names a
path outside its checkout, or a source file read by a command whose
`workdir` points at another project, is no longer judged only by the
- destination's policy. (#1199)
+ destination's policy. When the payload `cwd`'s own capture policy is
+ invalid, an event aimed at another repository is no longer rerouted; it
+ stays with that source repository as metadata only. (#1199)
+ - `scope_refusal` (the hooks-side mirror of the web surfaces
+ `refusal_response` mapped in #1204) now answers `404 Not Found`
+ for typed not-found `ScopeResolutionError` variants and `400
+ Bad Request` for typed bad-request variants. Previously every
+ refusal that was not `Forbidden` fell through to `500 Internal
+ Server Error`, hiding a missing-id mistake from the caller and
+ making it indistinguishable from a real fault. The four-branch
+ shape (forbidden / not_found / bad_request / fallback) matches
+ the web mapping from #1204; the typed `is_*` predicates the
+ store already exposes carry the classification, so the fix is
+ purely a branch reshuffle with no new predicate. Four unit
+ tests in `workstream.rs::tests` cover the unknown-id (404),
+ unknown-workspace (404), ambiguous-name (400), and forbidden
+ (403, regression guard) cases. (#1209)
+ - `POST /admin/pending-writes/{id}/approve` and `/reject` answered
+ `500 Internal Server Error` for an id that did not exist or belonged
+ to a different workspace, because the routes skipped the lookup and
+ let the wiki method surface a generic error. They now share the same
+ `pending_detail` helper the `/detail` and `/diff` routes already used,
+ so all four routes agree on `400` for an unparsable id, `404` for an
+ unknown or foreign-scope id, and `500` only for unexpected internal
+ errors. New tests in `admin::tests` cover the unknown, foreign-scope,
+ and unparsable cases for both `approve` and `reject`. (#1205)
+ - Fixed Kimi Code sessions resumed after `SessionEnd` never receiving an
+ open handoff. Kimi Code reuses its native session id when a session is
+ resumed, so the receiver row already had `ended_at` set when the resumed
+ session asked for its handoff, and `accept_handoff` refused the claim with
+ "an ended session cannot accept a handoff" — an error the `/handoff` route
+ swallows as an empty 200, leaving the handoff open forever.
+ `AgentKind::reuses_session_id_after_end()` now covers Kimi Code alongside
+ Grok, so accepting reopens the ended receiver row. Every surrounding guard
+ is unchanged: an ended session of any other agent is still final, a
+ receiver in another project is still refused, and the claim-once guard
+ still stops the resumed session from taking a second baton. Covered by an
+ adversarial integration test in `multi_session.rs` and a unit test on the
+ predicate itself.
+ - Fixed agents filing cross-project reports as wiki pages. Asked to "send a
+ report to the ai-memory inbox", an agent wrote pages into the target
+ project with `memory_write_page` instead of calling
+ `memory_message_send`, and the report never existed as a message. The
+ always-visible surfaces now carry the channel contrast in both
+ directions: `memory_message_send`'s tool description and its
+ MEMORY_INSTRUCTIONS bullet name the trigger phrasing ("send a report",
+ "notify", "leave a message for") and state it is the only tool that lands
+ in a project's inbox; `memory_write_page`'s description and bullet say a
+ page is not a message and redirect messaging to `memory_message_send`.
+ The routing snippet (full and compact) gained the same contrast, the
+ `memory_message_pop` bullet now forbids guessing the inbox's project
+ name, and `docs/agent-messaging.md` states the distinction.
+
## [2.6.3] - 2026-10-09
### Fixed
diff --cc docs/security-boundaries.md
index 16055fbe,b84b502a..f27d0058
--- a/docs/security-boundaries.md
+++ b/docs/security-boundaries.md
@@@ -33,9 -33,8 +33,9 @@@ means the boundary is not built yet
| 2 | Workspace isolation | same as #1; same-named project → distinct ids per workspace | `scope.rs` cross-workspace resolution rows; `multi_scope` dedup/validate | STRONG |
| 2b | Managed-workstream discovery stays checkout-local, including pagination | `ai-memory-workstream/src/repository.rs` `inspect_repository_fingerprints` shares the launch identity derivation without checkpoint scans; `ai-memory-cli/src/commands/resume.rs` `candidates_for_checkout` queries only the cwd, never registry links; the explicit `--all` walk (`candidates_across_checkouts`) lists each linked checkout through its own fingerprint-scoped request and applies `--workspace` before any request; `ai-memory-hooks/src/workstream.rs` `list_recent_workstreams` resolves an authorized explicit scope on every page; `ai-memory-store/src/workstream.rs` `list_recent` applies workspace/project/repository/worktree predicates before `LIMIT`/`OFFSET` | `resume.rs` `resume_lists_all_current_checkout_rows_not_registered_foreign_checkouts` (same scope/remote foreign checkout refused, 125 local rows visible), `empty_current_checkout_does_not_fall_back_to_the_registry`, `resume_all_walks_every_linked_checkout_and_honours_the_workspace_filter` (a foreign workspace filter sends no request; the default picker still ignores the registry); `workstream.rs` `recent_workstream_pages_reach_older_rows_without_crossing_checkout_or_scope` (foreign repo, worktree, project and workspace excluded on every page; 105 legitimate rows reach the client, huge offsets return nothing); store `recent_workstreams_are_checkout_local_and_include_linked_harnesses` (page two keeps native harness links); `repository.rs` `reports_origin_push_url_and_linked_worktree` verifies lightweight/full fingerprint parity and distinct worktree keys; CLI `resume_yolo_displays_picker_without_scanning_git_status` verifies listing skips status scans | STRONG |
| 3 | Multi-user auth ladder | `ai-memory-core/src/actor.rs` `AuthLevel::authorize`; `ai-memory-mcp/src/auth.rs` middleware; `admin.rs` `require_root_for_multiuser_admin` / `require_root`; `identity.rs` authorizes `NormalRead` behind the same machine bearer middleware as MCP; `serve.rs` mounts API-only and web+API protected routers behind `require_dual_auth` | `admin.rs` `multiuser_admin_routes_reject_db_user_tier` / `…reject_anonymous` / `create_user_as_user_tier_returns_403`; `auth.rs` unknown-bearer 401; `actor.rs` `skip_admission_chain_rejects_db_users`; `identity.rs` `identity_real_auth_isolates_users_root_and_revoked_keys`, `identity_anonymous_ignores_forged_headers_and_proxy_qualifies_oidc` (distinct users and root, invalid/revoked keys, forged headers, anonymous control); `serve.rs` `api_only_mode_keeps_data_authenticated_and_web_absent` (anonymous API read refused, authenticated control admitted, browser route absent; #986) | STRONG |
- | 3b | Browser triage of pending writes (#855) | `ai-memory-web/src/routes/pending.rs` `require_admin` (`AuthLevel::authorize(Capability::Admin, distinguishes_operators)`, trusted-proxy flag from `WebMountSpec`) gates `GET {web_slug}/pending`; `html_auth.rs` `AdminRequired` keeps a non-root 403 off the change-password redirect; decisions post to the existing `/admin/pending-writes/{id}/approve\|reject` behind `require_dual_auth` (session + CSRF) and `require_root_for_multiuser_admin`. `ai-memory-web` has no write route | `ai-memory-web` `tests/suite/pending.rs` — anonymous refused (401, login redirect), DB user refused (403, no proposal text, no redirect), trusted-proxy flag reaches the gate, single-operator control admits, POSTs to `/pending*` refused, project filter keys do not collide on `/` in names, projects past the 500-row read cap stay counted and reachable; `ai-memory-mcp` `tests/suite/admin_pending_writes_session.rs` — anonymous and DB-user sessions refused, root session without a matching CSRF header refused (each leaves the proposal pending and no file), root approval keeps `auto_improve_proposal_id`/`auto_improve_run_id` and records the approver, root reject writes no file (each proven to fail with its guard removed) | STRONG |
+ | 3b | Browser triage of pending writes (#855) | `ai-memory-web/src/routes/pending.rs` `require_admin` (`AuthLevel::authorize(Capability::Admin, distinguishes_operators)`, trusted-proxy flag from `WebMountSpec`) gates `GET {web_slug}/pending`; `html_auth.rs` `AdminRequired` keeps a non-root 403 off the change-password redirect; decisions post to the existing `/admin/pending-writes/{id}/approve\|reject` behind `require_dual_auth` (session + CSRF) and `require_root_for_multiuser_admin`. `ai-memory-web` has no write route | `ai-memory-web` `tests/suite/pending.rs` — anonymous refused (401, login redirect), DB user refused (403, no proposal text, no redirect), trusted-proxy flag reaches the gate, single-operator control admits, POSTs to `/pending*` refused, project filter keys do not collide on `/` in names, projects past the 500-row read cap stay counted and reachable; `ai-memory-mcp` `tests/suite/admin_pending_writes_session.rs` — anonymous and DB-user sessions refused, root session without a matching CSRF header refused (each leaves the proposal pending and no file), root approval keeps `auto_improve_proposal_id`/`auto_improve_run_id` and records the approver, root reject writes no file (each proven to fail with its guard removed); `ai-memory-mcp` `admin.rs` `pending_write_approve_foreign_scope_returns_404` and `pending_write_reject_foreign_scope_returns_404` — an id staged in workspace `alpha` requested through an existing `default` scope is 404 (never approved or rejected across the boundary), with the in-scope reject as the legitimate control (each proven to fail with 500 with the `pending_detail` guard removed, #1205) | STRONG |
+| 3c | Public human-auth routes refuse bodies a foreign page can send without a preflight (login CSRF, password guessing, root recovery) | `ai-memory-mcp/src/human_auth.rs` `handle_login` / `handle_recovery` read their bodies by hand (to rate-limit first), so each checks `declares_json_body` before reading: a `Content-Type` other than `application/json` or `application/*+json` (parameters and case ignored), or none, → 415 before any password or recovery-token check and without charging the per-IP failure budget. `text/plain`, form-urlencoded and multipart are the only bodies a cross-site page can `POST` without a preflight, and `/auth/*` carries no CORS layer. The built-in login page, the `docs/frontend-api.md` examples and the recovery `curl` in `docs/install.md` send `application/json` | `human_auth.rs` `public_auth_routes_refuse_preflight_free_browser_bodies`: valid root credentials and a valid recovery token, sent from a foreign origin as `text/plain`, form-urlencoded, multipart and with no content type, more times than the per-IP failure budget → 415, no session cookie; controls: a same-origin JSON login then succeeds (password unchanged, budget untouched) and a JSON recovery returns 204. `json_body_declaration` (header table) | STRONG. Bite check: with the check removed, the `text/plain` login returns 200 with the session cookie (the pre-fix behaviour) and the test fails. `/auth/password` and `/auth/logout` were already closed: they run behind `require_session`, whose unsafe methods need the `x-csrf-token` header (a custom header, so preflighted), and `/auth/password` also uses axum `Json` |
- | 4 | Handoff single-claim / no-steal | `ai-memory-store/src/ops.rs` `accept_handoff_in_transaction` (metadata `state='open'` guard + atomic CAS) | `multi_session.rs` `a_second_accept_cannot_steal_an_accepted_handoff`; `handoff_ownership.rs` `another_operator_cannot_claim_the_handoff` | STRONG |
+ | 4 | Handoff single-claim / no-steal | `ai-memory-store/src/ops.rs` `accept_handoff_in_transaction` (metadata `state='open'` guard + atomic CAS; the receiver-session check, which requires the receiving session to exist in the claim's own workspace, project and agent kind and refuses with `InvalidState` before the handoff row is touched; an ended receiver is final EXCEPT for the agents where `AgentKind::reuses_session_id_after_end()` holds — Grok and Kimi Code, whose harnesses reuse the native session id across SessionEnd→resume, so accepting reopens `ended_at` only after the claim-once guard) | `multi_session.rs` `a_second_accept_cannot_steal_an_accepted_handoff`; `handoff_ownership.rs` `another_operator_cannot_claim_the_handoff`; `multi_session.rs` `handoff_accept_rejects_foreign_or_missing_receiver_session` (receivers from a sibling project, another workspace, a different agent kind, and a nonexistent session are each refused as `InvalidState` with the handoff left open and every `accepted_*` column NULL; the matching receiver claims it; the same receiver retrying and a second matching session get `false` with the first claim intact; fails with the `project_id` or `agent_kind` predicate, or the missing-session refusal, removed. The `workspace_id` predicate is redundant defence in depth: project ids are globally unique, so the cross-workspace receiver is already caught by `project_id`); `multi_session.rs` `accept_reopens_an_ended_receiver_session_but_keeps_claim_once` (Grok reopen + no-steal) and `accept_reopens_an_ended_kimi_receiver_but_keeps_every_guard` (Kimi Code resume claims and reopens `ended_at`; adversarial controls: an ended claude-code receiver stays refused, a kimi-code receiver in another project stays refused, and the already-claimed guard still refuses the resumed kimi session a second baton) | STRONG |
| 4b | Handoff owner-scoped recovery (`any_owner` admin gate) | `ai-memory-mcp/src/server.rs` `require_admin_capability` on `memory_handoff_accept`/`_cancel` `any_owner` | `handoff_admission.rs` — cancel gate + **accept gate** (adversarial: non-admin `any_owner` accept refused) | STRONG |
| 4c | Turn-checkpoint baton is owner+scope-bound | `ai-memory-store/src/ops.rs` `checkpoint_session_handoff` — reads the session's own `(workspace, project, owner_user)` from `sessions WHERE id=?1 AND ended_at IS NULL`, refuses on scope/owner mismatch, refreshes only that session's own `state='open'` baton (id preserved), returns `None` when the session already ended | `ops.rs` `checkpoint_session_handoff_refreshes_only_the_live_sessions_own_baton` (#865) | STRONG |
| 4d | Native session rebind / drifted-end is owner+agent+cwd CAS | `ai-memory-store/src/ops.rs` — `session.moved` rebind gated on `agent==OpenCode` + `ended_at IS NULL` + lexical `normalize_cwd(stored)==normalize_cwd(from)`; `expire_same_cwd_auto_handoffs` AND-gated on `owner_user IS ?4 AND id IS NOT ?5` and on the source not being another still-open session (row 4e, #883); drifted `SessionEnd` ends only same owner+agent+cwd | `ops.rs` `native_move_rebinds_live_session_only_from_its_current_cwd`, `native_move_rejects_foreign_owner_and_ignores_completed_replay`, `drifted_session_end_ends_only_the_same_actor_agent_and_cwd` (#865) | STRONG |