Skip to content

fix(cli): print the namespace-create receipt before a post-receipt failure - #1568

Merged
alpergundogdu merged 4 commits into
mainfrom
fix/1549-namespace-create-receipt
Aug 3, 2026
Merged

alpergundogdu merged 4 commits into
mainfrom
fix/1549-namespace-create-receipt

Conversation

@yigitdot

@yigitdot yigitdot commented Aug 1, 2026 •

Copy link
Copy Markdown
Contributor

publish namespace create was the last caller in publish.rs still discarding a recorded tx hash on a post-receipt failure. #1548 fixed this class in assign, revoke, and request-vetting; this brings namespace_create onto the same convention.

Problem

All three ?s in the NamespaceCreated decode fired after createNamespace had confirmed on-chain, short-circuiting before write_namespace_outcome. So the receipt never printed (on --json, stdout was empty), outcome.tx was dropped with the struct even though send_for_receipt records the hash before awaiting the receipt precisely so this case can report it, and the first message told the operator to "check the tx on a block explorer" while withholding the tx. The namespace existed and was owned by the signer, but its id was unrecoverable from the CLI — and namespaceCount had already moved against maxNamespacesPerPublisher, so a blind retry silently burned quota.

Change

Mirrors request_vetting end to end:

  • decode_created_namespace(&receipt) -> anyhow::Result<u64> — the log lookup + decode, extracted so the caller can hold the Err.
  • Print, then propagate. The outcome is written with tx: Some / namespace_id: None, then the stashed error goes through the shared propagate helper, which already keeps a chain error ahead of a broken-pipe write error.
  • The send arm too, matching the sibling: an Err that left a hash behind means the transaction was broadcast and only its receipt was unreadable, so it reports in_flight with the hash rather than implying nothing happened.
  • namespace_failure_context(landed, in_flight) — the parallel of vetting_failure_context. It warns about the burnt quota only when something actually reached the chain; a rejected send (the modal case, since NamespaceCapReached is createNamespace's only revert and so surfaces from the pre-flight gas estimate) minted nothing and has no hash to cite.
  • status, as the issue asks. NamespaceOutcome gains in_flight/dry_run and renders status through the shared single_tx_status (dry_run / unknown / created / failed). created with a null namespace_id is now distinguishable from failed, where both previously rendered submitted=false-shaped output.

The text receipt moves to the sibling shape (status=created tx=…, with namespace_id on its own line like ready_at). That is not cosmetic: the old _ => "submitted=false dry_run=true" arm was only ever correct because a failed send could not reach the writer — now that it can, it would have claimed a dry run for a transaction that was broadcast. JSON keys submitted and namespace_id keep their names and shapes.

Review round

A multi-agent review of the branch found one defect in the fix itself, plus adjacent gaps small enough to close here.

The recovery guidance did not work. The first pass at the landed note told the operator to recover the lost id via ownerOf, which is mapping(uint256 namespaceId => address) — id → owner. It needs the very id that was lost, and there is no reverse index: namespaceCount returns a count and _nextNamespaceId is internal, so a scan cannot even be bounded. It now points at an owner-filtered log query: createNamespace emits NamespaceCreated unconditionally and indexes both parameters, so eth_getLogs on the signer returns the id in a topic with no data decode. That holds for all three decode failure modes, including a receipt that came back without the log — the log is still on-chain, it just was not in what the RPC returned. Which is why naming the event here does not re-create the contradiction it was removed for: it points at a log query, not at that receipt's log.

Comment claims that were wrong. The namespace_id doc gave failed one cause (rejected send) when send_for_receipt also folds a confirmed revert into it. And "match by signature first, then decode, so an ABI drift surfaces as a decode error" was backwards for the likely drift — a renamed event or changed parameter type changes the signature hash itself, so find returns None and the operator gets the "missing log" error the comment claimed to avoid. Only an indexed change reaches the decode arm; that arm's message now names the other cause too.

Two write-path gaps in the same class as the bug, fixed at all four publish.rs sites so the commands stay symmetric:

  • drop(out) discarded the final flush error. Stdout is a LineWriter, so a partial write can buffer the tail and fail unobservably at drop — a truncated receipt reported as a clean one.
  • propagate dropped everything the command had learned whenever the write failed, including on full success: a decoded id and its hash replaced by "failed to write namespace-create output". Reachable with decdn publish namespace create | head -1. Those facts now ride in the error context, which goes to stderr — a different descriptor, still writable when stdout is a closed pipe or a full disk.

revoke_failure_context — revoke's in-flight guidance was a string literal inside its async fn, asserted by nothing, while namespace and vetting had both extracted theirs. Extracted and tested.

Deliberately not fixed here, now tracked: #1550 (a confirmed revert's hash never reaches the JSON receipt — changing it means changing send_for_receipt's contract and ~13 call sites), #1577 (a lost send response is indistinguishable from a rejected send, so a broadcast tx can print status=failed with no warning), #1578 (the flat-bools outcome structs can represent contradictory receipts; must convert all three single-tx types at once).

Testing

namespace_output_distinguishes_created_unknown_and_failed is the acceptance test, written first and confirmed failing on main for the right reason — the writer emitted submitted=false dry_run=true with no tx hash at all. namespace_failure_context_only_claims_a_namespace_when_one_exists pins the three-way guidance split, including that the note never cites ownerOf.

The review round added coverage for decode_created_namespace and its decode_vetting_deadline sibling, whose error arms — the failures that trigger this entire receipt behavior — had none. Extracting them over &TransactionReceipt is what made them constructible, so a receipt_with_logs fixture now drives missing-log, topic0-matched-but-undecodable, and id-exceeds-u64. The ABI-drift test was verified to fail for the right reason by collapsing the ordering into find_map(|l| l.log_decode().ok()).

Both e2e receipt parsers now gate on status == "created" rather than submitted, matching parse_ready_at. submitted is true for an in-flight broadcast too, so it could not defend the field this PR adds.

cargo fmt -- --check                                    ok
cargo clippy --workspace --all-targets -- -D warnings   ok (clean)
cargo nextest run -p decdn-cli --no-fail-fast           408 tests run: 408 passed, 0 skipped
cargo nextest run -p decdn-e2e --features anvil-e2e -E 'test(namespace)' --test-threads 1
                                                        4 passed (one fails under default
                                                        parallelism on the DeployProtocol
                                                        stall, #1384 — unrelated)

Closes #1549

…ilure

`publish namespace create` decoded the `NamespaceCreated` log with `?`, so
every failure after `createNamespace` had already confirmed on-chain
short-circuited before the receipt was written. The namespace existed and was
owned by the signer, but its id — and the tx hash `send_for_receipt` records
before awaiting the receipt precisely for this case — went out with the
dropped struct. On `--json` stdout was empty, while the error told the
operator to check a transaction it refused to name. `namespaceCount` had
already moved against `maxNamespacesPerPublisher`, so a blind retry silently
burned quota.

Mirror `request_vetting` (#1548), which fixed the same defect class in
`assign`, `revoke`, and `request-vetting`: extract the lookup + decode into
`decode_created_namespace`, stash its `Err`, print the outcome with `tx` set
and `namespace_id` absent, then propagate through the shared `propagate`
helper. The send arm gets the same treatment, so a broadcast whose receipt
could not be read reports its hash instead of vanishing.

`NamespaceOutcome` gains `in_flight`/`dry_run` and renders a `status` via the
shared `single_tx_status`, for parity with the sibling receipts: `created`
with a null `namespace_id` is now distinguishable from `failed`, where both
previously rendered `submitted=false`-shaped output — and a rejected send no
longer prints `dry_run=true`. `submitted` and `namespace_id` keep their names
and shapes.

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

coderabbitai Bot commented Aug 1, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

@yigitdot, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 46 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Free

Run ID: 16e65cb9-f7ad-4737-a2f3-fbe395988142

📥 Commits

Reviewing files that changed from the base of the PR and between b2a9651 and 3f0794b.

📒 Files selected for processing (3)
  • crates/cli/src/commands/publish.rs
  • crates/e2e/tests/cli_publish.rs
  • crates/e2e/tests/g_origin_01_publish.rs

Note

🎁 Summarized by CodeRabbit Free

Your organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Pro by visiting https://app.coderabbit.ai/login.

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Aug 1, 2026 •

Copy link
Copy Markdown

Coverage report

Total: 80.19% (was 80.15%, ▲ +0.04%) — 56540/70507 lines

File Coverage Lines Δ
crates/cli/src/commands/publish.rs 72.37% 854/1180 ▲ +5.63%
History
Commit Total Δ vs base
8a49387 80.08% ▼ 0.02%
713a87a 80.10% ● 0.00%
3f0794b (HEAD) 80.19% ▲ +0.04%

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Not ready to approve

One new failure-context message can contradict a concrete decode failure mode (missing NamespaceCreated log) and should be reworded to avoid asserting an impossible recovery path.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

This review doesn't count toward merge requirements. Sign up for the private preview to control whether Copilot approvals count.

Pull request overview

This PR updates publish namespace create to preserve and print the recorded transaction hash (and a clear status) even when failures occur after the transaction has already been broadcast or confirmed, matching the conventions established for sibling publish commands.

Changes:

  • Extracts NamespaceCreated log decoding into decode_created_namespace so decode errors can be deferred until after writing the receipt.
  • Adds status/in_flight/dry_run modeling to NamespaceOutcome, and updates text + JSON output to reliably surface created/unknown/failed/dry_run.
  • Adds focused tests covering created-with-unknown-id, in-flight, failed, and failure-context guidance.
File summaries
File Description
crates/cli/src/commands/publish.rs Defers post-receipt errors until after output is written, adds status semantics for namespace-create receipts, and expands unit tests for the new output contract.
Review details
  • Files reviewed: 1/1 changed files
  • Comments generated: 2
  • Review effort level: Lite

We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.

Comment thread crates/cli/src/commands/publish.rs Resolved
Comment on lines +304 to +308
Some(
"the namespace exists and is owned by the signer — recover its id from the \
NamespaceCreated log of the tx above rather than re-running, which mints a second \
namespace",
)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed — a missing NamespaceCreated log is the first of decode_created_namespace's three failure modes, so on that path the note pointed at a log the error above it had just said was absent. 713a87a drops the log from the guidance: it now reads "recover its id from the tx above (its logs, or ownerOf on the registry)", which stays true for the missing-log, ABI-drift, and overflow cases alike. The test now asserts the string does not mention NamespaceCreated, with a comment saying why, so it can't drift back.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-checked this against the contract and you were right to push on the wording — but the replacement I first shipped was also wrong. ownerOf is mapping(uint256 namespaceId => address) (PublisherRegistry.sol:54), i.e. id → owner: it needs the id that was just lost, and there is no reverse index (namespaceCount returns a count, _nextNamespaceId is internal), so it cannot bound a scan either.

Fixed properly in ee1073e: the note now points at an owner-filtered log query. createNamespace emits NamespaceCreated unconditionally and indexes both parameters (line 79), so eth_getLogs filtered on the signer returns the id in a topic without decoding any data — true for all three of decode_created_namespace's failure modes. That includes the missing-log case you raised, because the log is still on-chain there; it just was not in what the RPC put in the receipt. So this names the event without reintroducing the contradiction: it points at a log query, not at that receipt's log.

The `landed` failure context told the operator to recover the namespace id
from the NamespaceCreated log of the recorded tx. A *missing* NamespaceCreated
log is one of the decode failures that context is attached to, so the guidance
could contradict the error it wraps. Point at the tx and `ownerOf` instead.

Also corrects the `namespace_id` doc comment, which listed three `None` cases
and omitted the in-flight one — there are four, one per `status` value.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
yigitdot and others added 2 commits August 2, 2026 03:18
…orks

Review of #1568 found the guidance added in 713a87a unusable. It tells the
operator to recover a lost namespace id via `ownerOf`, but PublisherRegistry
declares `mapping(uint256 namespaceId => address) public ownerOf` — id → owner.
It needs the id that was just lost, and there is no reverse index:
`namespaceCount` returns a count and `_nextNamespaceId` is internal, so an
operator cannot even bound a scan. The note fired on exactly the path this PR
exists to make recoverable.

`createNamespace` emits `NamespaceCreated` unconditionally and indexes both
parameters, so an owner-filtered `eth_getLogs` returns the id in a topic with no
data decode. That works for every decode failure, including a receipt that came
back without the log — the log is still on-chain, it just was not in what the RPC
returned. Which is also why naming the event here does not reintroduce the
contradiction Copilot flagged: it points at a log query, not at that receipt.

Also from the review:

- The `namespace_id` doc listed the send-rejected cause of `failed` but not the
  confirmed revert, which `send_for_receipt` folds into the same state.
- "Match by signature first, then decode, so an ABI drift surfaces as a decode
  error" was backwards for the likely drift: a renamed event or changed parameter
  type changes the signature hash itself, so `find` returns `None` and the
  operator gets the missing-log error the comment claimed to avoid. Only an
  `indexed` change reaches the decode arm. That arm now says so too.
- `Ok(0)` is a dead sentinel whose 0 is the registry's reserved no-namespace id;
  say that it is never read.

Tests: `decode_created_namespace` and its `decode_vetting_deadline` sibling had
no coverage of their error arms — the failures that trigger this whole receipt
behavior. Extracting them over `&TransactionReceipt` made them constructible, so
add a `receipt_with_logs` fixture and pin all three: missing log, topic0-matched
but undecodable, and an id too large for u64. Verified the ABI-drift test fails
for the right reason by collapsing the ordering into `find_map(log_decode().ok())`.

Two write-path gaps in the same class, applied to all four commands so they stay
symmetric:

- `drop(out)` discarded the final flush error. `Stdout` is a `LineWriter`, so a
  partial write can buffer the tail and fail unobservably at drop — a truncated
  receipt reported as a clean one.
- `propagate` dropped everything the command had learned when the write failed,
  including on full success: a decoded id and its hash, replaced by "failed to
  write namespace-create output". Reachable with `| head -1`. The facts now ride
  in the error context, which goes to stderr — a different descriptor, still
  writable when stdout is a closed pipe.

While there, `revoke`'s in-flight guidance was a string literal inside its async
fn, untested; extract `revoke_failure_context` to match its two siblings.

Refs #1568, #1577, #1578

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
`parse_ready_at` already gates on `status == "vetting_requested"`; the two
namespace parsers still checked `submitted`, which cannot separate a confirmed
create from a broadcast whose receipt could not be read — both carry
`submitted: true`, and only the first has an id to read. That left the `status`
field #1568 added with one line of defense, a unit test.

Verified against anvil: the four namespace journeys pass serialized. (One failed
under the default parallelism on an unrelated DeployProtocol stall, #1384.)

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@github-actions

github-actions Bot commented Aug 2, 2026

Copy link
Copy Markdown

Gas snapshot

No gas changes vs base.

@github-actions

github-actions Bot commented Aug 2, 2026

Copy link
Copy Markdown

Contracts coverage

Line coverage: 89.80% (2597/2892 lines)
▲ +0.00pp vs base (89.80% → 89.80%)
Run: 30724988943

@alpergundogdu
alpergundogdu merged commit 92a241b into main Aug 3, 2026
25 checks passed
@alpergundogdu
alpergundogdu deleted the fix/1549-namespace-create-receipt branch August 3, 2026 11:44
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.

cli: post-receipt failures in publish namespace create discard a recorded tx hash and the new namespace id

3 participants