carlos / platform Public

examples/rails-shop: the page's cable socket reconnects with capped backoff (#471 branch review R1 P2)

The page opened one WebSocket and never reconnected, so after a hub restart
or tunnel loss the counts stopped until a reload (spec :795 says every row
recovers without one). A close or an error now reconnects after 1 s,
doubling to at most 30 s, and the delay resets on welcome; each welcome
subscribes again. The fetch-submit is unchanged. No visible words.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by claude agent, operated by paul@keymail.dev db1b1797a4adbd777482893bb0b56781adbbe799 parent 447a570
1 file changed, +35 −12
  • examples/rails-shop/app/views/pages/show.html.erb +35 −12

CI failed — run details

Intent

Human

<task-notification> <task-id>a3be5845734ab5e17</task-id> <tool-use-id>toolu_014X4H3MsmTj3CF2y7KTAShT</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/ba9fa944-a429-4788-9b3c-f2b2f42617f3/tasks/a3be5845734ab5e17.output</output-file> <status>completed</status> <summary>Agent "Plan 6 Task 7a: carlos run on rootfs" finished</summary> <note>A task-notification fires each time this agent stops with no live background children of its own. The user can send it another message and resume it, so the same task-id may notify more than once.</note> <result>**Status:** DONE_WITH_CONCERNS. All three P2s from the re-review are fixed in one commit. **Commit:** `ba3d96cc` on `e026fdc1`, in the rootfs-apps-6 worktree. Not pushed. The fix report is appended to `task-7a-report.md`. **Tests:** the `-race` run of the cmd, lease and rootfs-run tests passed twice with no races. The Step 2/4 activator tests, every invariant guard, the wider rootfs/lease/swap tests and both censuses pass. The darwin, windows and linux/arm64 builds are clean. All 4 new mutations are caught. - **P2 1 and 2 (the Stop/AfterSettled contract):** back to the asynchronous contract, as ruled. Stop returns once termination is proven and does not wait for `AfterSettled`, which runs once afterwards. The contract is now in `CmdSpec.AfterSettled`'s doc comment: called once, after the proof, never while a lock is held, and it must not call Stop or Shutdown. The original test race is fixed by waiting for the callback explicitly. A new test shows a blocking callback holds up neither the first Stop nor a second one. - **P2 3 (the bound on the pending entry):** the report and code comment now say what actually bounds it. `ExecBackend.KillOneShot` bounds itself whatever its caller's context says: 30 seconds for root's kill, then 20 seconds for the cgroup proof. No timer clears the count. A new test shrinks both budgets to 200 ms and hangs first the control service, then the cgroup. Each kill returns within its budget, and the entry's count drops back to zero. - **Census:** the overlay is re-proposed with seal `a56c8ee8…`. Two claims change with their code (`KillOneShot` and `type CmdSpec`), and the other 34 carry over verbatim. No approval requested. **Concerns:** 1. The 30-second control budget is now a package variable so the test can shrink it. Production's value is unchanged. 2. Three of the four mutations are caught by the test hanging until its timeout, not by an assertion. That is the behaviour they introduce: a wait with no bound. 3. Still standing from round 1: the arm64-only tests haven't run on this box, the lease tests use real-time windows, and some test files outside this task fail `go vet` on darwin and windows.</result> <usage><subagent_tokens>624423</subagent_tokens><tool_uses>16</tool_uses><duration_ms>638110</duration_ms></usage> </task-notification>

Attributed to this commit: 7.61 g CO₂e (964,453 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on design-tunnel-websockets-471, never backward from it. A turn that produced more than one commit books all of its tokens to the last one, and a concurrent session on this branch can add to the same figure. Some of it was priced using the shared default rate, because no model-specific factor row exists yet for at least one model involved. The Carbon view has the repo total, which is never derived from this attribution.

diff --git a/examples/rails-shop/app/views/pages/show.html.erb b/examples/rails-shop/app/views/pages/show.html.erb
index 005acb12f..1ef9bfd6c 100644
--- a/examples/rails-shop/app/views/pages/show.html.erb
+++ b/examples/rails-shop/app/views/pages/show.html.erb
@@ -20,19 +20,42 @@
<script>
(function () {
- var socket = new WebSocket((location.protocol == "https:" ? "wss://" : "ws://") + location.host + "/cable", "actioncable-v1-json");
- socket.onmessage = function (event) {
- var data = JSON.parse(event.data);
- if (data.type == "welcome") {
- socket.send(JSON.stringify({ command: "subscribe", identifier: JSON.stringify({ channel: "PingsChannel" }) }));
- return;
- }
- var message = data.message;
- if (message && typeof message == "object" && "done" in message && "total" in message) {
- document.getElementById("done").textContent = message.done;
- document.getElementById("total").textContent = message.total;
+ // Reconnect after a close or an error: wait 1 s, doubling to at most
+ // 30 s, and start again at 1 s once the server says welcome.
+ var delay = 1000;
+
+ function connect() {
+ var socket = new WebSocket((location.protocol == "https:" ? "wss://" : "ws://") + location.host + "/cable", "actioncable-v1-json");
+ var retrying = false;
+
+ function retry() {
+ if (retrying) return;
+ retrying = true;
+ setTimeout(connect, delay);
+ delay = Math.min(delay * 2, 30000);
}
- };
+
+ socket.onclose = retry;
+ socket.onerror = function () {
+ retry();
+ socket.close();
+ };
+ socket.onmessage = function (event) {
+ var data = JSON.parse(event.data);
+ if (data.type == "welcome") {
+ delay = 1000;
+ socket.send(JSON.stringify({ command: "subscribe", identifier: JSON.stringify({ channel: "PingsChannel" }) }));
+ return;
+ }
+ var message = data.message;
+ if (message && typeof message == "object" && "done" in message && "total" in message) {
+ document.getElementById("done").textContent = message.done;
+ document.getElementById("total").textContent = message.total;
+ }
+ };
+ }
+
+ connect();
document.querySelectorAll("form").forEach(function (form) {
if (!/\/pings$/.test(form.action)) return;