Skip to content

fix(action-center): stop the demo brand's page-opened call from failing on every page - #1836

Merged
gkhngyk merged 2 commits into
ansvisor:mainfrom
cihan-gyk:fix/getting-started-demo-page-open
Oct 30, 2026
Merged

gkhngyk merged 2 commits into
ansvisor:mainfrom
cihan-gyk:fix/getting-started-demo-page-open

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

On the demo brand (00380/00381), every page that marks a Getting started step as opened logged a 500 in the console. markGettingStartedPageOpened threw on the RPC's demo_brand error, 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' }.
    • The demo brand's demo_brand error becomes { ok: true, recorded: false }: nothing written, nothing logged.
    • Other errors are logged and return failure: 'failed'.
    • A step without a page makes no RPC call (failure: 'step').
  • GettingStartedPageOpened (the caller in the layout):
    • sends nothing when the active brand is the demo;
    • writes its localStorage mark only on 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 fix

How to test

  1. On the demo brand, open Brand Visibility, Citations and Mentions. No 500 for the page-opened call.
  2. On a real brand, opening those pages still crosses out Getting started's Explore steps.
  3. Tests:
    • new 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

  • Branch follows the naming convention
  • Commits follow Conventional Commits
  • Web: lint (0 errors), typecheck and the full test suite pass (657 files, 6,463 tests)
  • Tests added

🤖 Generated with Claude Code

…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 gkhngyk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

  1. 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 new isDemo check covers that case too, which is right.
  2. useBrandStore(isDemoSelected) from @/lib/demo/demo-brand does the same thing as the inline selector.
  3. The comment above PAGE_STEPS in server/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 gkhngyk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@gkhngyk
gkhngyk merged commit bdb24b7 into ansvisor:main Oct 30, 2026
4 of 5 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