Skip to content

openchamber-serve single-instance guard never matches: generated wrapper has tr '\\0' instead of tr '\0' #2562

Closed

Description

@dezren39

Summary

The single-instance guard added to the generated openchamber-serve wrapper (bc6044f, for dezren39/darwin-nix#1117) never matches a running server, so it is a no-op in production: after a restart, a leftover OpenChamber server keeps sharing the socket-activated listener on 127.0.0.1:3000 with the new instance.

Root cause

In the wrapper as generated into the Nix store, the guard's cmdline capture is:

cmd="$(cat "$proc/cmdline" 2>/dev/null | tr '\\0' ' ')"

The generated script literally contains tr '\\0' ' ' (verified byte-for-byte with grep | cat -A on the store file). In shell single quotes that passes backslash + backslash + 0 to tr, and GNU tr reads \\ as an escaped backslash, so the translate set is {backslash, 0} — NUL bytes are never converted to spaces. Bash command substitution then strips the NULs, concatenating the argv words (...cli.jsserve--foreground--port3000--host...), so neither the cli.js serve pattern nor the --port 3000 boundary pattern can ever match any real process.

Intended text in the generated script: tr '\0' ' '.

Observed impact (2026-10-29 23:50 CDT, laptop)

systemctl --user restart openchamber.service with the guarded wrapper: the tracked main (pid 3892827) stopped cleanly, the new instance (pid 483540) started, the guard logged no reap, and the untracked leftover (pid 1668515, started 12:38 CDT) was still holding fd 3 on 127.0.0.1:3000 alongside the new instance (ss -tlnp showed both pids). Replaying the guard's three checks (exe match, cmdline match, port match) by hand against the leftover matched all three once \0 was translated correctly. The leftover had to be TERM'd manually to return to exactly one instance.

Suggested fix

  • Emit tr '\0' ' ' in the generated wrapper (adjust the Nix string escaping in home/common/default.nix where openchamberStart is defined).
  • Add a regression test that runs the guard scan against a synthetic /proc-style cmdline with real NUL separators (or a fake leftover process) and asserts the leftover is selected for reaping.

Acceptance criteria

  • The generated openchamber-serve wrapper contains tr '\0' ' ' (single backslash) — verified byte-for-byte in the generated store file, not just in the Nix source
  • A regression test runs the guard scan against a synthetic cmdline with real NUL separators (or a fake leftover process) and asserts the leftover is selected for reaping
  • After a restart with a leftover instance present, exactly one openchamber instance holds 127.0.0.1:3000 (the feat(usage-hub): snapshot retention — 13-month raw, monthly rollups, backup check #1117 scenario from dezren39/nix, re-verified)
  • No other generated-wrapper strings with the same double-escaping defect remain (audit the same Nix string for sibling tr/escape uses)

Activity

  1. added
    kind/bugSomething isn't working (prefixed form of the classic bug label)
    priority/highImportant and time-sensitive
    effort/sSmall: expected under 2 hours of work
    meta/enrichedIntake review done: acceptance criteria, links, and normalized labels added
    on Oct 30, 2026
  2. dezren39 commented on Oct 30, 2026

    @dezren39
    MemberAuthor

    Intake review

    Still live: root cause is byte-verified in the generated store file (tr '\\0' in the shipped wrapper) and the production symptom was observed live on the laptop 2026-10-29 23:50 CDT — a leftover instance (pid 1668515) kept sharing 127.0.0.1:3000 after a restart and had to be TERM'd by hand. No fix has landed.

    Related: dezren39/darwin-nix#1117 (the single-instance guard's origin). Cross-repo note: the fix itself lands in dezren39/nix (home/common/default.nix, where openchamberStart is defined) — per the fleet's one-issue-per-set rule this issue tracks the set; the nix PR should reference this issue by URL rather than filing a nix duplicate.

    Notes / risks: the mechanism is subtle — GNU tr reads \\ as an escaped backslash, so the translate set is {backslash, 0} and NULs survive until bash strips them, concatenating argv words so neither guard pattern can match. The fix is one character of escaping, but the regression test is the real deliverable: without a synthetic-cmdline test this exact class of Nix-string-escaping bug will recur silently.

    Suggested approach: fix the escaping in the Nix source, regenerate, byte-verify the store output, and add the guard-scan test against a fake /proc cmdline.

  3. added
    source/creatorFiled by the new-issue-creator job
    task/triageQueue packet kind: verify, reproduce, and route this item
    on Nov 3, 2026
  4. developing-today commented on Nov 3, 2026

    @developing-today
    Contributor

    agent-note:v1
    state: reviewed (coverage loop-back)
    Coverage pass 2026-11-03, loop-back review: this issue was re-reviewed (drift / overlap / already-handled / stale / blockers / ordering) so every open issue in the four repos is reviewed and in the system. Verdict: still live; in the system as task 7339 (triage, queued, priority 50) in repo-health-code-pilot. Labels audited and synced. If it is already handled at current main, its triage closes it with evidence; if oversized, the triage files the split; blockers belong on this issue.
    Found via: coverage loop-back 2026-11-03

  5. dezren39 commented on Nov 3, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · triaged

    Triage findings — 2026-11-03 (task 7339)

    The guard no longer lives in this repo

    • At code origin/main 6aeb038a0cd6: openchamberStart is gone from home/common/default.nix. The 2026-11-03 service cascade (comment at home/common/default.nix:930-947) moved the unit to services.openchamber from developing-today/openchamber's nix/modules; this repo's bin/openchamber-start.sh is only the attach shim and carries no single-instance guard.

    The defect survived the move, byte-for-byte

    • In openchamber origin/main, nix/modules/common.nix:180 (the writeShellApplication start wrapper, Linux single-instance guard):
      cmdline="$(tr '\\0' ' ' < "$proc/cmdline")" — inside a Nix indented string, where backslashes pass through literally.
    • Deployed proof (laptop, this triage): the live openchamber.service ExecStart is /nix/store/lqmdax8wgccwqd8avj322w9rfdyj6zxa-openchamber-start/bin/openchamber-start, and its line 37, byte-for-byte (grep | cat -A):
      cmdline="$(tr '\\0' ' ' < "$proc/cmdline")"$
    • Same failure mode as filed: GNU tr reads \\ as an escaped backslash, so the translate set is {backslash, 0}; NULs are never converted, bash $() strips them, argv concatenates, and the space-containing patterns (openchamber serve, --port 3000) can never match. The guard is still a no-op in production.

    Fix path (enqueued to the openchamber queue)

    • In openchamber nix/modules/common.nix: emit a single backslash in the source (tr '\0' ' ') so the generated wrapper contains tr '\0' ' ' — verified in the generated store file, not just the source.
    • Regression test per the acceptance criteria: build the start wrapper, assert the generated line byte-for-byte, and run the guard scan against a synthetic cmdline with real NUL separators asserting the fake leftover is selected.
    • Sibling audit (acceptance item 4) done in this triage: no other tr/escape defect in the generated start wrapper; the other \\ hits under openchamber nix/ are line continuations and \$@ in unrelated build contexts, and this repo no longer generates a wrapper to audit.
    • After the openchamber fix lands, this repo's flake input bump + laptop switch re-verifies acceptance item 3 (restart with a leftover → exactly one holder of 127.0.0.1:3000, the fix(openchamber): two OpenChamber web processes share laptop port 3000 — /api/version and /api/session-activity answers alternate between instances dezren39/darwin-nix#1117 scenario).
  6. dezren39 commented on Nov 3, 2026

    @dezren39
    MemberAuthor

    Fix task enqueued: task 8929 in queue repo-health-openchamber-pilot (fix: openchamber nix/modules/common.nix guard tr escaping + regression tests, tracking issue stays code#2562).

  7. added
    task/fixhas a fix task queued
    and removed on Nov 3, 2026
  8. 24 remaining items

  9. dezren39 commented on Nov 8, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · handed off

  10. added
    queue/claimedQueue worker lifecycle state
    and removed
    status/parkedDeliberately paused with a recorded resume condition
    queue/parkedQueue task is parked (waiting on CI, time, or an event)
    on Nov 8, 2026
  11. developing-today commented on Nov 8, 2026

    @developing-today
    Contributor

    🤖 Agent note · handed off

  12. developing-today commented on Nov 8, 2026

    @developing-today
    Contributor

    🤖 Agent note · handed off

  13. developing-today commented on Nov 8, 2026

    @developing-today
    Contributor

    🤖 Agent note · handed off

    • Agent: queue worker (repo-worker-code), lane code-y
    • Session / ID: task 12068 · lane Y shift 2026-11-08 04:04 CST
    • Found via: queue claim
    • Task: task 12068: handed to the opencode execution lane per queue lane assignment (assigned_lane=opencode)
    • Expectation: claimant launches the bound opencode session for task 12068; task parked 1200s so it returns to the queue if the claimant does not bind
    • Links: n/a
  14. added
    queue/parkedQueue task is parked (waiting on CI, time, or an event)
    status/parkedDeliberately paused with a recorded resume condition
    and removed
    queue/claimedQueue worker lifecycle state
    on Nov 8, 2026
  15. dezren39 commented on Nov 8, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · handed off

  16. developing-today commented on Nov 8, 2026

    @developing-today
    Contributor

    🤖 Agent note · handed off

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

Metadata

Metadata

Assignees

Labels

effort/sSmall: expected under 2 hours of workkind/bugSomething isn't working (prefixed form of the classic bug label)meta/enrichedIntake review done: acceptance criteria, links, and normalized labels addedpriority/highImportant and time-sensitivequeue/parkedQueue task is parked (waiting on CI, time, or an event)source/creatorFiled by the new-issue-creator jobstatus/parkedDeliberately paused with a recorded resume conditiontask/fixhas a fix task queuedtask/triageQueue packet kind: verify, reproduce, and route this itemwork/assignedQueue worker lifecycle state

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions