Skip to content

Add backend recovery overlay and quit deadline#65

Draft
fgilio wants to merge 3 commits intomainfrom
claude/rebase-update-main-vjwJh
Draft

Add backend recovery overlay and quit deadline#65
fgilio wants to merge 3 commits intomainfrom
claude/rebase-update-main-vjwJh

Conversation

@fgilio
Copy link
Copy Markdown
Owner

@fgilio fgilio commented Apr 27, 2026

Caution

DO NOT MERGE. The electron-main patch (scripts/patch-native-electron-main.php) is wired as a composer post-autoload-dump hook, but vendor/nativephp/desktop/resources/electron/out/main/index.js is regenerated by electron-vite build inside php artisan native:build (which release.yml runs after composer). Any patches applied at composer time get overwritten before electron-builder packages the app, so the lifecycle IPC handlers, phpServer registration, auto-restart, and 3s quit deadline never reach the shipped binary.

Resolve before merging. Options:

  • Add a postbuild script to the upstream electron package.json (patched the same way release.yml already patches npm ci -> npm install) that runs the PHP patch script after electron-vite build.
  • Convert the patch into an electron-vite plugin in electron.vite.config.mjs so out/main/index.js is born patched.
  • Patch the TS source (src/main/index.ts) instead of the build output, so electron-vite emits a patched bundle.

CI is green now (commit a51da14 makes the script skip gracefully when the build artifact is missing), but green CI does not mean the feature works in production.


Recover from silent NativePHP dev-server death and unblock Cmd+Q wedges:

  • Renderer overlay (Alpine + Tailwind) detects backend failure via Livewire
    commit hook plus a `/_rfa/health` poller; reloads on recovery, shows
    Force Quit / Restart buttons after it gives up.
  • `/_rfa/health` route registered outside web middleware so SQLite session
    contention can't false-flip the overlay.
  • Build-time vendor patches (`scripts/patch-native-electron-main.php` and
    the existing `patch-native-preload.php`) auto-respawn the PHP server on
    the captured port, expose a `rfaLifecycle` contextBridge for force-quit
    and restart, and arm a 3 s `app.exit(0)` deadline so Cmd+Q always wins.
  • Patch scripts are atomic (`.tmp` + rename), versioned-sentinel,
    whitespace-tolerant, and exit non-zero on missing anchors.

Co-Authored-By: Claude Opus 4.7 (1M context) noreply@anthropic.com

fgilio and others added 2 commits April 27, 2026 06:06
Recover from silent NativePHP dev-server death and unblock Cmd+Q wedges:

- Renderer overlay (Alpine + Tailwind) detects backend failure via Livewire
  commit hook plus a `/_rfa/health` poller; reloads on recovery, shows
  Force Quit / Restart buttons after it gives up.
- `/_rfa/health` route registered outside web middleware so SQLite session
  contention can't false-flip the overlay.
- Build-time vendor patches (`scripts/patch-native-electron-main.php` and
  the existing `patch-native-preload.php`) auto-respawn the PHP server on
  the captured port, expose a `rfaLifecycle` contextBridge for force-quit
  and restart, and arm a 3 s `app.exit(0)` deadline so Cmd+Q always wins.
- Patch scripts are atomic (`.tmp` + rename), versioned-sentinel,
  whitespace-tolerant, and exit non-zero on missing anchors.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 27, 2026

Warning

Rate limit exceeded

@fgilio has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 56 minutes and 40 seconds before requesting another review.

To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 6ff2c704-719e-457b-9c81-5fb5255d251c

📥 Commits

Reviewing files that changed from the base of the PR and between b728a65 and a51da14.

📒 Files selected for processing (15)
  • .github/actions/setup-php-composer/action.yml
  • bootstrap/app.php
  • composer.json
  • docs/upstream/nativephp-silent-close-handler.md
  • public/js/backend-health.js
  • resources/views/components/backend-health-overlay.blade.php
  • resources/views/layouts/app.blade.php
  • scripts/lib/native-patch-helpers.php
  • scripts/patch-native-electron-main.php
  • scripts/patch-native-preload.php
  • tests/Browser/BackendHealthFalsePositiveTest.php
  • tests/Browser/BackendHealthOverlayTest.php
  • tests/Feature/HealthRouteTest.php
  • tests/Unit/Scripts/PatchNativeElectronMainTest.php
  • tests/Unit/Scripts/PatchNativePreloadTest.php
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/rebase-update-main-vjwJh

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 32340deac0

ℹ️ 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".

Comment on lines +163 to +167
state.phpServer = newServer;
newServer.on("error", (err) => {
console.error('[rfa] PHP respawn error:', err);
});
newServer.on("close", __rfaRestartHandler);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Drain stdio on respawned PHP server

The respawn branch creates newServer and only wires error/close handlers, but never attaches stdout/stderr listeners. In this code path, callPhp() spawns the same php -S process used at startup, and that server continuously logs requests to stderr; without a consumer, the pipe buffer can fill and block the child process, causing the “recovered” backend to hang again under normal traffic. Please attach the same stream-draining listeners used for the initial phpServer to each respawned child.

Useful? React with 👍 / 👎.

`out/main/index.js` is generated by `electron-vite build`, not shipped
in the package dist. Hard-erroring in `post-autoload-dump` broke every
CI job that runs `composer install` from a cold cache (lint, types,
test-core, test-browser, benchmark-perf). Treat a missing file as a
skip; still error on missing anchors so upstream shape changes stay
loud.

Also add the new script + helper to the vendor cache key so the cache
busts when the patch script changes.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@fgilio fgilio marked this pull request as draft April 27, 2026 07:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant