You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Task 8] Authenticated Support Desk feedback - #29
Buildout Task 8 first host PR: compose published @pegma/support-desk-*@0.1.0
on D1 with Identity session CSRF, authenticated-user permission defaults,
durable create/reply rate limits, feedback pages, and independent maintenance
cursors. Staff UI and mail activation stay deferred.
The Support Desk host composition is structurally sound: authentication reuses the Identity session contract, customer AccessContext defaults are explicit, mutations enforce CSRF and same-origin Fetch Metadata, and missing versus non-owned tickets share a content-free 404. Storage namespace isolation, independent maintenance cursors, and gated health probing match the stated Task 8 exit criteria. Residual defects are limited to session-cookie lifecycle parity with Identity, incomplete client error handling on the ticket page, and an incorrect public tracking path in worker documentation.
🐞 0 bugs · ⚠️2 warnings · 🤏 1 nits
See the review — 3 inline comments. Commit 0234452.
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Implements Support Desk Buildout Task 8 in the pegma.dev host by composing the published @pegma/support-desk-*@0.1.0 packages over the existing IDENTITY_DB D1 binding, exposing authenticated customer feedback create/list/read/reply APIs plus the corresponding /feedback UI.
Changes:
Added authenticated Support Desk API routes (/api/support/*) with CSRF + same-origin Fetch Metadata enforcement and durable rate limiting.
Added feedback UI pages (/feedback, /feedback/[ticketId]) and client scripts to create tickets, list owned tickets, and reply to owned tickets.
Added host-owned Support Desk maintenance (queue repair + inactive sweep + limiter sweeps) plus health detail/probe wiring and composition docs.
Reviewed changes
Copilot reviewed 18 out of 19 changed files in this pull request and generated 3 comments.
Show a summary per file
File
Description
worker/src/support-maintenance.ts
Adds Support Desk maintenance tasks (queue repair/sweep + limiter sweeps) with independent cursors.
worker/src/support-desk.ts
Defines Support Desk composition/runtime, category allowlist, marker/url helpers, and health probe.
worker/src/support-desk.d1.test.ts
Adds an integration-style D1 test proving support create/list/read/reply over real D1 schema.
worker/src/support-cursors.ts
Adds host-owned cursor persistence for Support Desk maintenance loops.
worker/src/support-api.ts
Implements authenticated Support Desk HTTP API boundary with CSRF + rate limiting and error mapping.
worker/src/support-api.test.ts
Adds unit tests covering API auth, CSRF, ownership 404 behavior, markers/URLs, and maintenance cursors.
worker/src/support-access.ts
Defines AccessContext defaults granting customer permissions to authenticated principals.
worker/src/index.ts
Wires Support Desk health detail/probe, API routing, and scheduled maintenance execution.
worker/README.md
Documents Support Desk composition, routes, maintenance, and health probe behavior.
src/styles/global.css
Extends account-form styling and adds ticket/message list styles used by feedback UI.
src/pages/feedback/[ticketId].astro
Adds ticket detail page shell for viewing/replying to a single owned ticket.
src/pages/feedback.astro
Adds feedback create/list page shell for authenticated product feedback.
src/pages/account.astro
Adds a link from the account page to the feedback area.
src/layouts/Base.astro
Adds “Feedback” to the main navigation.
public/feedback.js
Client script for feedback page: session check, ticket create, and owned ticket list rendering.
public/feedback-ticket.js
Client script for ticket page: load owned ticket, render messages, and send replies.
package.json
Adds Support Desk and authorization-core dependencies.
package-lock.json
Locks newly added dependencies to specific resolved artifacts.
docs/SUPPORT_COMPOSITION.md
Adds public, host-safe composition notes for the Support Desk integration.
The reason will be displayed to describe this comment to others. Learn more.
Grok Build Review
The Support Desk host composition is otherwise disciplined: session-derived principals, CSRF and same-origin gates on mutations, ownership-collapsing 404s, namespaced D1 collections, and independent maintenance cursors are correctly wired. Two defects remain at the HTTP boundary. Ticket url values point at a path that does not exist on this site, and message-body validation rejects newlines that the multi-line feedback and reply forms are designed to submit.
Allow multiline message bodies, emit publicTicketUrl in API summaries, share category list from one constant, drop unused limiter cursors, and stretch secondary links on mobile.
The reason will be displayed to describe this comment to others. Learn more.
Grok Build Review
The Support Desk host composition is structurally sound: authentication reuses the Identity session contract, customer AccessContext defaults are explicit, mutations enforce CSRF and same-origin Fetch Metadata, and missing versus non-owned tickets share a content-free 404. Storage namespace isolation, independent maintenance cursors, and gated health probing match the stated Task 8 exit criteria. Residual defects are limited to session-cookie lifecycle parity with Identity, incomplete client error handling on the ticket page, and an incorrect public tracking path in worker documentation.
The reason will be displayed to describe this comment to others. Learn more.
⚠️[warning] Invalidated sessions do not clear the Host session cookie
Identity's API clears __Host-pegma_session on InvalidatedSessionError via Set-Cookie Max-Age=0. Support mirrors the same authenticate/invalidateSession path (destroy server-side session when data is corrupt, principal mismatch, or the account is inactive/unverified) but the error response at this catch only returns { error } with no cookie expiry. After server-side destruction, the browser continues to present a dead credential on subsequent Support calls until an Identity route performs the clear. That breaks session-lifecycle parity across /api/* and leaves a sticky 401 state for Support-only clients.
Suggestion: Match identity-api: on InvalidatedSessionError, append Set-Cookie: __Host-pegma_session=; Path=/; Max-Age=0; Secure; HttpOnly; SameSite=Strict (extend the local json() helper or share a clearSessionCookie utility).
The reason will be displayed to describe this comment to others. Learn more.
⚠️[warning] Non-401 identity failures abort loadTicket without UI recovery
loadTicket() preflights /api/identity/account and rethrows any error that is not status 401. loadTicket() is invoked without a rejection handler. Identity runtime unavailability (503), network failure, or non-JSON responses therefore become unhandled promise rejections while the page remains on "Loading ticket…". The list page (feedback.js) handles the same class of failure with a user-visible status message; the ticket page does not.
Suggestion: In the identity preflight catch, treat non-401 failures the same way as the ticket-load catch: set detail hidden, call showStatus with a clear unavailable message, and return. Do not rethrow.
The reason will be displayed to describe this comment to others. Learn more.
🤏 [nit] Documented ticket tracking path does not exist
The Support Desk section states tracking pages are /feedback and /feedback/{ticketId}. There is no dynamic /feedback/{ticketId} route. The implemented shell is /feedback/ticket/?id={ticketId}, which is what publicTicketUrl(), feedback.js links, and docs/SUPPORT_COMPOSITION.md already emit. Operators or agents following the Worker README will request a path that 404s.
Suggestion: Replace /feedback/{ticketId} with /feedback/ticket/?id={ticketId} so the README matches the live static route and publicTicketUrl().
The reason will be displayed to describe this comment to others. Learn more.
Handle identity preflight failures inside the ticket page
When /api/identity/account returns anything other than 401, or its fetch/JSON parsing fails, this rethrow escapes loadTicket(), which is invoked without awaiting or catching its promise. The page consequently remains stuck on “Loading ticket…” with an unhandled rejection instead of showing an availability error; handle these failures here or wrap the entire load flow in the existing status-rendering catch.
The reason will be displayed to describe this comment to others. Learn more.
Separate ticket creation success from list refresh failure
If the POST succeeds but this follow-up list request fails, the shared catch reports “Could not create ticket” even though the ticket was already committed. A user who retries can therefore create duplicate feedback tickets; preserve and report the successful creation independently, then handle a refresh failure as a separate list-loading error.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements Support Desk Buildout Task 8 (first pegma.dev host PR): authenticated customer feedback create / list / read / reply using published exact
@pegma/support-desk-*@0.1.0over D1.Plan / phase
support-deskdocs/BUILDOUT.mdTask 8pegma.devonlyExit criteria checklist
IDENTITY_DB, Support Desk collection isolation)X-Pegma-CSRF) / rate-limit composition[PEG-…]marker helpers + ticket URLsRoutes
/api/support/categories/api/support/tickets/api/support/tickets/api/support/tickets/:id/api/support/tickets/:id/repliesUI:
/feedback,/feedback/[ticketId]Test evidence
npm run test:node— 141 passed (10 new support-api tests)npm run test:d1— D1 support-desk test passednpm run check— cleanResidual risks