Skip to content

fix(cli): two bugs from ADR-005 Phase 1b live smoke - #196

Merged
samxu01 merged 1 commit into
mainfrom
fix/cli-phase-1b-smoke-fixes
Apr 15, 2026
Merged

samxu01 merged 1 commit into
mainfrom
fix/cli-phase-1b-smoke-fixes

Conversation

@lilyshen0722

Copy link
Copy Markdown
Contributor

Summary

Follow-up to #195. Smoke-tested Phase 1b against `api-dev.commonly.me` (pod `adr-005-smoke`) — memory round-trip works end-to-end: seeded `long_term` on CAP `/memory`, posted `@smoke-claude what fruit should I avoid?`, claude replied "You should avoid kiwi fruit due to your allergy." in one sentence, exactly matching the seeded memory. Attach → run → spawn → post → ack all validated.

Two bugs surfaced on the way:

1. `performRun` never created its per-agent cwd

`join(tmpdir(), 'commonly-agents', )` was passed as `ctx.cwd` without ever being `mkdir`-ed. Node's `child_process.spawn` rejects with `spawn claude ENOENT` when cwd doesn't exist — same shape as binary-missing — so the first live claude run failed with a misleading ENOENT and kept re-delivering (no ack on spawn failure, per ADR-005). New test asserts the dir is created at `performRun` start even when no chat event arrives, so a heartbeat-only run can't break on its first real spawn.

2. Program-level `--instance` shadowed subcommand option

Commander v12 routed `commonly login --instance ` to an unset program-level flag, so the URL was silently ignored and login fell back to `api.commonly.me`. Removed the duplicate; every subcommand already owns its own `--instance`.

Not in this PR (filed as follow-ups)

  • Self-mention loop (kernel-side): `agentMentionService.enqueueMentions` fires `chat.mention` events for messages authored by the mentioned agent itself. The stub adapter echoes the prompt → its own post re-triggers → infinite loop in the pod. Affects every driver (openclaw, webhook, local-cli), not just this one. Should be fixed at the backend — skip enqueue when `userId === agentUser._id`. Will file as a separate backend PR.
  • config.js `getToken(url)` asymmetry: `resolveInstanceUrl` accepts a URL, but `getToken` treats its arg as a config key. Worked around by using `--key` on login; not blocking, separate cleanup.

Test plan

  • `cd cli && npm test` — 53/53 passing (52 + 1 new cwd-creation test)
  • Live smoke on `api-dev.commonly.me` — memory round-trip confirmed (one-sentence kiwi-allergy reply); smoke agents + pod cleaned up
  • `npm run lint` — 0 new errors in `cli/`

🤖 Generated with Claude Code

Surfaced while smoke-testing PR #195 against api-dev.commonly.me.

1. performRun never mkdir-ed its per-agent cwd
   `join(tmpdir(), 'commonly-agents', <agent>)` was passed to
   `adapter.spawn` as `ctx.cwd`, but the directory was never created.
   Node's child_process.spawn rejects with "spawn <bin> ENOENT" when
   cwd does not exist — identical to the binary-missing diagnostic —
   so the first live claude run failed with a misleading ENOENT and
   looped on re-delivery (no ack on spawn failure, per ADR-005).

   Now ensures agentCwd exists at `performRun` start, once per run.
   Test: run-loop.test.mjs — assert the dir is materialised even when
   no chat events arrive, so a heartbeat-only run can't break on first
   real spawn.

2. Program-level `--instance` shadowed subcommand option
   commander v12 routed `commonly login --instance <url>` to an unset
   program-level flag, so the URL was silently ignored and login fell
   back to the default. Removed the duplicate; every subcommand already
   owns its own `--instance`.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@samxu01
samxu01 merged commit 423c929 into main Apr 15, 2026
8 checks passed
lilyshen0722 added a commit that referenced this pull request Apr 16, 2026
…1 as shipped

Sweep of documentation catching up with today's merges:

- ADR-003: status line now includes Phase 3 §Deliverable 3 shipped
  (2026-04-15). Added revision note pointing at the cross-check test
  file and its seven assertions. Deliverable 3 itself marked shipped
  inline.

- ADR-005: status bumped from Draft to Accepted. Revision history
  records Phase 1a (PR #194), Phase 1b (PR #195), and the three
  follow-up fixes that landed during/after live smoke (cwd guard +
  --instance shadowing #196, self-mention loop #201, URL/key
  asymmetry #202). Phase 1a + 1b headers marked shipped inline.

- ADR-006: status bumped from Draft to Accepted. Revision history
  names Phase 1 (PR #197), the Cloudflare UA follow-up
  (5db9376), and the live-smoke result on api-dev. Open Question
  #1 (ephemeral GC) updated with current TODO location.

- CLAUDE.md Agent Runtime Quick Rules: five new prescriptive rules
  — self-mention guard, `commonly agent init` self-serve path,
  Python SDK User-Agent requirement, CLI --instance symmetry.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
lilyshen0722 added a commit that referenced this pull request Apr 16, 2026
…ipped (#203)

* fix(cli): resolve --instance symmetrically (saved key OR URL)

Historically `resolveInstanceUrl` treated --instance as a URL and
`getToken` treated it as a config key. So:

  commonly whoami --instance https://api-dev.commonly.me
  → URL resolved correctly, but token lookup returned null (no auth)

  commonly whoami --instance dev
  → token found, but "dev" was returned literally as the URL (ENOTFOUND)

Neither form worked end-to-end. Filed as a follow-up during ADR-005
Phase 1b smoke.

Fix: funnel both functions through a new `resolveInstance(identifier)`
helper that probes URL-shaped inputs (http[s]://) against saved URLs
first (case-insensitive, trailing-slash tolerant), then falls back to
exact-key lookup, then to an unknown-URL bootstrap, then to null. Both
forms of --instance now work for both URL and token resolution.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>

* docs(adr): mark ADR-003 Phase 3, ADR-005 Phases 1a+1b, ADR-006 Phase 1 as shipped

Sweep of documentation catching up with today's merges:

- ADR-003: status line now includes Phase 3 §Deliverable 3 shipped
  (2026-04-15). Added revision note pointing at the cross-check test
  file and its seven assertions. Deliverable 3 itself marked shipped
  inline.

- ADR-005: status bumped from Draft to Accepted. Revision history
  records Phase 1a (PR #194), Phase 1b (PR #195), and the three
  follow-up fixes that landed during/after live smoke (cwd guard +
  --instance shadowing #196, self-mention loop #201, URL/key
  asymmetry #202). Phase 1a + 1b headers marked shipped inline.

- ADR-006: status bumped from Draft to Accepted. Revision history
  names Phase 1 (PR #197), the Cloudflare UA follow-up
  (5db9376), and the live-smoke result on api-dev. Open Question
  #1 (ephemeral GC) updated with current TODO location.

- CLAUDE.md Agent Runtime Quick Rules: five new prescriptive rules
  — self-mention guard, `commonly agent init` self-serve path,
  Python SDK User-Agent requirement, CLI --instance symmetry.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>

---------

Co-authored-by: Claude Opus 4.6 (1M context) <[email protected]>
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.

2 participants