Skip to content

feat(carrier): merchant can cancel an unaccepted marketplace booking - #164

Merged
breakdisk merged 9 commits into
masterfrom
feat/carrier/marketplace-merchant-cancel
Nov 27, 2026
Merged

breakdisk merged 9 commits into
masterfrom
feat/carrier/marketplace-merchant-cancel

Conversation

@breakdisk

Copy link
Copy Markdown
Owner

Summary

A merchant can cancel a marketplace booking the carrier has not accepted yet, without stranding a card hold.

  • Every transition out of Pending (expire, merchant cancel, accept) is a compare-and-set: UPDATE ... WHERE id AND tenant_id AND status='pending'. Zero rows means a conflict (BusinessRule), not a 500.
  • A hold that is authorized after the booking left Pending is voided instead of attached. The void is retried 3 times; on final failure it logs at error with booking_id, intent_id and a MANUAL RELEASE marker.
  • Every error on the authorized arm carries both ids and a "hold may be stranded — MANUAL RELEASE / RECONCILE" marker.
  • A merchant cancel that loses the provider claim returns a conflict, not a 500.

Merge note

  • services/carrier/src/api/http/mod.rs textually conflicts with feat/portals/marketplace-real-backend (both add routes). Keep both sets of routes.

Known follow-ups

  • Payments void/capture are not idempotent, so an uncertain provider outcome can leave a booking Pending.
  • Add alert rules on the MANUAL RELEASE and "hold may be stranded" log lines.
  • NI checkout is not expired on cancel. No HTTP-level route test. No portal caller yet.

Test plan

  • 77 unit + 70 integration (implementer run)
  • CI green

Part of the "wire the platform gaps" plan (docs/platform/gap-plans). Each task passed a task review; the branch passed a whole-branch final review and one fix wave with a scoped re-review.

🤖 Generated with Claude Code

claude and others added 9 commits November 26, 2026 05:09
…r has not accepted

POST /v1/marketplace/bookings/:id/cancel (marketplace:book). Void-then-cancel
is now one shared path used by the expiry sweep and the merchant cancel; a
failed void leaves the booking Pending. Someone else's booking is a 404
identical to a missing one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ands after cancel

accept, reject, expiry and merchant cancel now write through
transition_booking (UPDATE ... WHERE status and payment_status still match),
so racing writers cannot both win; a lost race is BusinessRule (expiry: skip),
not a 500. handle_authorized voids a hold that lands on a booking no longer
pending instead of marking it authorized.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…lease if it keeps failing

The booking-payment consumer commits every message, so a failed void was never
redelivered. The late-hold void now makes 3 attempts (0, 200 ms, 1 s) and, if
all fail, logs at error with booking_id, tenant_id and intent_id and a
MANUAL RELEASE REQUIRED marker. Stale "retry costs nothing" comments corrected.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A lost compare-and-set after a successful void re-read the booking and voided
the same intent again, raising a false MANUAL RELEASE alarm. The void is now
carried across CAS passes; if the void succeeded but the record never lands,
log "RECONCILE BOOKING" and return Err instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…d-arm error

The consumer commits unconditionally, so an error outside the late-hold void
was logged without ids and the hold silently stranded. handle_authorized now
wraps every error with booking_id, intent_id and logs a
"hold may be stranded - MANUAL RELEASE / RECONCILE" marker, CAS give-up included.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nflict, not a 500

After a void error, re-read the booking (tenant-scoped); if it left Pending the
carrier won the race, so return CONFLICT_MESSAGE instead of an internal error.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
CI installs stable Rust, which is now 1.100.0 (2026-11-09). Its type-
inference change (rust-lang/rust#148922) stops redis 0.25.4 compiling
(`!: FromRedisValue`), so "cargo check", "Lint" and every test job behind
it fail on master and every open PR, with no code change.

Lockfile-only, all in-range (no Cargo.toml change):
- redis 0.25.4 -> 0.25.5 (the never-type fallback fix)
- RustSec patched releases: ctutils 0.4.8, quinn-proto 0.11.19,
  quinn-udp 0.5.16, rustls 0.23.46, rustls-webpki 0.103.17,
  webpki-roots 1.0.12, rustix 1.1.6, tokio 1.54.1, url 2.5.9,
  aws-smithy-* (in range)

Verified locally on rustc 1.100.0: cargo check --workspace --all-targets
and CI's clippy command (-D warnings -D clippy::all) both pass.

Not cleared (no in-range fix; needs a decision, so no ignore is added):
crypto-bigint 0.5.5 via aws-sigv4 (RUSTSEC-2026-0387), libsqlite3-sys
0.30.1 in the lockfile but not built (RUSTSEC-2026-0459), unmaintained
chrono / chrono-tz / chrono-tz-build / pin-utils. rmcp (3 advisories)
needs a ServerInfo -> ServerConfig rename in ai-layer, so it lands with
the MCP PR, not here.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
rmcp 3.0.1 has three advisories (RUSTSEC-2026-0461 unbounded tool schema
cache in the Streamable HTTP server transport, which is the transport
/mcp serves; -0462 unbounded response buffering in Streamable HTTP
clients; -0457 OAuth client SSRF filter). The patched floor is 3.9.0, so
the workspace requirement is raised to 3.9.0 and the lock takes 3.12.0.

3.9+ deprecates `model::ServerInfo` in favour of `ServerConfig` (same
type), which fails CI's -D warnings, so the handler uses the new name.

Verified on rustc 1.100.0: clippy -p logisticos-ai-layer --all-targets
-D warnings -D clippy::all clean; cargo test -p logisticos-ai-layer
107 passed.

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

The 2026-11 advisory-db refresh left six findings that no in-range upgrade
clears. Each is added to all three places that must agree (ci-rust.yml
--ignore flags, deny.toml, scripts/check-audit-ignores.sh) with its reason
and an expiry check the guard re-runs on every CI build:

- RUSTSEC-2026-0387 crypto-bigint 0.5.5: compiled only via aws-sigv4's
  sigv4a (S3 multi-region access point signing), never called; fix is
  0.7.6 and aws-sigv4 1.x pins 0.5. Guard walks the chain
  crypto-bigint <- elliptic-curve/ecdsa/primeorder <- p256 <- aws-sigv4
  and fails if any link gains another consumer.
- RUSTSEC-2026-0459 libsqlite3-sys: never compiled (sqlx-sqlite optional
  dep, Postgres-only). Guard fails if it enters the build graph.
- RUSTSEC-2026-0543 chrono, -0555 chrono-tz, -0559 chrono-tz-build,
  -0441 pin-utils: unmaintained, informational, no fixed version. Guard
  fails once they stop being reported.

Verified locally: cargo audit with CI's flags, the guard script and
cargo deny check (advisories) all pass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
breakdisk pushed a commit that referenced this pull request Nov 27, 2026
- carrier: #164 added MarketplaceRepository::transition_booking. #171's admin
  route test double predates it, so the lib tests stopped compiling. Give the
  double the same compare-and-set as the service tests' double.
- order-intake: #173 wired tests/unit into Cargo, and its Shipment fixture
  predates #163's sla_due_at field. Add it as None.

Checked locally on rustc 1.100: workspace clippy --all-targets -D warnings,
the unwrap_used gate, the /health and OpenAPI route checks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@breakdisk
breakdisk merged commit 326c739 into master Nov 27, 2026
7 checks passed
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