Repository navigation
Description
Discovery summary
This issue captures the full codebase-wide Half-Shell audit of SwiftDispatch and serves as the parent discovery/tracking issue for the highest-value technical-debt work identified during the review.
The audit did not find a codebase that needs a broad rewrite. SwiftDispatch has already accumulated substantial product infrastructure: role-aware UI routing, tenant isolation, payments, public intake, realtime state, SMS outbox delivery, operational scripts, E2E coverage, and explicit lifecycle logic.
The main risk is policy drift as the product has grown:
- authorization rules are not enforced consistently at every boundary
- client mutation reliability differs by workflow
- background delivery recovery is incomplete
- test coverage is stronger around utilities than production mutation seams
- repository quality gates rely too heavily on developer discipline
- a few framework/tooling assumptions have gone stale
This discovery issue should remain the high-level map. Concrete implementation belongs in linked tracking issues.
Half-Shell findings
Leonardo — system-level verdict
The codebase is not asking for a rewrite. The load-bearing boundaries need reinforcement.
The top four debt buckets are:
- Authorization boundary is incomplete.
- Client mutation reliability is inconsistent.
- SMS background-job recovery is incomplete.
- Quality gates are mostly human-enforced.
Second-tier debt includes behavior-oriented test coverage, rate-limit degradation policy, framework maintenance, and minor repository hygiene.
Raphael — authorization boundary drift
SwiftDispatch intentionally distinguishes user capabilities in the UI/proxy layer:
- technicians use
/tech - dispatchers/admins use
/dispatch - admins use
/admin - super admins use
/superadmin
However, several API mutation routes rely on authentication/profile lookup plus tenant scoping rather than an explicit allowed-role check.
Current RLS is primarily tenant-scoped. It is effective for separating companies, but it does not universally express the application's role model.
The result is a split model:
UI authorization: role aware
API authorization: inconsistent
Database authorization: primarily tenant aware
This is especially risky where mutation routes assume that any non-admin actor is a dispatcher when writing audit/status events.
A requireRole() abstraction already exists, so this is mostly a consolidation/enforcement problem rather than a new architecture problem.
Child issue
- Centralize API role authorization and enforce a tested permission matrix #49 Centralize API role authorization and enforce a tested permission matrix
Donatello — overlapping responsibility boundaries
SwiftDispatch currently has several overlapping authorization/context mechanisms, including variants of:
- profile requirements
- admin/super-admin profile helpers
- generic role requirements
- manual company checks
- proxy checks
- RLS tenant enforcement
Each mechanism makes sense locally, but together they make it harder to answer one simple question:
What must be true for actor X to perform operation Y?
The long-term goal should be one boring application-level authorization contract, with RLS and route gating acting as defense-in-depth rather than competing sources of authority.
Donatello also flagged the same duplication pattern in client mutations: each flow independently implements fetch, optimistic state, error parsing, rollback, and canonical reconciliation.
That duplication is already producing divergent failure behavior.
Child issue
- Standardize client mutation handling and rollback semantics #50 Standardize client mutation handling and rollback semantics
Michelangelo — client/server divergence on transport failure
Several client workflows treat an HTTP error correctly but do not treat a rejected fetch() as the same failed mutation.
Typical failure mode:
optimistic UI update
→ fetch begins
→ transport failure rejects promise
→ HTTP error branch never runs
→ rollback never runs
→ UI disagrees with canonical server state
This was observed in the technician-assignment work addressed by PR #48 and also exists as a broader pattern in adjacent job-board operations such as optimistic job movement and loading-state cleanup.
The fix should not be scattered try/catch patches everywhere. The repo should have a small shared mutation/result contract that normalizes:
- success
- non-2xx HTTP failure
- network/transport failure
- malformed response
- rollback
- canonical reconciliation
Child issue
- Standardize client mutation handling and rollback semantics #50 Standardize client mutation handling and rollback semantics
Casey Jones — stranded SMS work
The SMS outbox has a good basic lifecycle:
pending
→ processing
→ sent
or retrying
→ failed
It also records locked_at, which suggests a lease model.
However, the worker only loads pending and retrying work. A row claimed into processing can remain there permanently if the worker crashes or is interrupted before the row is finalized.
That means the system already has most of a lease/retry design, but not stale-lease recovery.
The fix should complete the existing model rather than replace it with a new queueing platform.
Child issue
- Add stale SMS outbox lease recovery and worker resilience #51 Add stale SMS outbox lease recovery and worker resilience
Splinter — quality gates are conventions, not guarantees
The repo has useful local validation commands, but they are not fully enforced by repository automation.
Key observations from the audit:
maindoes not currently require validation checks before merge.- There is no baseline PR workflow enforcing the full validation contract.
- the lint command still reflects an older Next.js assumption (
next lint). - generated
tsconfig.tsbuildinfois tracked.
As SwiftDispatch grows, the repository should make a safe change the default path rather than depending on someone remembering every validation step.
Child issue
- Add CI quality gates and protect main from unvalidated changes #52 Add CI quality gates and protect main from unvalidated changes
April O'Neil — coverage is utility-heavy, workflow-light
The existing test suite provides useful coverage around several internal utilities and state primitives, but the product's most important business seams need more behavior-level integration coverage.
The important distinction is:
proving a final database state is reachable
versus
proving the same public mutation seam used by production reaches the correct state under success and failure
Issue #45 / PR #48 already exposed this distinction around dispatcher assignment.
Future test investment should focus on representative behavior boundaries rather than only increasing raw test count.
High-value seams include:
- dispatcher mutation authorization
- job lifecycle mutation
- technician assignment
- quote mutation
- customer acceptance
- SMS delivery/recovery
- public intake abuse controls
- cross-tenant isolation
This work can be added incrementally alongside #49–#52 rather than opened as a separate broad test rewrite unless the scope grows materially.
Shredder — adversarial view
The most useful adversarial question is:
What happens if the actor ignores the UI entirely and calls the APIs directly?
The first probes should be:
- technician attempting dispatcher/admin mutations
- dispatcher attempting admin mutations
- admin attempting super-admin operations
- valid user attempting cross-company mutations
- mutations interrupted between optimistic UI and server acknowledgment
- background jobs interrupted after claim but before completion
The codebase should answer those with executable tests, not architectural assumptions.
Recommended dependency chart
The audit recommends treating the work as a dependency graph, not four unrelated cleanup tasks.
flowchart TD
A[Discovery audit: this issue]
B[#49 Authorization boundary]
C[PR #48 Assignment divergence fix]
D[#50 Shared mutation reliability]
E[#51 SMS lease recovery]
F[#52 CI quality gates]
G[Broader behavior-level regression coverage]
H[Lower-priority maintenance: rate-limit policy, dependency updates, repo hygiene]
A --> B
A --> C
A --> E
A --> F
C --> D
B --> G
D --> G
E --> G
B --> F
D --> F
E --> F
F --> H
Suggested execution order
Phase 1 — establish correctness boundaries
-
Centralize API role authorization and enforce a tested permission matrix #49 Authorization boundary
- establishes who may perform each operation
- creates an executable permission matrix
- reduces security/correctness ambiguity before more feature work
-
Finish and merge PR Fix dispatcher assignment / Kanban state divergence (issue #45) #48
- resolves the concrete assignment/Kanban divergence already under review
- provides the first known-good canonical-state reconciliation pattern
Phase 2 — generalize the reliability lessons
-
Standardize client mutation handling and rollback semantics #50 Shared mutation reliability
- should build on the proven behavior from PR Fix dispatcher assignment / Kanban state divergence (issue #45) #48
- turns one bug fix into a reusable client mutation contract
-
Add stale SMS outbox lease recovery and worker resilience #51 SMS lease recovery
- can proceed mostly independently after the authorization model is understood
- should complete the background-work reliability model before notification volume grows
Phase 3 — lock in the gains
-
Add CI quality gates and protect main from unvalidated changes #52 CI quality gates
- should require the validation suites introduced/expanded by Centralize API role authorization and enforce a tested permission matrix #49–Add stale SMS outbox lease recovery and worker resilience #51
- makes new regressions harder to land
- branch protection should be enabled once the checks themselves are stable
-
Broader behavior-level regression coverage
- expand around real production seams as the above work lands
- avoid a giant one-time test rewrite
-
Lower-priority maintenance
- rate-limit fail-open/fail-closed policy by endpoint
- dependency/version verification and patching
- generated-file/repo hygiene
- stale abstractions/dead-code cleanup
Dependency rules / exit gates
Use these gates before moving to dependent work:
Before #50 is considered complete
- PR Fix dispatcher assignment / Kanban state divergence (issue #45) #48 behavior is either merged or intentionally superseded.
- technician assignment and job movement share the same failure semantics.
- transport rejection is covered by automated tests.
Before #52 branch protection is enabled
- the canonical lint command is fixed.
- typecheck, tests, and production build are stable in CI.
- Centralize API role authorization and enforce a tested permission matrix #49's authorization tests are included in the required test suite.
- Standardize client mutation handling and rollback semantics #50/Add stale SMS outbox lease recovery and worker resilience #51 regression tests are included if those issues are already merged.
Before declaring this discovery resolved
- Centralize API role authorization and enforce a tested permission matrix #49–Add CI quality gates and protect main from unvalidated changes #52 are either completed or explicitly deferred with rationale.
- permission boundaries are executable, not just documented.
- optimistic mutation rollback is deterministic.
- stale SMS processing work is recoverable.
- main has a working automated validation gate.
- any remaining audit findings are captured as follow-up issues or documented as intentionally accepted debt.
Priority summary
| Priority | Work | Reason |
|---|---|---|
| 1 | #49 Authorization boundary | Security and correctness boundary |
| 2 | PR #48 then #50 mutation reliability | Prevents UI/server divergence |
| 3 | #51 SMS lease recovery | Prevents silently stranded operational work |
| 4 | #52 CI / branch protection | Prevents the same classes of debt from returning |
| 5 | Behavior-level integration coverage | Makes production seams trustworthy |
| 6 | Rate-limit degradation review | Make security/availability tradeoffs explicit |
| 7 | Framework/dependency maintenance | Remove stale assumptions and patch risk |
| 8 | Repo hygiene | Low-risk cleanup after load-bearing work |
Non-goals
This discovery does not recommend:
- rewriting SwiftDispatch
- replacing Supabase
- replacing the SMS outbox with Kafka/SQS
- adopting a large frontend state library solely for mutation handling
- implementing enterprise RBAC/custom roles
- performing a giant test-suite rewrite
The recurring recommendation from the audit is to make the existing architecture more explicit and dependable, not more complicated.
Activity
diese-tech commentedon Sep 19, 2026
Status update: all four Phase 1–3 child issues are now merged.
Checking this issue's own "Before declaring this discovery resolved" gates:
fetchMutation()/MutationResult<T>contract in Standardize client mutation handling and rollback semantics #50, with debounced-patch-coalescing and delete-rollback fixes found in review)reclaimStale()lease recovery in Add stale SMS outbox lease recovery and worker resilience #51)mainhas a working automated validation gate (.github/workflows/ci.yml+ theprotect-mainruleset — verifiedmainreportsprotected: true, PR required,validatecheck required)What's left per the audit's own Phase 3/priority list is lower-priority and not yet broken into concrete tracked issues:
I'll leave this issue open pending direction on whether to open tracked follow-up issues for that remaining list, or treat it as accepted/deferred debt for now.
Generated by Claude Code
diese-tech commentedon Sep 19, 2026
Full scope for the remaining test/security work is now tracked, per the repo owner's follow-up request after #58 merged:
#62 and #64 both build directly on #58's findings — #62 finishes the route-coverage sweep #58 started, #64 goes looking for more instances of the exact cross-tenant bug class #58's review caught in
POST /api/jobs.Generated by Claude Code
diese-tech commentedon Sep 20, 2026
Status update — this discovery's tracked follow-on work is essentially done:
Closed: #49, #50, #51, #52, #58, #60, #62, #63, #64, #66.
Open, with a clear reason each:
SUPABASE_SERVICE_ROLE_KEY, which this session's Supabase MCP access correctly never exposes. Left open per your explicit call to leave it as partial progress rather than falsely claim it closed.nextvalRPC finding from Harden payment provider tests, especially the live Square integration #60 (probably-broken invoice-number sequence call, with a working fallback) was flagged but never turned into its own tracked issue — still your call whether it's worth one.Notable finding from this pass, fixed in PR #70 (#66):
status_eventsinserts for dispatcher/admin-created and -updated jobs were being silently dropped by RLS in production — confirmed directly against the live project that 654 real, non-demo jobs have zero audit-trail rows. Fixed by routing those inserts through the admin client, matchingintake/tech-action's existing pattern. No backfill was done for the already-affected 654 jobs — that's a data decision I left for you rather than doing unilaterally.Everything else from the original Half-Shell findings (authorization boundary, client mutation reliability, SMS lease recovery, CI quality gates, and the systematic role/coverage audits) has landed. I'd consider this discovery's tracked scope resolved except for #61's live smoke-test step and the optional
nextvalfollow-up.Generated by Claude Code
Generated by Claude Code