Skip to content

fix(web): route refused writes to their fix, keep edits on retry, calibrate cost previews - #91

Merged
PastaPastaPasta merged 1 commit into
masterfrom
fix/web-write-refusals
Sep 27, 2026
Merged

PastaPastaPasta merged 1 commit into
masterfrom
fix/web-write-refusals

Conversation

@PastaPastaPasta

Copy link
Copy Markdown
Owner

What this fixes

This PR fixes web write-flow defects from the QA ledger: D-007, D-008, D-011, D-012, D-042, D-045, D-048, D-049.

D-007: a refused write was shown as "Sent, not yet visible"

Cause. When Platform refuses a transition at the broadcast check (CheckTx), evo-sdk 4.2.0-beta.4 throws a WasmSdkError of kind Generic, with code: -1 and the message Failed to broadcast: Protocol error: <Drive's #[error] text>. I captured this live on moutai. consensusCodeOf needed a numeric code, so every such refusal fell through to the "unclassified → poll → Unconfirmed" path.

Fix.

  • asConsensusRefusal now decodes Drive's refusal texts (rs-dpp 4.2.0-beta.4 #[error] strings) into codes and figures: remaining, balance and required.

    • Covered: 40218 (key budget exceeded), 20015, 20016, 40219, 20006 and 40208 (key spent, expired or disabled), 40210 and 30000 (balance), 40105, 40106, 40120, 40127, 40128, 10417, 10421 and 20014.
    • Nonce refusals (40204) are deliberately not matched by text. A rebroadcast of bytes that did land gets the same answer, so it is settled by reading the chain.
    • The budget gate's own local refusals (grpc 8 "rate limited" and 14) stay unclassified.
  • ConsensusRefusal gains isBalance, unpaid, figures, and charged/feeCharged. A refusal at broadcast charges nothing and is not added to the ledger. A verdict from a block is charged, unless Drive leaves it unpaid.

  • writeFailure in lib/view/write-errors.ts maps each refusal to its fix:

    • a key budget short → a Top up key / Renew key sheet showing the shortfall;
    • an expired, disabled, missing or wrong-level key → a Renew sheet with the matching reason;
    • a short balance → a Top up sheet;
    • anything else → a plain sentence.

    "Sent, not yet visible" is only ever said for a write that really may still land.

  • useWriteGuard().failed(e) opens that sheet and refreshes the balance and limits. Every composer and ConfirmDialog uses it.

  • WriterBusyError and the new BusyWriteError get plain sentences. BusyWriteError covers the budget gate turning the broadcast away: "may not have been sent".

D-008: a retry after an edit lost the edit

  • The pending-transition cache now stores a content hash of the intended document.
    • For a private repo it hashes the plaintext before sealing (contentKey), because sealing is randomised.
  • When a retry's content differs from the cached attempt:
    • if the old attempt is on Platform, throw SupersededWriteError. A tombstone makes every later retry of that intent answer the same way and sign nothing;
    • if its nonce is still free, sign the edit with the same nonce, so at most one of the two can land;
    • if the nonce was taken, the old attempt must be definitely absent (after waiting a block) before signing afresh.
  • The superseded ids are kept with the cache entry across reloads and re-signs, and are settled before any "lost → re-sign" decision.
  • createNumbered remembers the number the last attempt signed (24h). A retry therefore finishes that number instead of allocating the next and posting a second issue or PR.
  • The composers treat Superseded as done: the draft is cleared, the intent renewed, and the page reloads.

D-011: previews under-estimated

  • lib/sdk/cost.ts is recalibrated from about 60 live moutai measurements (listed in the header). It adds first-write surcharges:
    • the first issue in a repo or by an author;
    • the first comment or event on a thread;
    • the first star on a repo;
    • the first review on a PR;
    • an identity's first write to a contract;
    • and so on.
  • An unknown surcharge counts as a first write, so every preview is an upper bound. HEADROOM is 1.06.
  • The first-write facts are read lazily, with one limit: 1 proved read or count per subtree (lib/repo/first-write.ts), only once the viewer turns to a write: typing, pointing at Star or Follow, or a confirm opening.
  • Unit tests assert, against every measured charge, that each preview is ≥ the actual and ≤ +30%, both with and without the first-write facts.
  • Unstar and unfollow show their refund.
  • The renew copy uses a measured figure (renew about 27.3M; the first key registration 44–47M) instead of "~0.0005 DASH". The controller's key:renew estimate now uses KEY_RENEW_CREDITS.

D-012: the pre-check had no headroom

  • Drive accepts a write only when the key budget and the balance cover what it estimates the write may take, which is well above what it then charges. For an issue that is about 99.6M from the budget and about 137M from the balance, against a charge of about 59M.
  • I measured these requirements from Drive's own refusals and they are now CostPreview.admit. affordability() compares against admit, so the case QA saw (0.0009 DASH left, 100.2M required) is stopped before signing.
  • sumPreviews admits each write after the earlier ones have spent theirs.

D-042: key expiry

  • The funds state re-evaluates by timer at the key's 7-day mark and at expiry, so the pill turns red without a reload.
  • A typed KeyUnusableError (expired | disabled | missing | level) replaces the raw "no usable AUTHENTICATION key" error and opens Renew with the right reason.

D-048: Follow

Follow now shows its price, runs the write guard, and confirms in ConfirmDialog. Unfollow confirms its refund.

D-049: body limits

Issue, comment, PR and review bodies are checked against the contract's schemaDefs limits (5,120 bytes and characters for a body; 1,024 bytes and 256 characters for a title). A live byte counter shows the count, and over-long input is blocked. Private repos keep their sealed limit.

D-045: copy

  • /login describes the real options.
  • The top-up sheet says which budget blocks, with the balance and shortfall.
  • The explorer field shows this network's default as its placeholder and says when non-https input was not saved.

Also

  • The repo-settings-sections guards now use admit.
  • Two unused imports that failed lint on master are removed from auth-context.tsx.

Tests

  • Unit (pnpm test: 1,891 pass, 10 skipped):
    • lib/view/write-errors.test.ts: decoding the real SDK strings; nonce text never read as a refusal; routing to each sheet; charged vs not.
    • lib/sdk/write-engine.test.ts:
      • a refusal at broadcast is never "sent" and charges nothing;
      • retry after an edit: the edited title lands and the old bytes are never rebroadcast;
      • Superseded twice signs nothing;
      • A→B→A-lands never posts B;
      • a nonce rebroadcast is settled;
      • a refused edit is not replayed after renew;
      • a block-verdict refusal is charged.
    • lib/repo/numbered-retry.test.ts: after Superseded, every retry of a numbered write returns to the same number (never posts a second issue or PR); a permanent refusal frees the number.
    • lib/sdk/cost.test.ts: 42 measured charges (the upper-bound and +30% bounds) and 15 measured admission requirements.
    • lib/view/funds.test.ts: admit-based affordability and the expiry timer.
    • lib/view/text-limits.test.ts: limits read from the contract file.
  • These tests fail on master (119 failures when run there) and pass here.
  • Playwright on moutai (e2e/write-refusals.spec.ts; E2E_WRITE=1, with E2E_REFUSAL_IDENTITY set to a funded identity of your own):
    • r1: a key short of Drive's requirement is stopped before signing;
    • r2: the key's budget is exhausted from another tab, then a write → Platform refuses it and the Renew sheet opens, not "sent";
    • r3: retry after an edit lands the edited title;
    • r4: an expiring key turns the pill red without a reload and opens Renew;
    • r5: Follow confirms with its price, and an over-long comment is blocked.
  • Live results. Before the devnet reset, all six live tests passed on this branch and r1–r5 failed on master, reproducing each defect. Evidence is in dash-forge-qa/evidence/impl/fix-web-write-refusals/{before,after}/.
    • moutai has since been wiped for beta.5. I will re-run the spec after the bring-up PR lands.

Not in this PR

🤖 Generated with Claude Code

@coderabbitai

coderabbitai Bot commented Sep 27, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

Next included review available in 39 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: b2640c42-8546-41aa-bec6-062c2ab341cf

📥 Commits

Reviewing files that changed from the base of the PR and between 659ae72 and a1d6ae1.

📒 Files selected for processing (45)
  • forge-web/app/login/page.tsx
  • forge-web/app/new/page.tsx
  • forge-web/components/auth/create-identity-flow.tsx
  • forge-web/components/confirm-dialog.tsx
  • forge-web/components/keys-panel.tsx
  • forge-web/components/login-modal.tsx
  • forge-web/components/profile-content.tsx
  • forge-web/components/repo/fork-button.tsx
  • forge-web/components/repo/inline-comments.tsx
  • forge-web/components/repo/issue-content.tsx
  • forge-web/components/repo/issues-content.tsx
  • forge-web/components/repo/merge-panel.tsx
  • forge-web/components/repo/new-pull-content.tsx
  • forge-web/components/repo/new-release.tsx
  • forge-web/components/repo/private-compose.tsx
  • forge-web/components/repo/private-members.tsx
  • forge-web/components/repo/pull-content.tsx
  • forge-web/components/repo/repo-settings-sections.tsx
  • forge-web/components/repo/settings-content.tsx
  • forge-web/components/repo/star-button.tsx
  • forge-web/components/top-up-sheet.tsx
  • forge-web/components/ui/text-counter.tsx
  • forge-web/contexts/auth-context.tsx
  • forge-web/e2e/write-refusals.spec.ts
  • forge-web/hooks/use-first-write.ts
  • forge-web/hooks/use-relation-toggle.ts
  • forge-web/hooks/use-ui-store.ts
  • forge-web/hooks/use-write-guard.ts
  • forge-web/lib/auth/controller.ts
  • forge-web/lib/repo/first-write.ts
  • forge-web/lib/repo/index.ts
  • forge-web/lib/repo/numbered-retry.test.ts
  • forge-web/lib/repo/writes.ts
  • forge-web/lib/sdk/cost.test.ts
  • forge-web/lib/sdk/cost.ts
  • forge-web/lib/sdk/index.ts
  • forge-web/lib/sdk/write-engine.test.ts
  • forge-web/lib/sdk/write.test.ts
  • forge-web/lib/sdk/write.ts
  • forge-web/lib/view/funds.test.ts
  • forge-web/lib/view/funds.ts
  • forge-web/lib/view/text-limits.test.ts
  • forge-web/lib/view/text-limits.ts
  • forge-web/lib/view/write-errors.test.ts
  • forge-web/lib/view/write-errors.ts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

…ibrate cost previews

D-007: decode Drive's refusal texts (budget, balance, key, gate, ...) and open the renew, top-up-key or top-up sheet; never show a refused write as sent. D-008: key the retry cache by content, pin an edited retry to the superseded attempt's nonce, remember superseded attempts and tombstone a landed one. D-011/D-012: recalibrate cost.ts from live moutai charges with first-write surcharges; check Drive's admission requirement before signing. D-042: typed unusable-key errors and an expiry timer. D-048: Follow through the write flow. D-049: body limits with a live counter. D-045: copy.

Co-Authored-By: Claude Opus 5.5 (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.

1 participant