Repository navigation
fix(action-center): stop the demo brand's page-opened call from failing on every page - #1836
Conversation
…ith a 500 Opening an explore page on the demo brand called getting_started_page_opened, whose write the demo brand's trigger refuses (00381, 'demo_brand'), and the server action threw it: every such page open logged a 500. The action now answers as a value and never throws (ansvisor#1777): { ok, recorded } or { ok: false, failure }. The demo brand's refusal is answered quietly, nothing recorded or logged, and the layout no longer asks for the demo brand at all. Co-Authored-By: Claude Opus 5.5 <[email protected]>
gkhngyk
left a comment
There was a problem hiding this comment.
Looks good. Approving.
Root cause. getting_started_page_opened inserts the step with on conflict do nothing. A BEFORE INSERT row trigger runs before Postgres checks for the conflict, so 00381's guard refuses the insert on the demo brand even though the demo already has every explore step recorded (server/src/lib/demo/action-center.js). The action threw on that error, and the thrown server action showed up as a 500. The PR stops the call where it starts (no request for the demo brand) and answers the database's demo_brand refusal as a value. That fixes the cause; it doesn't just hide the error.
Demo guard unchanged. No migration, and nothing in 00380/00381, DEMO_GUARDED or the demo coverage tests is touched. The database still refuses the write. The action only reads the exact demo_brand message, which only that trigger raises, so a real brand's errors are still logged and returned as failed. Real brands behave as before: their page opens are recorded, and the browser remembers the step only after ok && recorded.
Other page-load calls. I looked for other calls that write when a dashboard page opens. The KPI preset setup (seedKpiPresets) already returns early for the demo (isLocked, assertWritable, and the demo has its KPIs). I didn't find any other page-load write.
Tests: getting-started.test.ts and page-opened.test.tsx pass. With the two source files put back to main, 7 of their tests fail, so they cover the fix. Also passing: the rest of the getting-started tests, plan-row.test.ts, subscription-guard-coverage.test.ts, and the demo and demo-gate tests (12 files, 87 tests). tsc is clean. eslint and prettier pass on the four files. The PR already contains the latest main and merges cleanly. It also merges cleanly with every open PR, including #1799 and the #1800 → #1822 stack (whose only change in getting-started.ts is the dbClient import). On the merge with #1822, the same tests pass.
Notes (not blocking)
- On Ansvisor Cloud, the dashboard lock (
isLocked, which includes the demo brand) already stopped this call. The 500 showed up where that lock is off, for example a local build without the Cloud flag. The newisDemocheck covers that case too, which is right. useBrandStore(isDemoSelected)from@/lib/demo/demo-branddoes the same thing as the inline selector.- The comment above
PAGE_STEPSinserver/src/lib/demo/action-center.js("getting_started_page_opened then has nothing to record on a visit") is no longer accurate, because the insert is still attempted. Possible later change, which would need a migration: have the function insert only when the step isn't recorded yet. That would also save real brands a write on every first visit in a new browser.
gkhngyk
left a comment
There was a problem hiding this comment.
Merging in order with the other approved PRs. This head merges current main; its tree is what main will be after this squash, checked with the full server and web suites, tsc, lint, format and next build.
Summary
On the demo brand (00380/00381), every page that marks a Getting started step as opened logged a 500 in the console.
markGettingStartedPageOpenedthrew on the RPC'sdemo_branderror, which 00381's trigger raises by design. A thrown server action is also against #1777, which says return a value.What changes
markGettingStartedPageOpened(src/lib/actions/getting-started.ts) no longer throws. It returns{ ok: true; recorded } | { ok: false; failure: 'step' | 'failed' }.demo_branderror becomes{ ok: true, recorded: false }: nothing written, nothing logged.failure: 'failed'.failure: 'step').GettingStartedPageOpened(the caller in the layout):ok && recorded.No user-facing change other than the 500 going away, so no Help update.
Related issue
None. Found while building Chat Wave 1 against the demo brand.
Type of change
fix— Bug fixHow to test
src/lib/actions/getting-started.test.ts: recorded, not yet, demo silent, other errors and a throwing client return a value, a step without a page;page-opened.test.tsx: the new result shape, no request on the demo brand, and a failed result.Checklist
🤖 Generated with Claude Code