Skip to content

fix(cmd_connect): reject unknown flags instead of treating as positional name - #534

Merged
joelteply merged 2 commits into
canaryfrom
fix/cmd-connect-reject-unknown-flags
May 6, 2026
Merged

joelteply merged 2 commits into
canaryfrom
fix/cmd-connect-reject-unknown-flags

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

Summary

cmd_connect's arg loop had a single *) positional+=("$1") arm that silently accepted any unrecognized --<flag> as a positional. The accepted positional became target (line 1733: local name="${target:-}"), then host-mode name, which got persisted to config.json name field.

Observed in the wild today (2026-05-06): continuum-8e97 on Windows ran airc join --background (a documented-as-not-a-flag arg) after airc teardown and got:

Hosting as '--background' (reminder: 300s)

config.json then had "name": "--background", and identity stayed corrupted across airc teardown + airc join cycles. Manual JSON edit was the only recovery — exactly the failure mode #511/#521 fixed for --attach specifically.

Fix

Add an explicit -*) arm in cmd_connect's flag loop (lib/airc_bash/cmd_connect.sh:574) that rejects unknown flags loudly with return 2 and a stderr message. Inline invites, gist ids, and humanhash mnemonics never start with -, so the rejector cannot eat a legitimate positional. The existing PR #521 belt for encoding-corrupted --attach is preserved.

Tests

Adds scenario_join_rejects_unknown_flag to test/integration.sh covering:

  • Non-zero exit code on airc join --background --no-room --no-gist
  • stderr says "unknown flag"
  • stdout never says "Hosting as '--background'"
  • config.json is not poisoned

Local run on Windows WSL2 (Ubuntu, canary 2357f7b base):

$ bash test/integration.sh join_rejects_unknown_flag
─ join_rejects_unknown_flag: cmd_connect rejects --unknown-flag instead of accepting as positional ─
  ✓ unknown flag rejected with non-zero exit (rc=2)
  ✓ stderr names the rejection
  ✓ host setup never started with the bad name
  ✓ config.json was not written (rejected before init)
4 passed, 0 failed

Adjacent regressions also re-checked clean:

$ bash test/integration.sh attach_transport_survives_launcher_hup
2 passed, 0 failed

$ bash test/integration.sh attach_spawn_strips_attach_flag
2 passed, 0 failed

Related

🤖 Generated with Claude Code

Pre-fix `cmd_connect`'s arg loop had a single `*) positional+=("$1")` arm
that silently accepted any unrecognized `--<flag>` as a positional. That
positional then became `target` in the parser tail, which became host-mode
`name` (line 1733: `local name="${target:-}"`), which got persisted to
config.json `name` field (line 1740: `set_config_val name "$name"`).

Observed in the wild: continuum-8e97 on Windows ran `airc join --background`
and got "Hosting as '--background'", with config.json `name` field
persisted as `"--background"`. Identity stayed corrupted across `airc
teardown` + `airc join` cycles; only manual JSON edit recovered it.

Same shape as the original `--attach` leak (#511/#521). The PR #521 belt
at lines 584-594 strips `--attach` specifically from positional[]. This
generalizes the defense to ALL unrecognized flags.

Inline invites, gist ids, and humanhash mnemonics never start with `-`,
so the rejector cannot eat a legitimate positional. The known `--attach`
recovery belt is preserved (encoding-corrupted variants still recover).

Adds scenario_join_rejects_unknown_flag to test/integration.sh covering
exit code, stderr message, host-setup-not-started, and config-not-written
assertions. Test runs on the same path as #533's HUP regression test.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Copilot AI review requested due to automatic review settings May 6, 2026 16:56
@joelteply

Copy link
Copy Markdown
Contributor Author

Codex review found and fixed one first-run/Codex-specific masking bug before merge.

Initial #534 behavior was correct in plain shell, but in Codex the join dispatch routed through cmd_codex_start first. The detached child rejected --background, then the foreground parent continued into status/inbox and surfaced Not initialized instead of the real unknown flag. That is bad first-user UX and exactly the class we do not want.

I pushed 0c8ce55 onto this PR:

Local validation after the amendment:

  • bash -n airc lib/airc_bash/cmd_connect.sh test/integration.sh
  • ./test/integration.sh join_rejects_unknown_flag -> 4 passed
  • ./test/integration.sh attach_spawn_strips_attach_flag -> 2 passed
  • ./test/integration.sh attach_transport_survives_launcher_hup -> skipped/pass on macOS because no setsid

This is now mergeable once CI reruns green.

@joelteply
joelteply merged commit 13b530a into canary May 6, 2026
6 checks passed
@joelteply
joelteply deleted the fix/cmd-connect-reject-unknown-flags branch May 6, 2026 17:02
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