Repository navigation
feat(pm-console): the app works with no connection, and sends what was done once when it is back - #13287
Conversation
…s done once when it is back The app could not open without a connection, showed nothing, and lost whatever was done. Now: - It opens: the service worker keeps the app's own files. - It shows what the device last saw: the worker keeps the last good answer to everything the app reads, under the address it was asked for. The network is asked first; a copy is shown only when it gives no answer or is too slow, and is marked as one. An answer that says no is never replaced by a copy. The header says offline and how old. - What the owner does is kept and sent once. Every action gets a name on the device (a UUID) and is written to the browser's database before it is sent (public/outbox.js). With no connection it waits and is sent when there is one: by the page, or by the service worker if the app is closed (Background Sync). - The platform does an action once under its name however often it arrives. The edge writes down each name it did with its answer; a machine keeps its own record (src/named.ts, one for actions sent straight to it, relayed to it, and held for it). - What may have changed is not sent unasked: a merge, a deploy, a cancel, an unblock and a service action are sent by themselves only within ten minutes, and after that wait for the owner to look again. A merge names the commit the owner was shown, and GitHub merges only that. What sets the connection up or carries a secret is never kept. - A sign-in that ran out is told from no connection. More, On this device lists what is waiting, kept back, failed, with the platform, and sent; and can fetch a copy of every screen before a flight. Also: a first load that failed said "Loading" for ever instead of why; a toast's Undo was written in the page's ink, not the toast's. 321 tests under bun (was 278). 80 planted faults, all caught. In a real Chrome against the demo laptop and the demo edge, light and dark: taken offline it opens, shows, keeps, and sends each once; and with the app closed the worker sends when woken. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YLT5K1QVuzZjfWGFhXSSNF
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 46 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
While an action was written down and not yet answered, a send of what is waiting (the page's own, every twenty seconds, or the service worker's) could take it for something left waiting and send it too. The platform would still have done it once, under its name; the owner would have been told twice. An action is now sent under the same lock. Also: "Forget what it last saw" left its button disabled in a browser with no worker. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YLT5K1QVuzZjfWGFhXSSNF
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4eba2ebb83
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const before = (await link?.seen?.(name)) ?? null; | ||
| if (before?.state === "running") return json({ error: "This is still being done.", running: true }, 409); |
There was a problem hiding this comment.
Atomically claim action names before awaiting the audit write
When two requests with the same UUID arrive concurrently, both can observe seen(name) === null. Each then enters act(), which awaits the asynchronous audit write before reaching begin(name). Since Named.begin() does not reject an already claimed name, both requests proceed to perform(), duplicating external side effects such as comments or task moves. This affects direct host requests and independently forwarded edge relays. Make checking and claiming the name atomic before yielding to the audit operation.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in e4ab229. The name is now taken first, with nothing waited for in between, and what is known of it is read after (Named.take, Named.known); the second arrival gets 409 running. The edge's once() does the same. Tests: two arrivals at the same moment on the laptop (with a slow audit write) and at the edge (with a slow storage read) are one doing.
Generated by Claude Code
| fate = { ok: false, error: "this is not an action that may be done late" }; | ||
| } else { | ||
| await this.record(held.id, "started"); | ||
| await this.named.record(held.id, "started"); |
There was a problem hiding this comment.
Mark held actions as running in the shared name record
If a device retries an action while the host is executing its held copy, this call records "started" without adding the ID to Named.running. The newly shared record therefore makes Named.seen() report "lost", and the HTTP handler returns a terminal 502 claiming the host restarted even though the action is still executing. The device then marks the action failed and offers a retry under a new name, potentially repeating a successful operation. Use the running-state lifecycle (begin/end) for held execution too.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in e4ab229. Doing a held action takes the name before anything is read and gives it back after, like any other. Fixing it turned up that EdgeLink had two methods named take and the later one silently replaced the first; renamed. Test: a retry that reaches the laptop while the held copy is being done gets 409 running, and the outcome once it is over.
Generated by Claude Code
| // Still no connection: say so, and the browser will call again. | ||
| if (out.offline) throw new Error("still offline"); |
There was a problem hiding this comment.
Keep background sync pending after retryable platform responses
With the app closed, a 503 response or 409 { running: true } leaves the action in waiting, but Outbox.flush() returns offline: false. Consequently send() resolves successfully here, consuming the Background Sync registration without arranging another attempt. For example, a timely action rejected because the laptop is temporarily unreachable will not be retried or marked stale until the app is opened again. Reject or re-register when retryable work remains, while treating sign-in and stale entries separately.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in e4ab229. flush now says how many entries still wait to be sent, and the worker rejects the sync while that is not zero (not when what waits needs a sign-in, and not for stale entries). On the browser's last call it also says what is left.
Generated by Claude Code
| if (res.status === 200) { | ||
| const copy = kind === "read" ? await stamped(res.clone(), { "x-pm-kept-at": String(Date.now()) }) : res.clone(); | ||
| await cache.put(key, copy); |
There was a problem hiding this comment.
Return successful network responses even if caching fails
When Cache Storage rejects a write, such as when the device exhausts its storage quota, this awaited cache.put() rejects fromNetwork despite the fetch having succeeded. The response-selection logic then serves an old offline copy or rejects the request entirely if no copy exists, preventing healthy online reads of new screens. Make caching best-effort and return the successful network response independently of whether persistence succeeds.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in e4ab229. Keeping a copy is on a best effort: the network's answer is returned whether or not the write to the cache worked. Also handled: a browser that gives the site no cache at all (the worker installs and answers as if it kept nothing).
Generated by Claude Code
| let answer; | ||
| try { | ||
| answer = await send(entry); |
There was a problem hiding this comment.
Honor cancellations of queued entries during a flush
If a flush is waiting for action A's response and the owner selects “Do not send” for a later queued action B, the page removes B from IndexedDB, but this loop still sends B from the snapshot loaded at the start of the flush. It then writes B back with its outcome. This affects actions that had not even started sending when canceled, including merges and deploys. Coordinate cancellation with the sender and check that each queued entry still exists before starting its request.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in e4ab229. Each entry is read again from the store just before it is sent; one removed or dealt with meanwhile is skipped.
Generated by Claude Code
| keeps = false; | ||
| } | ||
| } | ||
| const answer = await Outbox.httpSend(entry); |
There was a problem hiding this comment.
Send new actions through the ordered outbox
When older actions are waiting, this direct send lets a newly submitted action overtake them instead of following the flush's oldest-first ordering. For example, while a flush waits on an earlier request, the owner can successfully change an issue's rank to priority/high; the flush subsequently sends an older queued rank change for that same issue and overwrites the newer choice. Ops.setRank() applies the supplied rank and removes competing ranks, so the final state reflects the older action. Route queueable submissions through the same ordered sender rather than sending them independently.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in e4ab229. A new action is written down and sent through the same oldest-first pass as what is waiting (sendInOrder). Also added: two about the same thing keep their order while the earlier one has not been taken (503, or 409 running), on the device and in what the edge holds for a machine. One case is left and filed as #13398.
Generated by Claude Code
…orker that asks again Review of the offline work found six faults; looking at them found more of the same kinds. Once under a name: - A name is taken first, with no waiting in between, and what is known of it is read after (Named.take, known), on the laptop and at the edge. Two arrivals under one name at the same moment used to both look, both find nothing, and both do it. - A held action being done on the laptop is marked as being done, so a device sending it again meanwhile is told to wait, not that the laptop restarted. - The laptop's link had two methods called take; the second silently replaced the first. Renamed (the console is not type-checked yet). - The record of names is read once however many ask together, and written one write at a time. In the order it was done: - Something done now is written down and sent through the same oldest-first pass as what is waiting (sendInOrder), not ahead of it. - Two about the same thing keep their order: while the earlier one has not been taken, the later one waits, on the device and in what the edge holds for a machine (subject, subjectOf). - Each entry is read again just before it is sent, so "do not send" during a send is honoured. The worker: - Asks to be woken again while anything still waits to be sent, and on the browser's last call says what is left. - Keeps copies on a best effort: a full device, or a browser with no cache at all, still gets the network's answer, and the worker still installs. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YLT5K1QVuzZjfWGFhXSSNF
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e4ab229e64
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| return await this.once(id, kind, () => | ||
| this.directAct(kind, args as Record<string, unknown>, by, who.via, id), |
There was a problem hiding this comment.
Preserve name ownership when switching execution sides
If an action succeeds but its response is lost, retrying its UUID after the execution route changes can repeat the external effect. For example, an issue.comment delegated to the host during the edge’s refusal cooldown is recorded only in the host’s Named ledger. Once that cooldown expires, a retry enters once() here, finds no edge a:<id> record, and posts the comment again. The reverse occurs when an edge-completed action is retried while its kind is delegated. Resolve existing names independently of the current route, or persist which side originally claimed each name.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 9e252b2. The edge now writes down a name it hands to a machine as given, and looks a name up before choosing a side: a name given to a machine goes to a machine again even after the edge takes the kind back, and a name the edge did is answered from its record even while the kind is handed over. Test: both directions, for a holdable kind and for a merge whose answer was lost.
Generated by Claude Code
| if (status === 200 && body.ok === true) { | ||
| return body.held === true | ||
| ? { state: "held", note: "Kept for the laptop, which will do it when it is back.", result: null } | ||
| : { state: "done", note: "", result: body.result ?? null }; |
There was a problem hiding this comment.
Surface refused question answers during outbox replay
When a queued question answer is replayed after the question has already been answered, Work.submit() returns { applied: 0, refused: [...] } inside a successful HTTP response rather than throwing. This branch marks that entry done, so background replay reports it as sent and the device history never exposes why the answer was not recorded. The immediate sendAnswer() path checks result.refused, and heldRunner() explicitly treats these outcomes as failures, but neither check runs for device-outbox replay. Preserve and surface refused or partially applied outcomes instead of counting them as successful completions.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 9e252b2. classify treats a success whose result carries refused as failed, with the same words the laptop uses for one it does late ("Not recorded: …" or "N recorded, M not recorded: …"), so a replayed answer shows under "could not be done".
Generated by Claude Code
…nt" means recorded Two findings from review of the last change, both real. - Which side does a kind can change: the edge is turned away for an hour, then takes the kind back. An action given to the laptop, its answer lost, and sent again after the change was done again by the edge, which had no record of the name; and the other way about. The edge now writes down a name it hands to a machine as given, and looks a name up before choosing a side. - An answer to a question settled in the meantime comes back as a success that says "not recorded". Sent from what the device kept, it was marked sent. It is now "could not be done", with why, as the laptop already says of one it does late. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YLT5K1QVuzZjfWGFhXSSNF
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9e252b2ccf
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const work = () => submitNow(entry); | ||
| return navigator.locks?.request ? navigator.locks.request("pm-outbox", work) : work(); |
There was a problem hiding this comment.
Persist queueable actions before waiting for the send lock
When another page or the service worker is already sending a slow request, this waits for its pm-outbox lock before submitNow() reaches outbox.put(). Both flushOutbox() and the worker hold that lock throughout their HTTP requests, and Outbox.httpSend() has no timeout. Consequently, a newly submitted prompt, note, or answer remains only in memory while waiting; closing or reloading the page during that wait loses it even though IndexedDB is available. Persist queueable entries before waiting for the sender lock, and serialize only their sending.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in c5c1a1d. A queueable action is written to the outbox first, and only its sending waits for the lock; what is never kept (the "now" kinds) is sent without the lock. httpSend also has a one-minute limit now, so a request that hangs cannot hold the lock for every sender. Checked in a real Chrome: with the lock held by another sender, the action is already in IndexedDB, and after the page is reloaded it is sent once.
Generated by Claude Code
| "div", | ||
| { class: "row end" }, | ||
| group.can.includes("drop") | ||
| ? h("button", { class: "small ghost", onclick: () => after(() => outbox.remove(e.id)) }, group.state === "waiting" ? "Do not send" : "Discard") |
There was a problem hiding this comment.
Restore canceled answers to the open-question list
After answering a question offline, selecting “Do not send” removes the queued answer but leaves its key in answeredHere. sendAnswer() has already removed the question from the local document, and withoutAnswered() continues filtering it from subsequent server responses because the unanswered question is still open there. Consequently, canceling the answer leaves the question hidden for the remainder of the page session, even after reconnecting, so it cannot be answered again without reloading. Clear the optimistic answered state and restore or reload the question when its queued answer is canceled.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in c5c1a1d. The set of answered questions is now worked out from the outbox (answers waiting or held), not kept beside it: taking an answer back, or one that fails, brings the question back (the questions document is read again whole), and one still waiting stays out of the list after a reload. Checked in a real Chrome, and the check fails against the previous code.
Generated by Claude Code
…a question again when its answer is taken back Two findings from review, both real, both in the page. - An action was written down only once it held the turn to send. With another tab or the worker in the middle of a slow send, closing the page lost it. It is written down first, and only the sending waits. One try at sending is given a minute, so a request that hangs cannot hold every sender up. - The page kept its own list of questions answered here, and "do not send" did not clear it: the question stayed hidden. The list is now worked out from what is kept, so a question is out of the list while its answer waits (across a reload too) and back when the answer is taken back or does not count. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YLT5K1QVuzZjfWGFhXSSNF
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c5c1a1db74
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| sendingAnswers.delete(key); | ||
| } | ||
| if (out.state === "failed" || out.state === "refused") toast(out.note, true); |
There was a problem hiding this comment.
Restore filtered questions when sending an answer fails
If a questions refresh returns a new document while an answer is being sent, withoutAnswered() removes that question using sendingAnswers. If the submission then fails, deleting this key does not restore the question: the failure branch only shows a toast and reloads core, while subsequent questions requests can return 304 and preserve the filtered document. The still-unanswered question consequently remains hidden until the server document changes or the page reloads. Restore it or invalidate and reload the questions document after clearing the sending key on failure.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in bd1d03f. When an answer fails, the questions document is read again whole (its tag is dropped first, so a 304 cannot keep the filtered copy). Checked in a real Chrome with the list read while the answer was on its way; the check fails against the previous code.
Generated by Claude Code
| } catch (error) { | ||
| // Given up on part-way through the answer: no answer at all. | ||
| if (gaveUp(error)) return { network: true }; | ||
| body = null; |
There was a problem hiding this comment.
Retry transport failures while reading action responses
When the connection drops after response headers arrive but before the body finishes, res.json() can reject with a transport TypeError, rather than AbortError or TimeoutError. This catch converts that failure into body: null, which classify() interprets as requiring sign-in. With the app closed, the service worker then resolves the sync event because out.signin suppresses retries, leaving the action's outcome unresolved until the app is reopened despite the session still being valid. Treat response-body transport failures as retryable network failures instead of sign-in responses.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in bd1d03f. Only a body that arrives and is not JSON (SyntaxError) is read as something other than the platform; any other failure while reading the body is no answer ({ network: true }), so it is offered again and the worker asks to be woken again.
Generated by Claude Code
| const said = flushSaid(out.changed); | ||
| if (said) { | ||
| toast(said, out.changed.some((e) => e.state === "failed")); | ||
| refresh(true); |
There was a problem hiding this comment.
Preserve active drafts when background replay finishes
If an older queued action finishes sending while the owner is composing a bug report, intake note, or agent message, this background call to refresh(true) bypasses refresh()'s focused-input guard and redraws the current screen. viewBugs(), viewIntake(), and viewAgents() recreate their textareas without retaining their contents, so reconnecting and replaying unrelated queued work can silently erase an unsent draft. Use a non-forced refresh for background completion or preserve the active form's state before redrawing; the service-worker completion handler has the same forced-refresh behavior.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in bd1d03f, two ways. A send that finishes in the background (the page's own flush, the worker's message, the worker taking the page over) no longer forces a redraw: it draws the screen again only when no dialog is open and no field has the cursor. And the bug, note and message forms now keep what is typed across any redraw, as the prompt box already did, so a draft that was set aside survives too. Checked in a real Chrome, cursor in the field and out of it; the check fails against the previous code.
Generated by Claude Code
…a cut-off answer is retried Three findings from review, all real. - When something kept earlier was sent, the screen was drawn again whatever the owner was doing, and a bug report, a note or a message half typed was gone. A background send now draws the screen again only when nobody is in the middle of something, and those three forms keep what is typed across any redraw. - An answer whose body stops arriving part-way was read as "sign in again", which also stopped the worker from asking to be woken again. It is no answer, and is offered again. - A failed answer could leave its question hidden if the list was read while the answer was on its way. On failure the list is read again whole. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YLT5K1QVuzZjfWGFhXSSNF
What
Step 4 of the plan in
doc/2026-11-23T06-50-00Z_architecture_pm_platform_cloudflare_core/: the app works with no connection, in a browser and in the Android app (which is this site in Chrome).Before this the app could not open offline, showed nothing, and lost whatever was done.
How it works
offlineand how old; a line under it says there is no connection and what is kept.public/outbox.js, one file for the page and the worker). With no connection it waits and is sent when there is one: by the page, or by the worker if the app is closed (Background Sync).src/named.ts: one record for actions sent straight to it, relayed to it, and held for it). A name offered again is answered from the record, markedagain.More → On this device: what is waiting, kept back, could not be done, is with the platform for a machine, and was sent; each can be dropped, sent, or tried again. "Keep a copy of every screen now" reads every screen once, for before a flight. "Forget what it last saw" drops the copies; signing out does the same.
Also fixed on the way
Checked
ServiceWorker.dispatchSyncEvent), sends what was kept, and the reopened app shows it sent.Not checked
After review
Six findings, all real, and more of the same kinds found while fixing them. All in
e4ab229e64.Once under a name
take; the second silently replaced the first, and the tests passed for the wrong reason. Renamed. The console's TypeScript is not type-checked anywhere: a check finds this at once, plus 53 smaller complaints, none a fault. Adding it to CI is the next PR.In the order it was done
The worker
Checked again: 40 planted faults in the new code, all caught (two more changed nothing: each is behind a second guard). In a real Chrome against both demos: the offline flow light and dark, the worker woken with the app closed, and a new check that an older waiting rank and a new one leave the device in order and are done in order (with the old direct send planted, that check fails). axe-core over 20 screens, dialogs and toasts: no violations. The Worker in its real runtime passes its own checks.
After the second review (
9e252b2ccf), two more, both real:After the third review (
c5c1a1db74), two more, both in the page:342 tests; 52 planted faults in the review fixes, all caught. Each of these two has a check in a real Chrome that fails against the code before its fix.
After the fourth review (
bd1d03fb2a), three more:Each has a check in a real Chrome that fails against the code before its fix.
Left out, and filed: #13398, an older action held for a machine against a newer one about the same thing that the edge does itself.
🤖 Generated with Claude Code
https://claude.ai/code/session_01YLT5K1QVuzZjfWGFhXSSNF
<ahref="https://dashboardbackend.blacksmith.sh/track/run-proof?expires=1798030510&installation_model_id=443529&pr_number=13287&ref=codesmith_pr_footer&repository=developing-today%2Fcode&return_to=https%3A%2F%2Fgithub.com%2Fdeveloping-today%2Fcode%2Fpull%2F13287&variant=see_it_in_action&signature=85629cf6e4ddfc077f087e9374a91807b4a706b260743ff3eafd6aacbbd64b64"><picture><source media="(prefers-color-scheme: dark)" srcset="https://pr-comments-assets.blacksmith.sh/codesmith/proof-see-it-in-action-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://pr-comments-assets.blacksmith.sh/codesmith/proof-see-it-in-action-v2-light.svg"><img alt="See it in action" src="https://pr-comments-assets.blacksmith.sh/codesmith/proof-see-it-in-action-v2-dark-3x.png" width="132" height="28">Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.Generated by Claude Code