Skip to content

fix(server): fall back to exclusive copy when Android SELinux blocks hardlinks - #42200

Open
noah1510 wants to merge 1 commit into
pingdotgg:mainfrom
noah1510:fix/android-termux-compat
Open

noah1510 wants to merge 1 commit into
pingdotgg:mainfrom
noah1510:fix/android-termux-compat

Conversation

@noah1510

@noah1510 noah1510 commented Nov 24, 2026 •

Copy link
Copy Markdown

Problem

On Android (Termux, arm64, Node v26.13.1), SELinux blocks link(2) with EACCES/EPERM, breaking fs.link, fs.linkSync, and fs.promises.link calls (e.g., lockfile and atomic link operations).

Change

  • Add an Android-only hardlink fallback (apps/server/src/androidCompat.ts, invoked early in runCliCommand() in apps/server/src/binMain.ts) that wraps fs.link, fs.linkSync, and fs.promises.link when process.platform === "android". When link(2) fails with EACCES or EPERM, it falls back to copyFile / copyFileSync / fs.promises.copyFile with COPYFILE_EXCL so EEXIST semantics are preserved, calls NodeModule.syncBuiltinESMExports(), and guards against double-patching. Non-Android platforms are untouched.
  • Add unit tests (apps/server/src/androidCompat.test.ts) covering non-Android no-op behavior, EACCES/EPERM fallback across sync/callback/promise APIs, error propagation for non-SELinux errors (EEXIST), and idempotency.

Split from the original combined PR: the companion ffi-rs 1.3.2 -> 1.3.7 bump is now in #44856 (full native Termux setup also depends on upstream microsoft/node-pty#1019). Creating the fork, commits, and this PR were all done using T3 Code itself running inside Termux via t3 serve and controlled from the T3 Code Android app (the web UI was also tested and used to configure Antigravity).

Scope

Focused, Android-only compatibility fix (process.platform === "android") with zero runtime impact on macOS, Linux, or Windows. No prior issue was filed because the failure is a straightforward EACCES/EPERM error from link(2) under Android SELinux.

Verification

Verified directly on Android arm64 (Termux, Node v26.13.1, pnpm 12.14.0):

  • Live T3 Code server on Android/Termux: Started the server in Termux with t3 serve, controlled it via the T3 Code Android app (creating the fork, commits, and PRs from it), and also tested the web UI directly, including configuring Antigravity through the web UI.
  • Real Android SELinux hardlink fallback E2E: Ran patchAndroidHardlinkFallback() against real node:fs / node:fs/promises on temporary files in Termux; verified linkSync, link, and promises.link fall back to copying content and still fail with EEXIST when the destination already exists.
  • Unit test assertions: Verified all 4 cases from apps/server/src/androidCompat.test.ts (non-Android no-op, EACCES/EPERM fallback with COPYFILE_EXCL, EEXIST propagation without copy, and idempotency).
  • Static checks:
    • tsc --noEmit (strict, exactOptionalPropertyTypes, noUncheckedIndexedAccess, verbatimModuleSyntax, erasableSyntaxOnly) on apps/server/src/androidCompat.ts: 0 errors.
    • oxlint on apps/server/src/androidCompat.ts, apps/server/src/androidCompat.test.ts, and apps/server/src/binMain.ts: 0 warnings, 0 errors.
    • oxfmt --check on all 3 files: all formatted cleanly.
  • Could not run locally: vp (vite-plus) does not ship an android-arm64 native binding yet, so vp run check:changed and running Vitest via vp test run could not be executed in Termux and rely on GitHub Actions CI.

Written with Gemini 4 Neon via Antigravity (running inside T3 Code on Android/Termux).

@github-actions github-actions Bot added vouch:unvouched Author is not yet trusted in the VOUCHED list. size:L 100-499 changed lines (additions + deletions). labels Nov 24, 2026
@coderabbitai

coderabbitai Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The server adds an Android-only fallback from blocked hardlink operations to exclusive file copies. The CLI applies the patch before command dispatch. Tests cover supported platforms, error handling, and repeated patching.

Changes: Android hardlink fallback

Layer / File(s) Summary
Implement and activate the Android fallback
apps/server/src/androidCompat.ts, apps/server/src/binMain.ts, apps/server/src/androidCompat.test.ts
The patch wraps callback, synchronous, and promise hardlink APIs. On Android, EACCES and EPERM trigger a copy with COPYFILE_EXCL; other errors propagate. The CLI applies the patch before command dispatch. Tests cover platform behavior, error handling, and repeated patching.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: krispamb

Merge Risk: Minimal · up to b0ea1

This change adds a narrowly scoped Android fallback for blocked hardlinks and leaves other platforms unchanged. No actionable merge-blocking risk was found in the supplied changes.

Pre-merge checks: Passed 4

Check name Status Explanation
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Title check Passed The title "fix(server): fall back to exclusive copy when Android SELinux blocks hardlinks" follows conventional commit form and names the main change: an Android-only fallback from hardlink to exclusi…
Description check Passed The description follows the template's sections: Problem, Change, Scope, and Verification. It explains the SELinux EACCES/EPERM failure, the Android-only fallback with COPYFILE_EXCL, and the unit test…
Full details: Title check

Explanation

The title "fix(server): fall back to exclusive copy when Android SELinux blocks hardlinks" follows conventional commit form and names the main change: an Android-only fallback from hardlink to exclusive copy when SELinux blocks link(2). It matches the androidCompat.ts patch, binMain.ts invocation, and tests. It omits the companion ffi-rs bump, which the description says was split out, so that omission is expected.

Full details: Description check

Explanation

The description follows the template's sections: Problem, Change, Scope, and Verification. It explains the SELinux EACCES/EPERM failure, the Android-only fallback with COPYFILE_EXCL, and the unit tests. It gives a scope justification for not filing an issue and lists concrete verification, including Termux runs and static checks. It also notes that vp-based checks could not run locally and rely on CI. It does not include a linked issue or a maintainer request, but the template allows a short explanation for small fixes. The template's model/harness attribution line is present, though it is set as a sentence at the end.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 99076b7 and b0ea153.

Files selected for processing: 1

  • apps/server/src/binMain.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

…hardlinks

Android SELinux blocks link(2) with EACCES/EPERM, breaking file locking and atomic copy operations that rely on fs.link*.

Patch node:fs link, linkSync, and promises.link on Android early in runCliCommand() to fall back to exclusive copyFile (COPYFILE_EXCL) while preserving EEXIST semantics, and add unit tests covering fallback, error propagation, and idempotency.

Co-authored-by: Antigravity (Gemini 4 Neon) <noreply@google.com>
@noah1510
noah1510 force-pushed the fix/android-termux-compat branch from 99076b7 to b0ea153 Compare November 28, 2026 09:33
@noah1510 noah1510 changed the title fix(server): fix ffi-rs startup crash and hardlink locking on Android/Termux fix(server): fall back to exclusive copy when Android SELinux blocks hardlinks Nov 28, 2026
@github-actions github-actions Bot added size:M 30-99 changed lines (additions + deletions). and removed size:L 100-499 changed lines (additions + deletions). labels Nov 28, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M 30-99 changed lines (additions + deletions). vouch:unvouched Author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant