Skip to content

The Platform Bridge: per-teacher Connections with an encrypted session store, Push and Pull only as Operations

Status: proposed (2026-10-01) — provisional by the maintainer’s explicit marking; the fences are explicitly revisitable as inter-platform experience grows.

The mandated external platforms (Xuexitong, iTest) are driven from emergent through the Platform Bridge: a teacher’s authenticated Connection, the recorded counterpart of each pushed object, and the Push and Pull Operations. The Bridge is not a sync rail: nothing moves without an Operation, and the student-facing graded step stays where the department requires it.

A Connection is one teacher’s authenticated link to one platform, person-scoped and never shared. Login form primary: the API performs the platform’s own login server-side (Xuexitong’s passport2 flow is analysed in the teaching repo — a static AES key on the credentials, a needVcode captcha flag that is risk-triggered, and a seven-day session valid across every chaoxing.com host), with a captcha relay in the same dialog when the platform demands one. Cookie paste is the fallback, the existing DevTools chore moved into emergent. iTest starts paste-only until its login flow is analysed the same way. The popup-on-the-platform’s-own-login- page variant is impossible by construction: the platform’s cookies belong to its origin, so emergent must perform the login itself for the session to be usable by the API and its workers.

Storage of the session is accepted with four conditions. The password is used transiently and never stored; only the session jar is stored, encrypted per teacher with a key held in Supabase Vault, not in the application; the row is readable only by its owning teacher under RLS and the API decrypts solely to act as that teacher; revocation is deleting the row. The residual risk (a database dump plus key compromise exposing a week-long session over 教务-linked rosters) is accepted as the reasonable bar for this data; a cached jar with a weekly manual re-login remains the fallback whenever the scripted login is refused.

All bridge operations are teacher-invoked. Tasks carry the buttons; they do not pull the trigger. Automatic or scheduled execution is deliberately undesigned and gets its own authorisation, audit and dry-run story before it exists. The CLI’s fences become the Bridge’s fences: the single permitted publish route, no exam publishing, no exposed deletes, publishes behind a dry-run preview — and these fences are time-limited, to be revisited “when we have more experience with the inter-platform interactions” (maintainer, 2026-10-01). Pulls land in canonical models (Gradebook Entries, external item marks, Survey Responses), attributed to Persons by student number. The v1 toolbox is what the teaching repo’s tools already do: Xuexitong push (问卷 create/update/ reissue, 作业 create and publish, files to 资料 and 云盘), Xuexitong pull (作业 results, 问卷 answers), iTest pull (task results) and iTest push (papers and class tests).

These choices bound the current implementation; they do not promote this proposed ADR or invent a maintainer policy for account switching and autonomous platform work.

  • The initial slice implements owner metadata, session paste, explicit checks, reconnect and physical revocation. Password login remains unavailable until browser-session coexistence and the actual behavioural-captcha relay contract are exercised. The analysed seven-day token is an observation, not a guaranteed lifetime for every jar. Copy-as-cURL does not include original cookie attributes; pasted cookies start with a narrow approved host/path, while actual response cookies retain their domain/path/expiry through a maintained jar. Additional host access needs explicit scope evidence.
  • Known authenticated listings verify session access but do not independently prove the account’s identity. Cookie IDs, course owners and paper owners are not substituted for a self-identity probe. Account metadata may remain unavailable. A deliberate version-checked reconnect from unknown to unknown may replace the stored session; known-to-different or known-to-unknown is refused. Later Push/Pull target readiness must be re-established after replacement, using actual target/owner evidence rather than preserving an authorization conclusion from the previous jar.
  • Connection data stays server-only, outside sync and offline stores. Native owner RLS supplies an independent boundary; client roles receive no table grant. The Operations metadata DTO carries neither encrypted jars nor key references. Former teachers may list and revoke their own rows through an authenticated owner route; new sessions and probes require current teaching authority. Existing explicit teacher/assistant grants on personal Offerings count as teaching authority; this slice introduces no institutional-only eligibility rule.
  • A short transaction reserves a version and opaque pending generation; the remote probe has no open database transaction. Final persistence rechecks authority and updates only that generation. Revoke or Person erasure therefore cannot be undone by a late probe. Failed replacement preserves the previous usable jar. This is not a transactional rollback guarantee for later remote writes.
  • A per-teacher key mapping and Vault provisioning participate in the reservation transaction. Decryption uses a separate Bridge-only mapped-key reader, never the credential signing roles. Last-Connection revocation and Person erasure delete the exact mapped Vault secret atomically. Actual Vault privilege/atomicity proof remains distinct from native fixture execution.

Operator setup and the current teacher workflow are recorded in the Connections runbook.

The D3 implementation preserves native Score/Attempt semantics and records attempt-less external item marks as External Item Results; aggregate marks use Gradebook Entries. The current design, source attribution, ownership and Survey follow-up are in the Pull design.

The D4a Survey draft implementation uses a private durable intent/step ledger: the started marker commits before each provider effect, and verified receipts commit before continuation. Uncertain effects survive lease expiry, reconnect, revocation and erasure; explicit reconciliation makes only reads. The Push design records the exact source, target, mapping and session-preparation contracts; the Push runbook describes the teacher workflow. Work/files, iTest and unproved Survey reissue remain subsequent work.

  • A popup that logs in on the platform’s own page. Rejected as impossible cross-origin (its cookies are unreadable by emergent and absent from emergent’s requests), not merely inconvenient.
  • Storing the password (or a long-lived credential) for unattended login. Rejected: the platform docs themselves advise against a stored credential for accounts with 教务-linked rosters; a cached jar plus reconnect-on-expiry is the honest mechanism.
  • Bespoke per-feature bridge code instead of Operations. Rejected: bridges are exactly the commands the Operations catalogue exists for (audit, permissions, one transport story).
  • Autonomous execution now (open the survey Friday at 17:00 without a hand). Deferred by the maintainer’s explicit fence; the Task/Reminder core (ADR-0030 update) makes the teacher the trigger until the authorisation model is designed.
  • A connection store (encrypted jars, RLS owner-only, Vault-held key), a reconnect UX for the weekly expiry, and the captcha relay are real build items before the first Push.
  • Before relying on the login form: test forbidotherlogin (a scripted login must not boot the maintainer’s browser session) and exercise the needVcode=1 path; both are recorded risks in the teaching repo’s platform docs.
  • Counterpart mappings (workLibraryId, taskId, activeId, paperId, folder ids) are Bridge state attached to the pushed object; re-push updates rather than duplicates where the platform allows (the 云盘 index lag and non-idempotent panFolder are known traps to encode, not rediscover).
  • Responses are verified (status, ids) rather than assumed; the platform docs call the endpoints undocumented and non-contractual, so a smoke test rides with each operation.
  • Bridge work runs server-side in the API (workers where needed); clients never hold platform sessions.