aboutsummaryrefslogtreecommitdiff
path: root/modules/core/module-debug-supervisor.js
diff options
context:
space:
mode:
authorAgando <roduccomm@gmail.com>2026-10-23 20:30:20 +0200
committerAgando <roduccomm@gmail.com>2026-10-23 20:30:20 +0200
commitdfef70b61b98382a1f78fc6d970fb24ac86c4e36 (patch)
tree80469fc7cb184015b8a4970b4606eea949d8db48 /modules/core/module-debug-supervisor.js
parent8e942d0eacf9e6e46fec1e51d6c18ea40afe3310 (diff)
fix(chat): three concurrency holes found reviewing my own patch (v4.6.77)
1. chat.py renamed the temp file AFTER releasing the flock, so two writers could each read the pre-replace snapshot and the later rename silently dropped the earlier message. os.replace now happens inside the lock. 2. The agent cursor was global. After hermes-reset it pointed past the end of the new empty thread, so every read returned nothing — the agent would think it had been ignored. Key is now per thread and reset clears every chat cursor. 3. chat-relay.sh had no overlap guard: a slow agent run (up to 5 min) could collide with the next tick and answer the same thread twice. flock -n on /tmp/chat-relay.lock. Verified: stale cursor 'webx11_chat_agent_cursor_oldthread00000' set to 9999999999999, hermes-reset -> zero cursor keys remain, read returns {messages:[], note:'no new messages...'}.
Diffstat (limited to 'modules/core/module-debug-supervisor.js')
-rw-r--r--modules/core/module-debug-supervisor.js4
1 files changed, 4 insertions, 0 deletions
diff --git a/modules/core/module-debug-supervisor.js b/modules/core/module-debug-supervisor.js
index 6768df1..79c9acc 100644
--- a/modules/core/module-debug-supervisor.js
+++ b/modules/core/module-debug-supervisor.js
@@ -173,6 +173,10 @@ class DebugSupervisorModule {
try {
localStorage.removeItem('webx11_chat_token');
localStorage.removeItem('webx11_chat_state');
+ // a stale agent cursor would point past the end of the new, empty thread
+ Object.keys(localStorage)
+ .filter(k => k.indexOf('webx11_chat_agent_cursor') === 0)
+ .forEach(k => localStorage.removeItem(k));
this.terminal.print('🔄 Chat token rotated — a new thread starts with your next message', 'success');
} catch (e) {
this.terminal.print('❌ ' + e.message, 'error');