Skip to content

Human Confidence web example in client side and server side modes - #271

Draft
jwrosewell wants to merge 8 commits into
rcfrom
feature/humanconfidence-web-demo
Draft

jwrosewell wants to merge 8 commits into
rcfrom
feature/humanconfidence-web-demo

Conversation

@jwrosewell

@jwrosewell jwrosewell commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

What this is

The Human Confidence web example reworked as a demo, for work to continue on it.

  • The page shows HumanConfidenceSource and HumanConfidence in a table. Both rows are in place from the start, each with a running timer until its level arrives, so nothing on the page moves.
  • Client side (?mode=client). The browser loads the 51Degrees client script from the cloud and this server redeems the sealed result with the License Key. Client side has no passive row, as the passive level is read by this server, so it is shown server side.
  • Server side (?mode=server). The browser never calls the cloud. This server serves the client script with every cloud address pointed at itself and sends the calls on through the cloud request engine. The passive row comes from the visitor's request.
  • A toggle reloads the page in the other mode, kept in a cookie. Under the table are two curl commands, for PowerShell or bash, that replay the passive data and the active data from a terminal, and a link to the Configurator.
  • The client script's third party cookie check is pointed at the cloud named in _51DEGREES_CLOUD_ENDPOINT by setting window.fodTpcEndpoint, because it otherwise goes to the public cloud.
  • A row shows the level it was given, Unknown included. A row that gets no level shows No result, which covers a failed call and a client script that does not load. If the cloud refuses a sealed value, the Active row shows Low, and a line under the table says so. A redeem call that does not happen, or that this server has not answered in 15 seconds, shows No result. At 30 seconds a row with no level says No result, unless a redeem is still running.
  • The address sent to the cloud as client-ip is the connection's own address, when it is a public one.
  • After it starts, the example writes nothing to the console.

Files: app.py and templates/index.html.

How to run it

python -m fiftyone_pipeline_examples.cloud.humanconfidence_web

Set _51DEGREES_RESOURCE_KEY to a key that carries HumanConfidence and HumanConfidenceSource, _51DEGREES_LICENSE_KEY to a License Key on the same account, and _51DEGREES_CLOUD_ENDPOINT to a cloud that offers the redeem call (POST /api/v4/hc/redeem), which the public cloud does not offer yet. Then open http://localhost:5151/.

How it was checked

By hand, against a cloud that offers the redeem call, in headless Edge.

  • Both modes load with both rows and both command boxes in place. The page height was the same at load and after the result (916 client side, 1107 server side).
  • Active arrived after 3.8 seconds client side and 4.8 seconds server side, and every redeem succeeded.
  • Every request the browser made, recorded in both modes, went to the cloud named in _51DEGREES_CLOUD_ENDPOINT or to this server.

Still to do

  1. The redeem belongs in the package, not the example. The cloud request engine should redeem the sealed value itself and give HumanConfidence directly, so the example only reads HumanConfidenceSource and HumanConfidence. The /redeem route in app.py is the stand-in until then. FIX: Redeem a sealed Human Confidence value in the cloud request engine #274, opened against this branch, does this.

  2. The example's tests are in line with this version. Locally 101 pass and 4 skip. The 4 are the live tests, which need _51DEGREES_RESOURCE_KEY_BESPOKE and _51DEGREES_RESOURCE_KEY_BASIC, and they were not run.

  3. No workflow runs these tests on a pull request that touches only the examples, so the checks here say nothing about them. Run them by hand from pipeline/fiftyone_pipeline_cloudrequestengine/examples:

    pytest tests/test_cloud_humanconfidence_web_offline.py tests/test_cloud_humanconfidence_web_port.py tests/test_cloud_humanconfidence_web.py
    

Since 8357555

Two commits on top of 8357555.

The first:

  • The page shows Unknown as Unknown, where it showed Low, and shows No result for a passive answer that is not a level, a failed fetch, and a client script that does not load.
  • At the 30 second limit, the page waits for a redeem that is still running.

The second:

  • /redeem gives Low only when the cloud answers 200 or 400 with no level, which is how it refuses a sealed value. An unreachable cloud, a timeout, any other status, or an answer that is not a JSON object gives no level, and the page shows No result, as the .NET and Rust pages do. Before, a cloud without the redeem call, which today includes https://cloud.51degrees.com/api/v4/, gave Active Low on every visit.
  • The page stops waiting for /redeem after 15 seconds and shows No result.
  • The live Basic key test makes the passive call itself, naming HumanConfidence and HumanConfidenceSource, and expects humanconfidencesource to be present and null with a string humanconfidencesourcenullreason, as the .NET and Rust live tests do. The passive level test accepts only High, Medium and Low, also as they do.

On Windows with Python 3.12, the three test files above give 101 passed and 4 skipped, where they gave 88 passed and 4 skipped at 8357555. The 4 are the live tests, which need keys. The page script was also run under Node with a stand-in page.

Since 4daa4eb

A merge of rc (6e5c98c). Only tests/test_cloud_humanconfidence_web.py conflicted.

  • The two tests of HumanConfidenceSource are marked staging and call the cloud that CLOUD_STAGING_ENDPOINT names, so cloud-human-confidence.yml (pytest -m staging) runs both. The Bespoke test uses RESOURCE_KEY_BESPOKE_STAGING, reads the source from the cloud's recorded answer, as /passive gives only the level, and expects Passive. It also checks the level and the address the example describes, without printing the key. The Basic key test keeps this branch's direct call to the cloud.
  • The passive level test that ran on the cloud _51DEGREES_CLOUD_ENDPOINT names is now part of the Bespoke staging test, as rc had done with its own. rc's Basic key test, and the checks at the end of the file that read a source from the example, are gone.
  • The fixture that names the two properties matches the address without its query and records the cloud's answers.
  • A new offline test checks that both source tests carry the staging mark.
  • No test was run on the merge before this push. The levels accepted stay High, Medium and Low, so the staging test fails if the staging cloud answers Unknown to a passive call.

Before this leaves draft

Not ready to merge until these are done.

  1. Merge by squash, with a new message.
  2. Whether a redeem that the cloud refuses with a status other than 200 or 400, such as 401 or 403, shows Low or No result. It shows No result now. The cloud's redeem call and the draft specification in Specify how a package redeems a sealed Human Confidence level specifications#201 settle that.
  3. The page test checks lines of the template, not what the page does.
  4. #274, which item 1 of "Still to do" names, now conflicts with this branch in app.py, templates/index.html and tests/test_cloud_humanconfidence_web_offline.py, and has to take these changes.
  5. Cloud Human Confidence passes at this head, with both staging tests run and none skipped.
  6. Whether the passive level test should also run on the production cloud, as it did before this merge.

The page shows HumanConfidenceSource and HumanConfidence in a table whose
rows are in place from the start, each with a running timer until its
level arrives, so nothing on the page moves.

Client side, the browser loads the 51Degrees client script from the cloud
and this server redeems the sealed result with the License Key. There is
no passive row client side, because a passive result passed on by the
browser could have been changed.

Server side, the browser never calls the cloud. This server serves the
client script with every cloud address pointed at itself and sends the
calls on through the cloud request engine. The passive row comes from the
visitor's request.

A toggle reloads the page in the other mode, and the choice is kept in a
cookie. Under the table are two curl commands that replay the passive data
and the active data from a terminal, and a link to the Configurator.

The third party cookie check in the client script is pointed at the cloud
named in _51DEGREES_CLOUD_ENDPOINT, as it otherwise goes to the public
cloud.
jwrosewell and others added 4 commits November 23, 2026 16:25
The page recorded the browser test answers only when they were sent to a
51degrees.com address, and server side only 51degrees.com addresses in the
client script were pointed back at this server. With a private cloud, such
as one in Docker at a localhost address, the active replay never filled,
and server side the browser sent the test answers to its own machine.

Both checks now take the host of the endpoint in use as well as the
51Degrees cloud hosts, and a call sent on to the endpoint's own host keeps
the endpoint's scheme, so a plain http private cloud works.
The page redeemed every HumanConfidence value the 51Degrees script gave through fod.onChange. The first one comes before the browser tests have run and is a plain level, which the cloud can't open, so the redeem answered unreadable and the page showed Active Low. When the test answers then didn't arrive, or the page was left early, Low stayed on the page for tests that never ran.

The page now redeems only a value that isn't a plain level (High, Medium, Low, or Unknown), so Active shows a level only once the tests have run and their result is sealed.
Now that only a sealed value is redeemed, a page whose test answers never reach the cloud waited for ever, with the Active timer running on. After 30 seconds with no sealed value the row now says No result. A sealed value that arrives later still replaces it.
After it starts, the Human Confidence web example writes nothing to the
console. /redeem no longer prints each outcome, the web server no longer
logs each request, and /hc/script.js answers 502 with an empty script
when the cloud can't be reached, so the page shows Active Low.

The cloud request engine is built with the example's 10 second timeout,
its evidence keys give the headers passed on, and its answer is read
under cloud-response. The address sent as client-ip is the connection's
own, when it is a public one, and the replay command shows the form the
engine sent. The start-up error shows the Resource Key as <Resource
Key>, and the header comment says what redeeming needs and gives.

The three test files now test the example as it is. 88 pass, and the 4
live tests skip with no keys set.
The web demo page showed Low for Unknown and for a passive call that
gave no level. Unknown now shows as Unknown, in the neutral style.
A passive answer that is not a level, a failed fetch, a client script
that does not load and a failed redeem fetch show No result. A line
under the table says that Active Low is also given when the sealed
value cannot be redeemed. The /redeem route is unchanged, so a value
that does not redeem still gives Low.

At the 30 second limit the page shows No result only when no redeem
is still running, so a redeem that is under way can still give its
level.

The live Basic key test no longer accepts an answer with no
HumanConfidence. It asks the cloud whether the key carries the
property. If it does, the passive answer must be a level. If it does
not, the example must stop at start with the contact link. Offline
tests run the live test against the stand-in cloud for a pass and a
failure of each.
The /redeem route gave Low for every failure, so a cloud without the
redeem call showed Active Low on every visit. Low is now given only
when the cloud answers 200 or 400 with no level, which is how it
refuses a sealed value. Any other answer, or none at all, gives no
level, and the page shows No result, as the .NET and Rust examples
do. The page also stops waiting for /redeem after 15 seconds. The
comments, the start-up message and the line under the table say the
same.

The live Basic key test makes the passive call itself, naming
HumanConfidence and HumanConfidenceSource, as the .NET and Rust live
tests do. It expects humanconfidencesource to be present and null and
humanconfidencesourcenullreason to be a string. The passive level
test accepts only High, Medium and Low, also as in .NET and Rust.
Offline tests run the Basic key test against the stand-in cloud.
This merge takes rc into the branch. Only
tests/test_cloud_humanconfidence_web.py conflicted, where rc moved the
HumanConfidenceSource tests to the staging cloud and the branch had
changed the same tests.

The two tests of the source are now marked staging and call the cloud
CLOUD_STAGING_ENDPOINT names. The Bespoke test uses the key in
RESOURCE_KEY_BESPOKE_STAGING. As /passive gives only a level, it reads
HumanConfidenceSource from the cloud's recorded answer and expects
Passive, and it checks the level and the address the example describes
without printing the key. The Basic key test keeps the branch's direct
call to the cloud. rc's own Basic key test, and the checks at the end of
the file that read a source from the example, are gone.

The fixture that names the two properties matches the address without
its query, as the engine posts to <key>.json?, and records the cloud's
answers. An offline test checks that both source tests carry the
staging mark, so the Cloud Human Confidence workflow has tests to run.
@jwrosewell jwrosewell mentioned this pull request Nov 25, 2026
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