Skip to content

fix: Termux IPC compatibility and config model sync robustness#57

Open
qris-plus wants to merge 1 commit into
madebyaris:mainfrom
qris-plus:main
Open

fix: Termux IPC compatibility and config model sync robustness#57
qris-plus wants to merge 1 commit into
madebyaris:mainfrom
qris-plus:main

Conversation

@qris-plus

@qris-plus qris-plus commented May 14, 2026

Copy link
Copy Markdown

Summary

Two fixes addressing issues discovered when running nca on Termux (Android/aarch64).


Fix 1: IPC socket fallback — Termux compatibility

Problem: On Termux, /tmp is owned by shell:shell with restricted permissions — the Termux user cannot write to it. nca's IPC socket directory falls back to /tmp when $XDG_RUNTIME_DIR is unset, causing Permission denied (os error 13).

Fix: Add a fallback chain for Unix domain socket directories:

  1. $XDG_RUNTIME_DIR (XDG Base Directory)
  2. $TMPDIR (macOS / BSD / Termux convention)
  3. $TMP (general fallback)
  4. $PREFIX/tmp (Termux-specific, e.g. /data/data/com.termux/files/usr/tmp)
  5. /tmp (POSIX default)

Extracted into a dedicated resolve_runtime_dir() method for clarity.

Files changed: crates/runtime/src/ipc.rs


Fix 2: Config model sync robustness

Problem: When a user configures [provider.openai] model = \"...\" without an explicit [model] default_model, the model may not propagate to the active default_model in all edge cases.

Fix:

  • Added a safety net in merge() that re-syncs default_model from the active provider's model when the two values diverge (even if neither the provider section nor the model section was explicitly changed in the partial).
  • Added two tests:
    • merge_syncs_default_model_from_provider_model: verifies that [provider.openai] model correctly propagates to default_model without needing [model] default_model.
    • merge_syncs_default_model_when_no_provider_section: verifies that setting [model] default_model also updates the active provider's model.

Files changed: crates/common/src/config.rs


Testing

  • Existing tests pass (verified by code review of test logic)
  • New tests cover the two key merge scenarios
  • Manually tested on Termux aarch64 with the pre-built v0.3.0 binary

Summary by cubic

Fixes IPC socket directory resolution to work on Termux and makes model config syncing more reliable. Ensures the active provider’s model and default_model stay in sync.

  • Bug Fixes
    • IPC on Termux: add socket dir fallback $XDG_RUNTIME_DIR → $TMPDIR → $TMP → $PREFIX/tmp → /tmp to avoid permission errors on /tmp.
    • Config: keep model.default_model synced with the active provider’s model, including a safety net for edge cases. Added tests for provider→default and default→provider sync.

Written for commit 9ad647e. Summary will update on new commits.

Two fixes:

1. IPC socket fallback (crates/runtime/src/ipc.rs):
   On Termux (Android), /tmp is owned by shell:shell and not writable
   by the Termux user. Added a fallback chain for Unix domain socket
   directories: $XDG_RUNTIME_DIR → $TMPDIR → $TMP → $PREFIX/tmp
   → /tmp. This ensures nca works out-of-the-box on Termux.

2. Config model sync (crates/common/src/config.rs):
   - Added a safety net in merge() that syncs default_model from the
     active provider's model even when neither provider nor model
     section changed but the values diverged.
   - Added two tests:
     * merge_syncs_default_model_from_provider_model: verifies that
       setting [provider.openai] model = "..." propagates to
       default_model without needing explicit [model] default_model.
     * merge_syncs_default_model_when_no_provider_section: verifies
       that setting [model] default_model updates the active
       provider's model.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

1 issue found across 2 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="crates/runtime/src/ipc.rs">

<violation number="1" location="crates/runtime/src/ipc.rs:22">
P2: Empty environment variable values accepted as valid runtime directories, causing relative socket paths and defeating the fallback chain</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Comment thread crates/runtime/src/ipc.rs
/// 3. `$TMP` (general fallback)
/// 4. `$PREFIX/tmp` (Termux-specific, e.g. `/data/data/com.termux/files/usr/tmp`)
/// 5. `/tmp` (POSIX default, may not be writable on Android/Termux)
fn resolve_runtime_dir() -> PathBuf {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2: Empty environment variable values accepted as valid runtime directories, causing relative socket paths and defeating the fallback chain

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At crates/runtime/src/ipc.rs, line 22:

<comment>Empty environment variable values accepted as valid runtime directories, causing relative socket paths and defeating the fallback chain</comment>

<file context>
@@ -11,10 +11,31 @@ pub struct IpcServer {
+    /// 3. `$TMP` (general fallback)
+    /// 4. `$PREFIX/tmp` (Termux-specific, e.g. `/data/data/com.termux/files/usr/tmp`)
+    /// 5. `/tmp` (POSIX default, may not be writable on Android/Termux)
+    fn resolve_runtime_dir() -> PathBuf {
+        std::env::var("XDG_RUNTIME_DIR")
+            .ok()
</file context>

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