Skip to content

fix(agent): COD-549 preserve worker IDs after readiness failures - #709

Merged
Ark0N merged 3 commits into
Ark0N:masterfrom
aakhter:pr/COD-549-worker-readiness
Oct 27, 2026
Merged

Ark0N merged 3 commits into
Ark0N:masterfrom
aakhter:pr/COD-549-worker-readiness

Conversation

@aakhter

@aakhter aakhter commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

When agent spawn creates a worker successfully but its readiness request throws, the command exits without returning the created session ID. Callers then cannot reliably inspect or clean up that worker.

Catch readiness transport errors, preserve the session ID and error in human or JSON output, and return an error exit status. Empty exception messages receive a fallback diagnostic so they cannot turn a failed wait into a successful exit. Existing creation and readiness request counts are preserved.

Validation:

  • 85 CLI tests passed, including human/JSON ID preservation and empty Error/string exceptions.
  • Typecheck, lint, formatting, lockfile and diff checks passed.
  • Independent review checked output, exit status and worker lifecycle behavior.

@Ark0N

Ark0N commented Oct 25, 2026

Copy link
Copy Markdown
Owner

Thanks @aakhter! This makes codeman agent spawn keep the new worker's session id when the readiness request throws, so a caller can still read or delete the worker instead of losing track of it. I checked it against master: the four new tests fail there and pass with your change, and typecheck, lint, formatting and the cli-agent/mcp-server tests are green locally.

One non-blocking note on the empty-message fallback (src/cli-agent.ts:576): the empty message you guard against is a real case. On Node 22, a connection refused on a host that resolves to both ::1 and 127.0.0.1 rejects with an AggregateError whose message is '' but whose code is ECONNREFUSED. With the current fallback the user sees readiness check failed: Readiness request failed, which drops that code. Something like getErrorMessage(error) || ((error as { code?: unknown })?.code ? String((error as { code?: unknown }).code) : 'request failed without a message') would keep it, and the expected string in the test at test/cli-agent.test.ts:584 would change to match. Push it if you want it in; it is not required for merge.

This is good to merge once the CI test job finishes.

Node 22 rejects a refused connection to a host that resolves to both ::1
and 127.0.0.1 with an AggregateError whose message is empty and whose code
is ECONNREFUSED. The readiness fallback dropped that code, and the agent
CLI's top-level error line and the MCP server's "Cannot reach Codeman"
error printed nothing at all for it.

Add describeRequestError() (message, else code, else a generic line) and
use it at all three sites.
@aakhter

aakhter commented Oct 25, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @Ark0N, took the note in 77ce481.

  • New describeRequestError() in src/cli-agent.ts: the message, else the error's code, else request failed without a message. The readiness catch uses it, so the empty AggregateError case now reports readiness check failed: ECONNREFUSED.
  • Same empty-message gap in two neighbours, fixed the same way: the agent CLI's top-level error line (run(), which printed a bare glyph for this case) and the MCP server's Cannot reach Codeman at <url>: . error.
  • Tests: the empty-message expectation now reads request failed without a message; new tests throw an AggregateError with an empty message and code ECONNREFUSED through agent spawn and through the MCP list_sessions tool and check that the code appears, plus a unit test for the helper. Each fails with its site reverted.

@Ark0N

Ark0N commented Oct 25, 2026

Copy link
Copy Markdown
Owner

Thanks again @aakhter. With this, codeman agent spawn keeps the new worker's session id and exits 1 when the readiness request throws, so a caller can still read or delete the worker. 77ce481 takes the empty-message note and carries it to the agent CLI's top-level error line and the MCP "Cannot reach Codeman" error as well; the new tests fail when the readiness catch or the MCP site is reverted, and CI is green on the head.

At merge time I will extend the changeset (.changeset/tidy-workers-return.md:5) by one clause so the release notes also mention that codeman agent and codeman mcp now name the error code (such as ECONNREFUSED) when a request fails with an empty message. Nothing else is needed from you. Merging.

@Ark0N
Ark0N merged commit bd3320f into Ark0N:master Oct 27, 2026
2 checks passed
Ark0N pushed a commit that referenced this pull request Oct 27, 2026
Replaces the six contributor changesets (#694, #707, #708, #709, #718,
#713) with one consolidated minor changeset covering all 14 PRs, with the
Thanks section first and the release-review fixes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Ark0N

Ark0N commented Oct 27, 2026

Copy link
Copy Markdown
Owner

Merged in 1.46.0 (https://github.com/Ark0N/Codeman/releases/tag/codeman%401.46.0). Thank you; carrying the empty-message fallback through to the agent CLI's error line and the MCP error was a good extension. The release notes mention that codeman agent and codeman mcp now name the error code (such as ECONNREFUSED) when a request fails with an empty message, as promised.

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