Skip to content

[No QA] Add patch so the Re.Pack dev server exits on Ctrl+C - #105612

Merged
mountiny merged 4 commits into
Expensify:mainfrom
callstack-internal:fix/repack-ctrl-c-stdin-resume
Nov 3, 2026
Merged

mountiny merged 4 commits into
Expensify:mainfrom
callstack-internal:fix/repack-ctrl-c-stdin-resume

Conversation

@kacper-mikolajczak

@kacper-mikolajczak kacper-mikolajczak commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Explanation of Change

Since native bundling moved to Re.Pack, npm run ios / npm run android / npm run start can start a dev server that ignores Ctrl+C: the port stays held and only an external signal stops the process. The dev server in @callstack/repack enters raw mode in setupInteractions without resuming process.stdin. Raw mode clears the TTY's ISIG flag, so the kernel stops turning Ctrl+C into SIGINT and the 0x03 byte is deliverable only as stream data. When a prompt was shown before the bundler starts (simulator picker, "port in use, use another port?"), the prompt framework closes with input.unpipe(), and Node's Readable.unpipe() calls pause() on its source - so the stream delivers nothing, the keypress listener never fires, and the process.on('SIGINT') handler registered next to it is unreachable. The r / d / j / a shortcuts are dead in the same session for the same reason.

This PR adds a patch with the one-line fix: process.stdin.resume() after setRawMode(true), which is what @rock-js/plugin-metro does on the same path (attachKeyHandlers resumes stdin right after entering raw mode, which is why the same flow always worked under Metro).

Known gap this PR does not close: Ctrl+Z

setupInteractions still prints Press Ctrl+c or Ctrl+z to quit the dev server. Ctrl+Z has never worked in Re.Pack, before or after this patch; the banner is an upstream bug that predates the move to Re.Pack.

Re.Pack maps Ctrl+Z to process.emit('SIGTSTP', 'SIGTSTP') (setupInteractions.js:37). process.emit only runs process.on('SIGTSTP') listeners, and no such listener exists: grep over @callstack/repack, @rock-js/* and @callstack/repack-dev-server finds none, and searching all 972 upstream commits for on('SIGTSTP' or a self-kill(process.pid, 'SIGTSTP') returns nothing. The case 'z' arrived in 5752810c (2021-03-08) already written as process.emit, so this line was never functional. Suspending needs setRawMode(false) then process.kill(process.pid, 'SIGTSTP'). Measured after this patch: the emit does reach a test SIGTSTP listener, and the process keeps running.

Metro offers no Ctrl+Z either. @react-native/community-cli-plugin and @rock-js/plugin-metro handle r / d / j plus Ctrl+C / Ctrl+D and their banners advertise only those. Fixing Ctrl+Z, or removing it from the banner, is an upstream change; this PR stays a one-line resume so it can be dropped when callstack/repack#1515 lands.

Calling-side option

A rock.config.mjs wrapper around pluginRepack() can resume stdin for npm run ios / android / ipad: @rock-js/config stores the bundler object and reads bundler.start at call time (config.js:67, :92), and platformIOS.js:45 passes getBundlerStart() into createRun. It cannot cover npm run start, because @rock-js/plugin-repack registers its own start command action calling its local startDevServer (pluginRepack.js:26-29), bypassing getBundlerStart. The durable fix belongs in @rock-js/plugin-repack, mirroring plugin-metro; that would also be acceptable to the upstream maintainers, who asked that this be fixed in the calling CLI rather than in Re.Pack.

The patch is scoped to @callstack/repack@5.4.1. setupInteractions.js is byte-identical in 5.4.2 and the canary, so no version bump escapes it; drop the patch when upstream ships the resume().

Upstream issue with reproduction and the same $ callstack/repack#1515

Fixed Issues

$ #105422
PROPOSAL:

Tests

  1. Run npm i (or bun scripts/applyPatches.ts). Verify the output contains @callstack/repack@5.4.1 (2 resume-stdin-for-ctrl-c) ✔ and patch-package succeeded without errors or warnings.
  2. Open node_modules/@callstack/repack/dist/commands/common/setupInteractions.js. Verify process.stdin.resume(); follows process.stdin.setRawMode(true);.
  3. Boot no simulator and make sure nothing holds port 8081, then run npm run ios so the device-selection prompt is shown. Pick a device and wait for the dev server to report it is listening.
  4. Press Ctrl+C once. Verify the process exits and the port is free (lsof -i :8081 returns nothing).
  5. Run npm run ios twice at the same time so the second run shows the "port in use, use another port?" prompt. Confirm it, wait for the dev server, press Ctrl+C. Verify the process exits.
  6. Repeat step 3 and press r. Verify Reloading app is printed.
  7. Repeat step 3 and press Ctrl+Z. Verify the process keeps running and the banner text is unchanged - this patch does not alter Ctrl+Z, see the Known gap section.
  • Verify that no errors appear in the JS console

Offline tests

Not applicable. Dev-server terminal handling only; nothing in this patch runs in the app or touches the network.

QA Steps

No QA. This changes the local dev-server process in a developer terminal; nothing ships in the app binary or the web bundle. patches is a fingerprint extraSource in rock.config.mjs, so the native fingerprint changes and CI will not reuse prebuilt binaries for this branch, which is expected for any patch change.

  • No QA needed

Evidence

Measured in a pseudo-terminal against the published @callstack/repack@5.4.1 tarball, with a prompt framework's unpipe() teardown replayed before the dev server starts:

variant stdin state at the prompt Ctrl+C r
unpatched setupInteractions.js isPaused() === true, readableFlowing === false still alive 3s later, killed externally nothing
with this patch isPaused() === false, readableFlowing === true exits on the first keystroke onReload runs

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I verified any copy / text that was added to the app is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • If new assets were added or existing ones were modified, I verified that:
    • The assets are optimized and compressed (for SVG files, run npm run compress-svg)
    • The assets load correctly across all supported platforms.
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • If the PR adds or modifies the UI:
    • I asked an AI agent to review the changes for accessibility issues and addressed its findings.
    • I tested with a screen reader (VoiceOver on macOS) and verified all new/changed elements are reachable with a logical focus order.
    • I verified all new/changed elements have meaningful accessible names and roles.
    • I verified state changes are announced (e.g. checked/unchecked, expanded/collapsed, selected).
  • I added unit tests for any new feature or bug fix in this PR to help automatically prevent regressions in this user flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Both patches in patches/@callstack/repack/ apply together on a clean 5.4.1 install with --error-on-fail --error-on-warn and no conflicts, which is how scripts/applyPatches.ts runs them.

Screenshots/Videos

Android: Native

No UI change.

iOS: Native

No UI change.

Raw mode clears the TTY's ISIG flag, so Ctrl+C is only deliverable as stream
data. A stdin paused earlier by a CLI prompt's unpipe() delivers nothing, so
the keypress listener never fires and the dev server cannot be interrupted.
@kacper-mikolajczak
kacper-mikolajczak requested a review from a team as a code owner November 2, 2026 12:24
@melvin-bot
melvin-bot Bot requested review from daledah and removed request for a team November 2, 2026 12:24
@melvin-bot

melvin-bot Bot commented Nov 2, 2026

Copy link
Copy Markdown

@daledah Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-02T12:36:52.554758Z 6ec1e96 PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

⚠️ This PR is possibly changing native code and/or updating libraries, it may cause problems with HybridApp. Please check if any patch updates are required in the HybridApp repo and run an AdHoc build to verify that HybridApp will not break. Ask Contributor Plus for help if you are not sure how to handle this. ⚠️

@daledah

daledah commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

I'll review this PR soon

@daledah

daledah commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Reviewer Checklist

  • I have verified the author checklist is complete (all boxes are checked off).
  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
  • I checked that screenshots or videos are included for tests on all platforms
  • I included screenshots or videos for tests on all platforms
  • I verified that the composer does not automatically focus or open the keyboard on mobile unless explicitly intended. This includes checking that returning the app from the background does not unexpectedly open the keyboard.
  • I verified tests pass on all platforms & I tested again on:
    • Android: HybridApp
    • Android: mWeb Chrome
    • iOS: HybridApp
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
  • I verified any copy / text that was added to the app is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar have been tested & I retested again)
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • If the PR adds or modifies the UI:
    • I asked an AI agent to review the changes for accessibility issues and addressed its findings.
    • I tested with a screen reader (VoiceOver on macOS) and verified all new/changed elements are reachable with a logical focus order.
    • I verified all new/changed elements have meaningful accessible names and roles.
    • I verified state changes are announced (e.g. checked/unchecked, expanded/collapsed, selected).
  • For any bug fix or new feature in this PR, I verified that sufficient unit tests are included to prevent regressions in this flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.
  • I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

Screenshots/Videos

MacOS: Chrome / Safari Screenshot 2026-11-02 at 20 12 27 Screenshot 2026-11-02 at 20 17 04

@daledah

daledah commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

@kacper-mikolajczak setupInteractions.js still prints this banner at startup

Screenshot 2026-11-02 at 20 19 49

Step 7 of the Tests confirms that Ctrl+Z doesn't quit: Repeat step 3 and press Ctrl+Z. Verify the process keeps running — this patch does not change Ctrl+Z

Should we fix this as well?

@kacper-mikolajczak

kacper-mikolajczak commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor Author

Hi @daledah, thanks for the feedback!

I have checked and Ctrl+Z seems to never worked in Re.Pack, with or without this patch. The banner is an upstream bug from 2021. What my agent found out is, the case 'z' shipped in 5752810c (2021-03-08).

Metro offers no Ctrl+Z either. @react-native/community-cli-plugin and @rock-js/plugin-metro bind r/d/j plus Ctrl+C/Ctrl+D and advertise only those keys.

With that said, I would do nothing for now at least to keep the parity and do not introduce too much complexity in the patches, where they would diverge from source.

@daledah daledah left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@melvin-bot
melvin-bot Bot requested a review from mountiny November 2, 2026 18:14

@mountiny mountiny left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks!

@mountiny
mountiny merged commit 035509f into Expensify:main Nov 3, 2026
28 of 31 checks passed
@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

🚧 mountiny has triggered a test Expensify/App build. You can view the workflow run here.

@OSBotify

OSBotify commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

@OSBotify

OSBotify commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

🚀 Deployed to staging by https://github.com/mountiny in version: 9.5.31-0 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 failure ❌
🍎 iOS 🍎 success ✅

@OSBotify

OSBotify commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

🚀 Deployed to staging by https://github.com/mountiny in version: 9.5.31-0 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

@OSBotify

OSBotify commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

🚀 Deployed to production by https://github.com/blimpich in version: 9.5.31-4 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

Bundle Size Analysis (Sentry):

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.

4 participants