Skip to content

fix(amber): store anonymous hub views with a NULL uid - #9226

Open
tanishqgandhi1908 wants to merge 4 commits into
apache:mainfrom
tanishqgandhi1908:fix/hub-anonymous-view
Open

tanishqgandhi1908 wants to merge 4 commits into
apache:mainfrom
tanishqgandhi1908:fix/hub-anonymous-view

Conversation

@tanishqgandhi1908

@tanishqgandhi1908 tanishqgandhi1908 commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

What changes were proposed in this PR?

A logged-out viewer's page sends POST /api/hub/view with userId: 0. postView incremented the view count, then inserted a user_action row with uid = 0. That breaks the foreign key to user(uid), since no user has uid 0, so the request returned 500 and the view was never recorded, though the count had already gone up.

  • postView now records the view with a NULL uid when userId is 0 or missing. user_action.uid is nullable, and migration 13.sql already stored the old anonymous views as NULL.
  • recordUserAction now takes userId: Option[Integer] = None and sets the uid only when one is given, so the default can't hit the same foreign key.
  • postView bumps the count and inserts the user_action row in one transaction, so a view that can't be recorded (for example, a uid whose account was deleted) no longer raises the count.

Before and after, sending the logged-out request ({"entityId":8,"userId":0,"entityType":"workflow"}) three times:

Responses view_count (from 42) user_action view rows
Before 500, 500, 500 45 0
After 200, 200, 200 45 3, uid NULL

Any related issues, documentation, discussions?

Closes #9225.

How was this PR tested?

New HubResourceSpec tests:

  • a view with userId: 0 and one with no userId both return the next count and are recorded with a NULL uid;
  • a view whose uid has no user row fails and leaves the count unchanged.

Each fails without its part of the fix. HubResourceSpec passes (75/75), and scalafmtCheckAll and scalafixAll --check are clean. The before/after table above came from running the requests against a local server.

Was this PR authored or co-authored using generative AI tooling?

Generated-by: Claude Code (Claude Opus 5.5)

… with 500

A logged-out viewer sends userId 0, which no user row has, so the user_action
insert broke its foreign key after the view count was already incremented.
postView now records the view with a NULL uid, and recordUserAction defaults
to null instead of 0.

Closes apache#9225
@Yicong-Huang Yicong-Huang added release/v1.3 back porting to release/v1.3 release/v1.2 back porting to release/v1.2 labels Oct 30, 2026
@github-actions
github-actions Bot requested review from mengw15 and xuang7 October 30, 2026 03:40
@github-actions

github-actions Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Backport auto-label report

This fix: PR was checked against each actively-supported release branch. A release/* label nominates a backport target; the branch's release manager approving this PR is what sends the fix there. The required Backport Approvals check stays red until every label below is approved, so each manager either approves or removes their own label — which is why the labels left on a merged PR are exactly the branches it reached.

Release branch Analysis
🚫 release/v1.3 Label was removed earlier (opt-out); not re-added. Re-add it by hand if this fix should be backported here after all — the branch's release manager then has to approve before this PR can merge.
🚫 release/v1.2 Label was removed earlier (opt-out); not re-added. Re-add it by hand if this fix should be backported here after all — the branch's release manager then has to approve before this PR can merge.

Auto-label run.

@github-actions

Copy link
Copy Markdown
Contributor

Automated Reviewer Suggestions

Based on the git blame history of the changed files, we recommend the following reviewers:

  • No candidates found from git blame history.

@github-actions

github-actions Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ Benchmark changes need a look

🟢 0 better · 🔴 10 worse · ⚪ 5 noise (<±5%) · 0 without baseline

Compared against main b516b2c benchmarked on this same runner, so the delta is largely free of cross-runner hardware noise. The "7d avg" column still reflects the gh-pages dashboard. Treat <±5% as noise unless repeated.

Dashboard · Run

config throughput MB/s latency max Δ latest / 7d
🔴 bs=10 sw=10 sl=64 364 0.222 26,403/42,824/42,824 us 🔴 +21.8% / 🔴 +212.0%
🔴 bs=100 sw=10 sl=64 822 0.502 119,338/148,986/148,986 us 🔴 +8.8% / 🔴 +68.3%
⚪ bs=1000 sw=10 sl=64 975 0.595 1,022,703/1,079,218/1,079,218 us ⚪ within ±5% / 🔴 +30.6%
Baseline details

Latest main b516b2c from same runner

config metric PR latest main 7d avg Δ latest Δ 7d
bs=10 sw=10 sl=64 throughput 364 tuples/sec 414 tuples/sec 1,005 tuples/sec -12.1% -63.8%
bs=10 sw=10 sl=64 MB/s 0.222 MB/s 0.253 MB/s 0.614 MB/s -12.3% -63.8%
bs=10 sw=10 sl=64 p50 26,403 us 22,939 us 10,325 us +15.1% +155.7%
bs=10 sw=10 sl=64 p95 42,824 us 35,168 us 13,728 us +21.8% +212.0%
bs=10 sw=10 sl=64 p99 42,824 us 35,168 us 16,323 us +21.8% +162.3%
bs=100 sw=10 sl=64 throughput 822 tuples/sec 886 tuples/sec 1,347 tuples/sec -7.2% -39.0%
bs=100 sw=10 sl=64 MB/s 0.502 MB/s 0.541 MB/s 0.822 MB/s -7.2% -39.0%
bs=100 sw=10 sl=64 p50 119,338 us 109,717 us 80,846 us +8.8% +47.6%
bs=100 sw=10 sl=64 p95 148,986 us 141,445 us 88,523 us +5.3% +68.3%
bs=100 sw=10 sl=64 p99 148,986 us 141,445 us 112,010 us +5.3% +33.0%
bs=1000 sw=10 sl=64 throughput 975 tuples/sec 988 tuples/sec 1,394 tuples/sec -1.3% -30.0%
bs=1000 sw=10 sl=64 MB/s 0.595 MB/s 0.603 MB/s 0.851 MB/s -1.3% -30.0%
bs=1000 sw=10 sl=64 p50 1,022,703 us 1,017,181 us 787,853 us +0.5% +29.8%
bs=1000 sw=10 sl=64 p95 1,079,218 us 1,061,575 us 826,583 us +1.7% +30.6%
bs=1000 sw=10 sl=64 p99 1,079,218 us 1,061,575 us 872,816 us +1.7% +23.6%
Raw CSV
config_idx,batch_size,schema_width,string_len,num_batches,total_ms,total_tuples,total_bytes,tuples_per_sec,mb_per_sec,lat_p50_us,lat_p95_us,lat_p99_us
0,10,10,64,20,549.29,200,128000,364,0.222,26403.35,42823.78,42823.78
1,100,10,64,20,2433.53,2000,1280000,822,0.502,119338.14,148986.36,148986.36
2,1000,10,64,20,20509.65,20000,12800000,975,0.595,1022702.79,1079217.74,1079217.74

@codecov-commenter

codecov-commenter commented Oct 30, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.61%. Comparing base (b516b2c) to head (477e265).
⚠️ Report is 1 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff            @@
##               main    #9226   +/-   ##
=========================================
  Coverage     91.60%   91.61%           
  Complexity     5038     5038           
=========================================
  Files          1283     1283           
  Lines         57005    57014    +9     
  Branches       7419     7420    +1     
=========================================
+ Hits          52222    52232   +10     
+ Misses         2915     2913    -2     
- Partials       1868     1869    +1     
Flag Coverage Δ *Carryforward flag
access-control-service 77.44% <ø> (ø) Carriedforward from 26f6487
agent-service 99.56% <ø> (-0.01%) ⬇️ Carriedforward from 26f6487
amber 85.34% <100.00%> (+0.01%) ⬆️
computing-unit-managing-service 64.05% <ø> (ø) Carriedforward from 26f6487
config-service 87.73% <ø> (ø) Carriedforward from 26f6487
file-service 82.31% <ø> (ø) Carriedforward from 26f6487
frontend 96.41% <ø> (-0.01%) ⬇️ Carriedforward from 26f6487
notebook-migration-service 83.77% <ø> (ø) Carriedforward from 26f6487
pyamber 98.50% <ø> (ø) Carriedforward from 26f6487
workflow-compiling-service 78.30% <ø> (ø) Carriedforward from 26f6487

*This pull request uses carry forward flags. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@sshiv012 sshiv012 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.

LGTM @bobbai00, this is a quick review. Please merge if think its okay!

@bobbai00 bobbai00 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.

LGTM. @xuang7 @mengw15 please decide if we want to backport this fix

@mengw15 mengw15 removed the release/v1.3 back porting to release/v1.3 label Nov 9, 2026
@xuang7

xuang7 commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

Removing release/v1.2: the view count is still recorded.

@xuang7 xuang7 removed the release/v1.2 back porting to release/v1.2 label Nov 16, 2026

@bobbai00 bobbai00 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.

🟡 0 must-fix · 3 advisory · 0 polish: the fix is correct and stores anonymous views the way migration 13 does; three optional follow-ups.

Correctness (1)

  • HubResource.scala:423: count bump and audit insert still commit separately (advisory, see inline)

Simplifications (1)

  • HubResource.scala:422: null sentinel where an Option would do (advisory, see inline)

Conventions (1)

  • HubResourceSpec.scala:456: title length and scope (advisory, see inline)
Verification trace

Traced every userId the frontend sends to POST /hub/view: the uid decoded from the session token, or 0, from the four postView call sites. Null, 0 and negative values now become a NULL uid, which user_action.uid allows and sql/updates/13.sql already uses for old anonymous rows. Positive uids pass through unchanged. HubResourceSpec runs on MockTexeraDB, which loads sql/texera_ddl.sql, so the uid-0 case hits the real foreign key.

Takes the anonymous viewer as Option[Integer] instead of a null uid, and
writes the view count and its user_action row together, so a view that
cannot be recorded does not raise the count.
@tanishqgandhi1908 tanishqgandhi1908 changed the title fix(hub): record an anonymous view with a NULL uid instead of failing with 500 fix(amber): store anonymous hub views with a NULL uid Nov 17, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Viewing a public workflow, dataset or model while logged out returns 500, but the view count still increments

7 participants