Skip to content

Bare opaque ids without a digit are rejected, and bad ids surface as raw SDK errors #65

Description

@lmjabreu

Two small things I ran into while working on #64, both reproduced on 3.4.0 (aa8e93a). Neither is a regression from that PR.

Bare opaque ids are rejected when they contain no digit

tdc conversation done CDMDzXhBNCgyQZjkDnqwG --dry-run
# Error: INVALID_REF
# Invalid conversation reference: CDMDzXhBNCgyQZjkDnqwG. Use an id, id:<id>, or a Comms URL.

tdc conversation done id:CDMDzXhBNCgyQZjkDnqwG --dry-run
# [dry-run] Would archive conversation: ...

Expected: the bare form works, like tdc thread view Cf9TR6CPC2dKQL5fB2EoL does.

It's not conversation-specific; the three resolvers in refs.ts are identical. parseRef only treats a bare token as an id when looksLikeRawId passes (refs.ts:68, 151), and that requires at least one digit. The fallback looksLikeOpaqueCommsId (refs.ts:75) only accepts a Cb prefix. This id has no digit and starts with CD, so it's parsed as a name. Swap any letter for a digit, or the prefix for Cb, and the same command reaches the API. Base58 has 9 digits in 58 characters, so a 21-character id comes out digit-free about 3% of the time ((49/58)^21), roughly one id in thirty.

A malformed or missing id surfaces as a raw SDK error

tdc thread view id:nope
# CommsRequestError: Request failed with status 409
#     at fetchWithRetry (.../comms-sdk/dist/esm/transport/fetch-with-retry.js:28:23)
#     ...

tdc thread view Cf9TR6CPC2dKQL5fB2EoL --comment id:nope     # same
tdc thread view id:nope --json
# {"error":{"code":"INTERNAL_ERROR","message":"Request failed with status 409"}}

Expected: a CliError (NOT_FOUND or INVALID_REF) with a hint, per AGENTS.md.

The 409 is the API's "id must decode to 16 bytes" (error_code 217); a well-formed id that doesn't exist gets a 404 and prints the same stack trace. The catch in api.ts maps 403 (both flavours) and 401 and rethrows everything else (api.ts:192-220), so 404 and 409 fall through to the generic branch in index.ts:230.

Happy to open a PR for either if useful.

Activity

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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions