Commit ·
d2f0ef7
1
Parent(s): fe22177
Deploy: fix GitLab encoding bug + align field names with pe-cu (Method_and_Decisions doc dropped, binary rejected by HF)
Browse filesFiles changed (5)
- .env.example+1-1
- PROJECT_LOG.md+44-22
- gitlab_save.py+4-1
- order_link.py+3-3
- web_app.py+12-12
24 unmodified lines2526272829303124 unmodified lines# the predetermined, exactly-alternating task-order allocation log (order_link.py,# gitlab_save.assign_task_order). Without this, task order falls back to an unkeyed local hash# per participant -- still works, but only approximately balanced, not exactly alternating.# SONA_GITLAB_PROJECT=princessamygdala/sona# SONA_GITLAB_TOKEN falls back to GITLAB_TOKEN above if unset (one token can cover several# projects); SONA_GITLAB_URL/SONA_GITLAB_BRANCH similarly fall back to GITLAB_URL/GITLAB_BRANCH.# SONA_GITLAB_TOKEN=glpat-xxxxxxxxxxxxxxxxxxxx24 unmodified lines2526272829303124 unmodified lines# the predetermined, exactly-alternating task-order allocation log (order_link.py,# gitlab_save.assign_task_order). Without this, task order falls back to an unkeyed local hash# per participant -- still works, but only approximately balanced, not exactly alternating.# SONA_GITLAB_PROJECT=princessamygdala/bear-sona# SONA_GITLAB_TOKEN falls back to GITLAB_TOKEN above if unset (one token can cover several# projects); SONA_GITLAB_URL/SONA_GITLAB_BRANCH similarly fall back to GITLAB_URL/GITLAB_BRANCH.# SONA_GITLAB_TOKEN=glpat-xxxxxxxxxxxxxxxxxxxx
306 unmodified lines307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338306 unmodified linesfails signature verification (e.g. someone opens its link directly) — verified end toend via a local dev server, including a deliberately-tampered signature being rejectedand correctly falling back to independent resolution rather than being trusted.- **Every session now records its own `task_order_first` / `task_order_position` (1 or 2)/ `task_order_source`** (`"shared_log"`, `"hash_fallback"`, or `"handoff"`) in the savedmetadata — per the same reviewer's point: without this, reconstructing whichcounterbalancing scheme a given participant's session actually used (exact vs.approximate, and which task resolved it) is only possible by re-deriving it later, whichafter the fallback-disagreement bug above is exactly the thing that can't bereconstructed from outside the session. `task_pe-cu-nicewebrl` records the matchingfields (`task_first`/`task_position`/`task_order_source`) on its own side.## 7. In progress / open items- **Deploy status (2026-09-26): items 1-35 pushed to `origin`/`hf`; items 36-37 (SONA infra)not yet pushed** — see the commit history for exactly what's landed by the time you read this.Needs `OTHER_TASK_BASE_URL` and `SONA_PID_HASH_KEY` (item 36) plus `SONA_GITLAB_PROJECT` +`SONA_GITLAB_TOKEN` (item 37) set as HF Space secrets before the combined flow works live atfull strength (see `.env.example`). Every piece degrades independently rather than breaking:`OTHER_TASK_BASE_URL` unset -> no next-task link shown (this task behaves exactly as it didbefore this feature existed); `SONA_PID_HASH_KEY` unset -> pid falls back to the raw codewith a loud warning (NOT safe for real data collection, but keeps a local test run working);`SONA_GITLAB_PROJECT` unset -> task order falls back to the local hash (works, just onlyapproximately balanced, not exactly alternating) — recorded as such via `task_order_source`.- **The new `sona` GitLab repo does not exist yet.** Needed for item 37 (the task-orderallocation log) and, later, the payment store. This session's GitLab helper only pushes toan EXISTING project — creating one needs the user (or a token scoped to create projects,which is broader than what's configured for anything else in this repo). Once it exists,both this task's and `task_pe-cu-nicewebrl`'s `.env` need `SONA_GITLAB_PROJECT` (+ token)pointed at it.- **Input-drop limitation (item 33) is unresolved and out of this repo's control** — flaggingfor awareness, not a to-do: if it becomes a real problem in the lab, the options are asking kidsto pace their presses, or forking/patching the vendored `nicewebrl` package (bigger undertaking,306 unmodified lines307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360306 unmodified linesfails signature verification (e.g. someone opens its link directly) — verified end toend via a local dev server, including a deliberately-tampered signature being rejectedand correctly falling back to independent resolution rather than being trusted.- **Every session now records its own `task_first` / `task_position` (1 or 2) /`task_order_source`** (`"shared_log"`, `"hash"`, or `"handoff"`) in the saved metadata —per the same reviewer's point: without this, reconstructing which counterbalancing schemea given participant's session actually used (exact vs. approximate, and which taskresolved it) is only possible by re-deriving it later, which after the fallback-disagreement bug above is exactly the thing that can't be reconstructed from outside thesession. Field names (and the `"hash"` string, not `"hash_fallback"`) settled jointly with`task_pe-cu-nicewebrl`, which records the same fields, so a combined-analysis script neverneeds per-task column renaming.- **The `bear-sona` GitLab project was created** (2026-09-26, same day, with the user) —`princessamygdala/bear-sona` on `gitlab.com`, private, a Developer-role project accesstoken (needed `main`'s branch protection widened from "Maintainers" to "Developers +Maintainers" for "allowed to push", since the token's writes were otherwise silentlyrejected with 403). `SONA_GITLAB_PROJECT`/`SONA_GITLAB_TOKEN` written directly to bothtasks' `.env` from the clipboard (never displayed in chat); `OTHER_TASK_BASE_URL` (cross-referenced: each task's `.env` points at the OTHER task's real HF Space) and a freshlygenerated `SONA_PID_HASH_KEY` (identical in both) written the same way.- **A real bug, found only by testing against the live `bear-sona` repo, not the mock**:`assign_task_order`'s POST/PUT bodies never set `"encoding": "base64"`. GitLab's single-file API defaults to `encoding: "text"` when it's omitted, so the base64 string this codesends as `content` was stored LITERALLY instead of being decoded — every write silentlycorrupted the log into double-base64-encoded gibberish, which then parsed as nonsense CSVand threw the alternation count off. The mocked test from the CAS work above didn't catchthis because the mock always decoded `content` as base64 regardless of the `encoding`field — it was faithful to what the code SHOULD do, not to what GitLab ACTUALLY doeswithout that field. Fixed both: `assign_task_order` now sends `encoding: "base64"`explicitly, and the mock was corrected to only decode when that field is present (so thisclass of bug fails the mock too, next time). Re-verified end to end against the real repo:clean alternation over several real writes, correct idempotent re-lookup, and a session'ssaved data showing `task_order_source: shared_log` (not the hash fallback) for the firsttime. Lesson: a mock that encodes the same assumption the code under test makes will passeven when that assumption is wrong — this one needed a real API round-trip to surface.## 7. In progress / open items- **Deploy status (2026-09-26): items 1-35 pushed to `origin`/`hf`; items 36-37 (SONA infra)not yet pushed** — see the commit history for exactly what's landed by the time you read this.`SONA_GITLAB_PROJECT`/`SONA_GITLAB_TOKEN`/`OTHER_TASK_BASE_URL`/`SONA_PID_HASH_KEY` are allset in this machine's local `.env` (and the matching values in `task_pe-cu-nicewebrl`'s), but**still need to be added as HF Space secrets on both live Spaces** before the combined flowworks in production — a local `.env` is not read by the deployed Space. Every piece degradesindependently rather than breaking if a secret is missing there too: `OTHER_TASK_BASE_URL`unset -> no next-task link shown (this task behaves exactly as it did before this featureexisted); `SONA_PID_HASH_KEY` unset -> pid falls back to the raw code with a loud warning (NOTsafe for real data collection); `SONA_GITLAB_PROJECT` unset -> task order falls back to thelocal hash (works, just only approximately balanced) — recorded as such via `task_order_source`.- **`princessamygdala/bear-sona` (item 37) exists now** — private, on `gitlab.com`, holding thetask-order allocation log; will also hold the payment store once that's designed. Both tasks'local `.env` point at it already.- **Input-drop limitation (item 33) is unresolved and out of this repo's control** — flaggingfor awareness, not a to-do: if it becomes a real problem in the lab, the options are asking kidsto pace their presses, or forking/patching the vendored `nicewebrl` package (bigger undertaking,
200 unmodified lines201202203204205206207200 unmodified linesrows.append({"survey_code": str(survey_code), "first_task": next_first,"assigned_utc": _now_iso()})content = _serialize(rows)body = {"branch": branch, "content": content,"commit_message": f"task-order assignment: {survey_code}"}url = f"{base}/api/v4/projects/{pid}/repository/files/{quote(path, safe='')}"if text is None:200 unmodified lines201202203204205206207208209210200 unmodified linesrows.append({"survey_code": str(survey_code), "first_task": next_first,"assigned_utc": _now_iso()})content = _serialize(rows)# encoding=base64 is required: without it GitLab's single-file API defaults to "text"# and stores our base64 STRING literally as the file's content, rather than decoding# it -- the file then contains base64-encoded gibberish instead of the CSV.body = {"branch": branch, "content": content, "encoding": "base64","commit_message": f"task-order assignment: {survey_code}"}url = f"{base}/api/v4/projects/{pid}/repository/files/{quote(path, safe='')}"if text is None:
63 unmodified lines6465666768697012 unmodified lines8384858687888928 unmodified lines11811912012112212312463 unmodified linesdef first_task(survey_code):"""(value, source) -- "sl"/"pe", and "shared_log" or "hash_fallback" saying how it wasresolved (record BOTH in the session's own saved data -- see web_app.py -- so animbalanced fallback is visible in the data itself rather than something that has to bereconstructed later). Blocking (does network I/O via the shared allocation log); call via12 unmodified linesf"shared task-order log unavailable for survey_code={survey_code!r} -- falling back ""to a local hash (only approximately balanced, not exactly alternating). Set ""SONA_GITLAB_PROJECT (+ SONA_GITLAB_TOKEN or GITLAB_TOKEN) to fix.")return _hash_fallback(survey_code), "hash_fallback"def am_i_first(survey_code):28 unmodified linesas "no next task".`first_task_value` must be the value THIS task already resolved for this participant (itsown app.storage.user["task_order_first"]), not re-derived here."""base = os.getenv(OTHER_TASK_URL_ENV, "").strip().rstrip("/")if not base:63 unmodified lines6465666768697012 unmodified lines8384858687888928 unmodified lines11811912012112212312463 unmodified linesdef first_task(survey_code):"""(value, source) -- "sl"/"pe", and "shared_log" or "hash" saying how it wasresolved (record BOTH in the session's own saved data -- see web_app.py -- so animbalanced fallback is visible in the data itself rather than something that has to bereconstructed later). Blocking (does network I/O via the shared allocation log); call via12 unmodified linesf"shared task-order log unavailable for survey_code={survey_code!r} -- falling back ""to a local hash (only approximately balanced, not exactly alternating). Set ""SONA_GITLAB_PROJECT (+ SONA_GITLAB_TOKEN or GITLAB_TOKEN) to fix.")return _hash_fallback(survey_code), "hash"def am_i_first(survey_code):28 unmodified linesas "no next task".`first_task_value` must be the value THIS task already resolved for this participant (itsown app.storage.user["task_first"]), not re-derived here."""base = os.getenv(OTHER_TASK_URL_ENV, "").strip().rstrip("/")if not base:
771 unmodified lines7727737747757767777783 unmodified lines782783784785786787788108 unmodified lines89789889990090190290390490547 unmodified lines953954955956957958959318 unmodified lines12781279128012811282128312846 unmodified lines129112921293129412951296129712981299130013011 unmodified line13031304130513061307130813091310131113121313771 unmodified linesasync def run_intro(container):# Combined-SONA-study consent, before anything else -- but only on whichever task this# participant lands on FIRST (task_order_first, resolved once per session in index() via# order_link.first_task/gitlab_save.assign_task_order). The second task trusts the first# task already showed it: app.storage.user is per-origin, so a "consented" flag set in the# other app's storage never reaches here to check directly. Skipped entirely unless the3 unmodified linescombined_study_active = (app.storage.user.get("study") == "sona"and bool(os.getenv(order_link.OTHER_TASK_URL_ENV, "").strip()))if combined_study_active and not app.storage.user.get("consented"):if app.storage.user.get("task_order_first") == order_link.THIS_TASK:if not await Q.consent_screen(container):nicewebrl.clear_element(container)with container.style("align-items:center; max-width:600px;"):108 unmodified lines# The SONA return URL needs the raw SONA code, not the pseudonymised stored pid (see# _pid_pseudonym) -- SONA itself needs the raw code back to grant credit.survey_code = app.storage.user.get("survey_code") or pid# task_order_first was resolved once, in index(), via order_link.first_task (network I/O# against the shared allocation log) -- reused here rather than re-querying.sona_first = (app.storage.user.get("task_order_first") == order_link.THIS_TASK) if is_sona else True# Combined-SONA-study only: general self-report measures (demographics, TriPM) run once,# for whichever task the participant finishes SECOND -- these belong to the combined study,47 unmodified lines# return to SONA for credit (if this one ran second, after the general measures above).# Falls through to the existing Prolific/lab endings below if OTHER_TASK_BASE_URL or the# ?sona= completion URL aren't configured, rather than leaving the participant stuck.first_value = app.storage.user.get("task_order_first") or ""if is_sona and sona_first and order_link.other_task_url(survey_code, app.storage.user.get("sona_url") or "", first_value):next_url = order_link.other_task_url(survey_code, app.storage.user.get("sona_url") or "", first_value)ui.markdown("### Thank you! Please continue to Part 2.")318 unmodified linescombined_study_active = is_sona_q and bool(os.getenv(order_link.OTHER_TASK_URL_ENV, "").strip())# Resolve which task this participant sees first ONCE per session, then cache it# (task_order_first/task_order_source, both recorded in the saved session data so the order# actually used -- and how it was resolved -- is visible in the data itself rather than# something to reconstruct later).#6 unmodified lines# skip the end-of-study general measures. See order_link.py's module docstring.# 2. Resolve directly (shared-log-then-hash) when there's no handoff to trust -- this# participant is visiting FIRST, or opened this task's link directly with no handoff.if combined_study_active and app.storage.user.get("survey_code") and "task_order_first" not in app.storage.user:first_q = (request.query_params.get("first") or "").strip().lower()fsig_q = (request.query_params.get("fsig") or "").strip()if order_link.verify_signed_first(app.storage.user["survey_code"], first_q, fsig_q):app.storage.user["task_order_first"] = first_qapp.storage.user["task_order_source"] = "handoff"else:try:1 unmodified lineorder_link.first_task, app.storage.user["survey_code"])except Exception as e:logger.warning(f"order_link.first_task failed, using local hash fallback: {e}")resolved, source = order_link._hash_fallback(app.storage.user["survey_code"]), "hash_fallback"app.storage.user["task_order_first"] = resolvedapp.storage.user["task_order_source"] = sourceapp.storage.user["task_order_position"] = (1 if app.storage.user["task_order_first"] == order_link.THIS_TASK else 2)# dyad mode: parent/child pairs, e.g. ?dyad_mode=yes. OFF by default -- a single-participant# sample (SONA pilot) has no counterpart, so the role picker and the hypothetical771 unmodified lines7727737747757767777783 unmodified lines782783784785786787788108 unmodified lines89789889990090190290390490547 unmodified lines953954955956957958959318 unmodified lines12781279128012811282128312846 unmodified lines129112921293129412951296129712981299130013011 unmodified line13031304130513061307130813091310131113121313771 unmodified linesasync def run_intro(container):# Combined-SONA-study consent, before anything else -- but only on whichever task this# participant lands on FIRST (task_first, resolved once per session in index() via# order_link.first_task/gitlab_save.assign_task_order). The second task trusts the first# task already showed it: app.storage.user is per-origin, so a "consented" flag set in the# other app's storage never reaches here to check directly. Skipped entirely unless the3 unmodified linescombined_study_active = (app.storage.user.get("study") == "sona"and bool(os.getenv(order_link.OTHER_TASK_URL_ENV, "").strip()))if combined_study_active and not app.storage.user.get("consented"):if app.storage.user.get("task_first") == order_link.THIS_TASK:if not await Q.consent_screen(container):nicewebrl.clear_element(container)with container.style("align-items:center; max-width:600px;"):108 unmodified lines# The SONA return URL needs the raw SONA code, not the pseudonymised stored pid (see# _pid_pseudonym) -- SONA itself needs the raw code back to grant credit.survey_code = app.storage.user.get("survey_code") or pid# task_first was resolved once, in index(), via order_link.first_task (network I/O# against the shared allocation log) -- reused here rather than re-querying.sona_first = (app.storage.user.get("task_first") == order_link.THIS_TASK) if is_sona else True# Combined-SONA-study only: general self-report measures (demographics, TriPM) run once,# for whichever task the participant finishes SECOND -- these belong to the combined study,47 unmodified lines# return to SONA for credit (if this one ran second, after the general measures above).# Falls through to the existing Prolific/lab endings below if OTHER_TASK_BASE_URL or the# ?sona= completion URL aren't configured, rather than leaving the participant stuck.first_value = app.storage.user.get("task_first") or ""if is_sona and sona_first and order_link.other_task_url(survey_code, app.storage.user.get("sona_url") or "", first_value):next_url = order_link.other_task_url(survey_code, app.storage.user.get("sona_url") or "", first_value)ui.markdown("### Thank you! Please continue to Part 2.")318 unmodified linescombined_study_active = is_sona_q and bool(os.getenv(order_link.OTHER_TASK_URL_ENV, "").strip())# Resolve which task this participant sees first ONCE per session, then cache it# (task_first/task_order_source, both recorded in the saved session data so the order# actually used -- and how it was resolved -- is visible in the data itself rather than# something to reconstruct later).#6 unmodified lines# skip the end-of-study general measures. See order_link.py's module docstring.# 2. Resolve directly (shared-log-then-hash) when there's no handoff to trust -- this# participant is visiting FIRST, or opened this task's link directly with no handoff.if combined_study_active and app.storage.user.get("survey_code") and "task_first" not in app.storage.user:first_q = (request.query_params.get("first") or "").strip().lower()fsig_q = (request.query_params.get("fsig") or "").strip()if order_link.verify_signed_first(app.storage.user["survey_code"], first_q, fsig_q):app.storage.user["task_first"] = first_qapp.storage.user["task_order_source"] = "handoff"else:try:1 unmodified lineorder_link.first_task, app.storage.user["survey_code"])except Exception as e:logger.warning(f"order_link.first_task failed, using local hash fallback: {e}")resolved, source = order_link._hash_fallback(app.storage.user["survey_code"]), "hash"app.storage.user["task_first"] = resolvedapp.storage.user["task_order_source"] = sourceapp.storage.user["task_position"] = (1 if app.storage.user["task_first"] == order_link.THIS_TASK else 2)# dyad mode: parent/child pairs, e.g. ?dyad_mode=yes. OFF by default -- a single-participant# sample (SONA pilot) has no counterpart, so the role picker and the hypothetical
.env.example+1-1
PROJECT_LOG.md+44-22
gitlab_save.py+4-1
order_link.py+3-3
web_app.py+12-12