fix: save agent prompt and reload changes reliably

Agent settings now correctly save an emptied system prompt instead of silently keeping the old text.

After saving agent, command, or skill settings, OpenChamber refreshes the updated configuration instead of showing stale values from a short-lived cache.

Reload actions now surface refresh failures consistently while avoiding noisy background errors.
This commit is contained in:
Bohdan Triapitsyn
2026-06-08 13:43:45 +03:00
parent b2b71198ca
commit ef71a997a8
10 changed files with 103 additions and 14 deletions
+10 -1
View File
@@ -168,6 +168,10 @@ const getSkillsCacheKey = (directory: string | null): string => {
return directory?.trim() || DEFAULT_SKILLS_CACHE_KEY;
};
export const invalidateSkillsLoadCache = (directory: string | null = getCurrentDirectory()) => {
skillsLastLoadedAt.delete(getSkillsCacheKey(directory));
};
const MAX_HEALTH_WAIT_MS = 20000;
const FAST_HEALTH_POLL_INTERVAL_MS = 300;
const FAST_HEALTH_POLL_ATTEMPTS = 4;
@@ -302,6 +306,7 @@ export const useSkillsStore = create<SkillsStore>()(
}
const needsReload = payload?.requiresReload ?? false;
invalidateSkillsLoadCache(currentDirectory);
if (needsReload) {
requiresReload = true;
await refreshSkillsAfterOpenCodeRestart({
@@ -352,6 +357,7 @@ export const useSkillsStore = create<SkillsStore>()(
}
const needsReload = payload?.requiresReload ?? false;
invalidateSkillsLoadCache(currentDirectory);
if (needsReload) {
requiresReload = true;
await refreshSkillsAfterOpenCodeRestart({
@@ -393,6 +399,7 @@ export const useSkillsStore = create<SkillsStore>()(
}
const needsReload = payload?.requiresReload ?? false;
invalidateSkillsLoadCache(currentDirectory);
if (needsReload) {
requiresReload = true;
await refreshSkillsAfterOpenCodeRestart({
@@ -554,13 +561,15 @@ export async function refreshSkillsAfterOpenCodeRestart(options?: { message?: st
await waitForOpenCodeConnection(options?.delayMs);
updateConfigUpdateMessage("Refreshing skills…");
const skillsStore = useSkillsStore.getState();
invalidateSkillsLoadCache();
const loaded = await skillsStore.loadSkills();
if (loaded) {
emitConfigChange("skills", { source: CONFIG_EVENT_SOURCE });
}
} catch {
} catch (error) {
updateConfigUpdateMessage("OpenCode refresh failed. Please retry.");
await sleep(1500);
throw error;
} finally {
finishConfigUpdate();
}