Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions examples/openclaw-plugin/context-engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import {
} from "./memory-ranking.js";
import { sanitizeToolUseResultPairing } from "./session-transcript-repair.js";


// Simple in-memory lock to prevent concurrent commits
const commitLocks = new Set<string>();
type AgentMessage = {
role?: string;
content?: unknown;
Expand Down Expand Up @@ -572,6 +575,17 @@ export function createMemoryOpenVikingContextEngine(params: {
}

const OVSessionId = afterTurnParams.sessionId;

// Skip if a commit is already in progress for this session
if (commitLocks.has(OVSessionId)) {
logger.info(`openviking: afterTurn skipped (commit in progress for ${OVSessionId})`);
diag("afterTurn_skip", OVSessionId, {
reason: "commit_lock_contention",
});
return;
}
commitLocks.add(OVSessionId);

try {
const agentId = resolveAgentId(OVSessionId);

Expand Down Expand Up @@ -673,6 +687,8 @@ export function createMemoryOpenVikingContextEngine(params: {
diag("afterTurn_error", OVSessionId, {
error: String(err),
});
} finally {
commitLocks.delete(OVSessionId);
}
},

Expand Down