Skip to content

Commit 2a8ff4c

Browse files
Eistee82claude
andauthored
fix: improve script restart behavior (#2194)
Prevents duplicate 'Stopping script' logs by early-returning when script is not running. Restricts restart handling to the owning instance only. Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 98cf9c3 commit 2a8ff4c

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ Executes Javascript, Typescript Scripts.
2727
### **WORK IN PROGRESS**
2828
-->
2929
### WORK IN PROGRESS
30+
* (Eistee82) Fix: prevent duplicate 'Stopping script' log when script is not running
31+
* (Eistee82) Fix: only restart scripts on the instance that owns them
3032
* (Eistee82) Added OID display mode toggle for Blockly editor: 4 display modes (Name, Name path, State ID, Full ID) with toolbar dropdown, context menu, optional object icons, and translations in 11 languages
3133
* Per-provider test buttons in adapter config (OpenAI, Anthropic, Gemini, DeepSeek, Custom API)
3234
* Optional API key field for custom base URL providers (e.g. Ollama without auth)

build/main.js

Lines changed: 6 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -675,9 +675,11 @@ class JavaScript extends Adapter {
675675
// Start script
676676
await this.loadScriptById(id);
677677
}
678-
} else {
679-
// if (obj.common.source !== formerObj.common.source) {
680-
// Source changed => restart the script
678+
} else if (
679+
obj.common.engine === `system.adapter.${this.namespace}` ||
680+
formerObj.common.engine === `system.adapter.${this.namespace}`
681+
) {
682+
// Source changed => restart the script (only on the relevant instance)
681683
this.stopCounters[id] = this.stopCounters[id] ? this.stopCounters[id] + 1 : 1;
682684
void this.stopScript(id).then(() => {
683685
// only start again after stop when "last" object change to prevent problems on
@@ -2601,6 +2603,10 @@ class JavaScript extends Adapter {
26012603
}
26022604

26032605
async stopScript(name: string): Promise<boolean> {
2606+
if (!this.scripts[name]) {
2607+
return false;
2608+
}
2609+
26042610
this.log.info(`${name}: Stopping script`);
26052611

26062612
await this.setState(`scriptEnabled.${name.substring(SCRIPT_CODE_MARKER.length)}`, false, true);

0 commit comments

Comments
 (0)