Repository navigation
Conversation
Add a response field that lets clients distinguish stored session policies from an actively running idle scheduler, while keeping server defaults off. Co-authored-by: TRAE CLI <noreply@bytedance.com>
Apply idle auto-commit policies across harness integrations, gate Codex local recovery on server capability, and make close paths commit within host budgets. Co-authored-by: TRAE CLI <noreply@bytedance.com>
Document server capability detection, per-harness idle policy knobs, fixed close behavior, and the remaining lifecycle gaps across integrations. Co-authored-by: TRAE CLI <noreply@bytedance.com>
Startup recovery in the OpenCode plugin ran unguarded, so a single state entry whose OV session no longer exists rejected init() and took the plugin down on every launch. Its flushSession also grew an uncaptured-message branch that preempted both the queue fallback and the direct commit, silently dropping the final commit on a non-retryable send or an exhausted dispose deadline. The pi extension stopped queueing a failed non-takeover shutdown commit; that rule only applies to takeover mode, where a delayed commit must not advance the local context boundary, so non-takeover lost its only recovery path. OpenClaw sent the raw hook agent id as the actor peer while its messages are recorded under a prefixed and sanitized peer, scoping the shutdown commit to a peer the session never used; ids containing ':' were rejected outright. DSH re-ran full initialization from dispose when a session was never ready, which cannot fit the host process grace, and returned without committing or queueing when it still failed. Codex created an "unknown" state file and a bogus cx-unknown session when the hook payload carried no session id, and a covered marker without a usable timeout was neither committed nor garbage-collected. The shared helper cached a server as legacy on any ok-but-no-echo create, and plugin fetch helpers turn an unparseable 200 into an empty result, so one garbled response disabled the backstop for the whole TTL. Session-start policy application in the thin hook harnesses also had no request timeout and logged nothing when it did not apply. Co-authored-by: TRAE CLI <noreply@bytedance.com>
The OpenClaw and Codex pages presented the session_auto_commit snippet without saying where it goes, and on the OpenClaw page it followed plugin-config commands, inviting users to set a server-only option in the plugin config where it is silently ignored. Both now name the server's ov.conf, in English and Chinese. The Cursor hook list still credited sessionEnd with committing pending messages, contradicting the paragraph below it that explains the hook command cannot execute. Also drop the mirrorMemoryWrites key from the pi design doc: it matches no config field and its only flow step was already removed. Co-authored-by: TRAE CLI <noreply@bytedance.com>
This was referenced Sep 30, 2026
14 of 21 tasks
This branch has not been deployed
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.
Description
Harness memory plugins commit an OV session at end-of-conversation, but several
harnesses never fire a usable hook when the user simply closes them. Codex fires
nothing at all on
SIGTERM/Ctrl+C//exit(upstream declined aSessionEndhook), so its plugin emulates one with local state files, a 2-minute
active-window heuristic and a 30-minute idle-TTL sweep — and its own design doc
accepts that if the user never relaunches Codex, the session stays open forever.
The server already has the right mechanism (
auto_commit_policy.idle_timeout_secondsplus
SessionAutoCommitScheduler, #3736/#3850), but nothing used it: the.mjsplugins never create sessions at all (they rely on
auto_createinsidePOST /messages, which takes no options), and the sweeper is gated bymemory.session_auto_commit.idle_enabled, which is not reachable over HTTP.This PR makes every harness plugin request a per-session idle policy, lets
plugins detect whether the server will actually act on it, retires Codex's local
sweep on servers that do, and fixes each harness's real close path.
Upstream close behavior was verified against source/docs per harness before
writing any of it; the findings changed the plan (Cursor and pi turned out to be
in the "does not commit on close" group, DSH turned out to be better than
assumed), and the docs now describe what remains uncovered rather than a guess.
Human Involvement
Type of Change
Changes Made
Server — capability detection only, defaults unchanged
POST /api/v1/sessions,GET /api/v1/sessions/{id}andPATCH /api/v1/sessions/{id}/confignow returnauto_commit_idle_enabled.It gives clients a tri-state: field absent means an old server,
falsemeansa server that stored the policy but will not sweep,
truemeans it will.The policy echo alone cannot express that difference, which is why the field
exists.
memory.session_auto_commitdefaults are deliberately untouched(
default_enabled=false,idle_enabled=false); a unit test pins both so afuture accidental flip fails CI.
examples/ov.conf.exampledocuments theblock at its shipped values.
Plugins — one shared, idempotent policy path
examples/memory-plugin-shared/lib/session-policy.mjs: normalize/buildthe policy, then
POST /sessionswith it and fall back toPATCH /{id}/configonALREADY_EXISTS. Old servers ignore the unknowncreate field, so they are detected by the missing echo and negative-cached for
6h; transient failures never write that cache.
{idle_timeout_seconds, pending_token_threshold: 0, message_count_threshold: 0}. The two zeros matter: they disable theserver-side threshold triggers so they cannot race the plugins' own
client-side threshold commits, which use different keep-recent semantics.
openclaw, once per session start, best-effort, never blocking the hook.
Knob:
OPENVIKING_COMMIT_IDLE_TIMEOUT_SECONDS/commitIdleTimeoutSeconds,default 3600,
0/offto disable.Codex — the local sweep now retires itself
serverIdleCommitonly when the server reportedauto_commit_idle_enabled: true. Both the active-window heuristic and theidle-TTL sweep skip marked sessions, and a marked file is garbage-collected
(never committed) once it is past the server's own timeout plus a margin.
idle_enabled=false,a failed apply or the knob turned off all leave the marker absent, so on stock
servers the sweep stays fully active. Zero regression by construction.
as
X-OpenViking-Actor-Peerinstead of the swept session's storedworkspacePeerId, misattributing extracted memories.Close-path fixes, per harness
session_end(reason=shutdown|restart)per active session during shutdown drain, plus an awaited
gateway_stop; theplugin received the first and discarded it and never registered the second.
Both now commit, bounded to fit the 2s drain and 5s per-hook budgets.
session_shutdownfires on every close mode and is fully awaited,but in the default takeover config the handler only persisted local state.
It now commits, ordered commit-before-watermark and refusing to advance on
failure so a delayed commit can never move the local context boundary.
sessionEndfires only onwindow_close, where theshell-exec host is already torn down, so the hook command never spawns
(Cursor-staff-confirmed, no ETA). Commit-turn threshold now defaults to 1,
adopting the zcode/trae per-turn model that already ships.
addMessage(10s) or threshold commit (30s), a SIGHUP listener coversterminal close, and dispose no longer re-runs full initialization on the
teardown path.
pending-queue fallback can still enqueue, and startup flushes and commits
rehydrated entries that a dead process left behind.
Docs (EN + ZH)
to enable the server backstop, explicitly in the server's
ov.conf— theearlier draft showed the snippet with no file named, right after plugin-config
commands, where setting it does nothing.
DESIGN.md/VERIFICATION.mdcover the new marker, the gating decisiontree and the manual runbook.
Testing
I have added tests that prove my fix is effective or that my feature works
New and existing unit tests pass locally with my changes
I have tested this on the following platforms:
pytest tests/server/test_api_sessions.py tests/server/test_api_sessions_event_tags.py tests/unit/service/test_session_auto_commit.py tests/unit/session/test_auto_commit_policy.py→ 90 passed.
node --testacross memory-plugin-shared, codex, claude-code, cursor, zcode,trae, opencode, pi and dsh → 183 passed.
examples/openclaw-plugin:npm run typecheckclean,npm run test→ 751passed. The 4 failures in
tests/ut/architecture-boundaries.test.tsarepre-existing and fail identically on
main(verified in a clean worktree);they are unrelated to this branch.
The gating logic carries an explicit mutation guard: a test asserts that stale
state the server does not cover is still swept locally, for both an unmarked
file and a marked file missing its timeout. Without it, relaxing the predicate
from
=== trueto!== falseleft the whole suite green while silentlydisabling commits on every stock server.
Checklist
Additional Notes
Rollout is order-independent. Plugins against an old server negative-cache and
keep today's behavior; the server field against old plugins is inert because no
policy is sent. Codex's sweep only retires where an operator has enabled
idle_enabled— intentionally, since that is the only state in which the serveractually sweeps.
Draft while a review pass finishes. Known follow-ups, deliberately not in scope:
openviking-session-state.jsonin the OpenCode plugin is one global filerewritten wholesale from a single process's in-memory map, so concurrent
OpenCode servers clobber each other's entries. Needs a layout change.
os.tmpdir()and itswritePathAsyncdefault detaches the SessionEnd write./healthfails at that instant — the sameoutage that stranded the session disables its recovery.
examples/ov.conf.examplecannot be loaded by the server's strictjson.loadsbecause of pre-existing trailing commas; now that docs pointusers at it to find this knob, that is worth fixing separately.