Reload stale OpenCode frames after server recovery

This commit is contained in:
Nick Sweeting 2026-09-02 22:37:53 -07:00
parent 2d23264bd6
commit 4149b6f578
No known key found for this signature in database
2 changed files with 38 additions and 0 deletions

View File

@ -206,6 +206,42 @@
});
})();
</script>
<script>
(() => {
const frame = document.querySelector(".opencode-agent-frame");
if (!frame) return;
let checking = false;
let wasUnavailable = false;
const check = async () => {
if (checking) return;
checking = true;
try {
const response = await fetch("/admin/agent/opencode/global/health", {
cache: "no-store",
credentials: "same-origin",
});
if (!response.ok) {
wasUnavailable = true;
} else if (wasUnavailable) {
wasUnavailable = false;
frame.contentWindow.location.reload();
}
} catch {
wasUnavailable = true;
} finally {
checking = false;
}
};
window.setInterval(check, 3000);
window.addEventListener("online", check);
document.addEventListener("visibilitychange", () => {
if (!document.hidden) check();
});
check();
})();
</script>
{% endif %}
</div>
{% endblock %}

View File

@ -186,6 +186,8 @@ def test_opencode_agent_superuser_gets_admin_wrapper(admin_client, live_opencode
assert f'<iframe src="{session_path}"'.encode() in response.content
assert b'id="header"' in response.content
assert b'id="progress-monitor"' in response.content
assert b'fetch("/admin/agent/opencode/global/health"' in response.content
assert b"frame.contentWindow.location.reload()" in response.content
assert response.headers["X-Frame-Options"] == "DENY"
assert response.headers["Content-Security-Policy"] == "frame-ancestors 'none'"