Skip to content

Web: fix Patinae colour replay, command policy and picks, session recovery and the CIF tokenizer - #24

Open
AtharvaTilewale wants to merge 4 commits into
RosettaCommons:mainfrom
AtharvaTilewale:fix/web-patinae-viewer
Open

AtharvaTilewale wants to merge 4 commits into
RosettaCommons:mainfrom
AtharvaTilewale:fix/web-patinae-viewer

Conversation

@AtharvaTilewale

Copy link
Copy Markdown
Contributor

Builds on #20. The first commit here is #20 (CI fix); please review the commits after it. GitHub will drop it from this diff once #20 merges.

What this fixes

Patinae viewer

  • Colours moved to later selections. setColor logged color X, sele and applyBaseStyle replayed it against whatever sele was at replay time. Colours drifted to later selections and leaked into other documents. Colours are now recorded against the document atom indices selected when they were applied. The list is cleared on open, combine, structural edits and restore, and color all supersedes earlier entries. This adds an optional ViewerAdapter.clearColors(); Mol* is unaffected.
  • Command policy. The policy moves to studio/patinae-commands.ts. The deny-list gains align, biounit, copy, delete_states, materialize, reinitialize, set_name, setup_ccd, split_states and symexp, which create, rename or re-bond objects or move coordinates and so desync the viewer from the document. A test classifies all 91 commands in the shipped catalog.
  • Picks on non-document objects fell back to the native per-object index as a document index, selecting the wrong atom. Hits not in the identity map are now ignored.

Session lifecycle

  • Failed restore. A restore whose GET fails clears sessionId. Stored state is forgotten only on 404/403, so other errors can be retried. A session that loads but fails to display stays active and closable.
  • Open with a display failure now leaves the new session persisted with Download/Validate/Close enabled.
  • Combine now posts and refreshes inside the viewer update queue.

WASM CIF tokenizer (packages/core/src/lib.rs), per CIF 1.1

  • A quote closes a value only when followed by whitespace or EOF, so 'N'-ACE' works.
  • # starts a comment only at the start of a token, so A#1 is one value.
  • Semicolon text fields drop their final line terminator.

VS Code

  • annotationStudio.serverUrl is added to restrictedConfigurations, so an untrusted workspace can no longer point the webview at an arbitrary server.

Validation

  • Web unit tests: 51/51, with 11 new tests in packages/web/tests/*.test.ts, each failing on Fix CI: open rebuilt examples as Annotated CIF and protonate them #20's code.
  • VS Code tests: 7/7.
  • cargo test: 10 passed, with 4 new tokenizer tests. cargo fmt and clippy -D warnings are clean.
  • tsc --noEmit is clean.
  • Not run locally: the Playwright/e2e suites and backend-parity (no browser or WebGPU here), and the real wasm-pack build. tsc ran against a temporary .d.ts for the WASM module, which is not committed. The adapter tests use a recording stub in place of the WebGPU renderer, so CI's browser jobs are the real check for this PR.

Please note

  • Built assets are not rebuilt. The tracked bundle under packages/api/annotation_studio/web/ is unchanged, so installed users get these fixes only after make build. Tell me if you'd like the rebuilt bundle in this PR.
  • Behaviour change: quoted values that span lines are now rejected with "unterminated quoted CIF value", as CIF 1.1 requires. Previously they were silently accepted.
  • Not done:
    • A revision guard for combine needs expected_revision on the server CombineMutation.
    • Deleting the previous session on open is a product decision, because of shared ?session= links.

Copilot AI balanced review requested due to automatic review settings October 22, 2026 08:03

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

The unresolved critical host-readiness issue and moderate session-clearing issue must be addressed before approval.

1 open issue

Review effort: Lite

Comment thread packages/web/src/main.ts Resolved
@AtharvaTilewale

Copy link
Copy Markdown
Contributor Author

Thanks — addressed in the latest commit. On a terminal display failure (CIF/render parse error), the host is now notified on both the open path and the restore path, while the caller still rejects, and exactly one notification is sent when recovery succeeds. Three new session-lifecycle tests cover both failure paths and the no-duplicate guard.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Patinae selections can remain stale across document replacement, and the shipped fallback guide remains out of sync.

No open issues 🎉

1 resolved since last review

Review effort: Lite

@AtharvaTilewale

Copy link
Copy Markdown
Contributor Author

Thanks. On the two summary notes (no open threads):

  • Stale selection across document replacement: I traced every path where the document changes. Open, combine, structural edits (refreshFromServer(..., preserveSelection=false)), condition reset, and Undo when the atom count changes all call selectionController.clear(), which reaches PatinaeAdapter.clearSelection(). The only path that keeps the selection is renderer recovery, which reloads the same document. So I didn't find a reproducible stale-selection case and haven't changed code for it. Happy to add one if you have a sequence in mind.
  • Shipped guide out of sync: the bundled packages/api/annotation_studio/guide/ and browser bundle are regenerated in the release: commits rather than alongside docs edits (upstream main already has WEB.html older than WEB.md), so I've left them for the release build rather than committing regenerated HTML here.

Branch rebased onto the updated #20.

A workspace setting could point the Studio webview at an arbitrary server.
Only pythonPath was listed in restrictedConfigurations.
… CIF tokenizing

- Patinae colors: record the document atoms a selection color targets when it is
  applied and replay those (not the later contents of "sele"); "color all" supersedes
  earlier colors; clear the replay list on clearAllVisuals, comparison loads and destroy.
- Patinae commands: move the Studio command policy into studio/patinae-commands.ts and
  block catalog commands that create, rename or re-bond objects or move/drop coordinates
  (align, biounit, copy, delete_states, materialize, reinitialize, set_name, setup_ccd,
  split_states, symexp). A unit test classifies every command in the vendored catalog.
- Patinae picks on objects that are not in the document identity map are ignored instead
  of being reported as the same-numbered document atom.
- Session restore: forget the session id after a failed restore; only drop storage on
  404/403, and keep a session whose GET succeeded but whose display failed savable.
- Open: keep a session that cannot be displayed persisted with Download/Close enabled.
- Combine: run the combine POST and refresh inside the viewer update queue.
- CIF tokenizer: quotes close only before whitespace/EOF and cannot span lines, '#'
  starts a comment only at token start, and semicolon text fields drop the final line
  terminator.

The bundled assets under packages/api/annotation_studio/web/ are not rebuilt here.
When opening or restoring a session whose structure cannot be displayed,
execution previously skipped notifyHost("ready") on the terminal-failure
path, so an embedded host (e.g. VS Code) never received the session id and
timed out. Notify the host on both the open and restore failure paths while
still rejecting for the caller, and send exactly one notification when
recovery succeeds. Covered by new session-lifecycle regression tests.
…y point

main.ts and the Patinae adapter now import the design card, refold panel and
embed API, call requestAnimationFrame and read the page theme. The two
harnesses that load them under Node stub the new UI modules, resolve
directory imports to index.ts, substitute the __STUDIO_VERSION__ build
constant as Vite does, and give the fake window the dispatchEvent the embed
API uses. No assertions changed.
@AtharvaTilewale

Copy link
Copy Markdown
Contributor Author

Rebased onto current main (d7b78e4, 0.0.12). The earlier red CI was GitHub expiring the Oct 22 runs after 30 days awaiting approval; no job had run. CI on the rebased branch is green. The only failing job is the non-blocking integration acceptance suite, which fails the same single check on main ("a plain mmCIF opens as an entry does"), 36/37 in both.

Two conflicts needed porting rather than merging:

  • Colour replay: main moved the base style into buildStylePlan/runStylePlan, which still replayed raw color …, sele strings. Colours are now recorded against the document atoms they were applied to (colorOperations), and the plan and its signature are built from those records (colorCommandsForPlan).
  • Session restore: main's new restoreSession() already covers most of the original fix. I added only the case it lacked: the server returns the session but it can't be displayed. That session is now kept (Download/Close stay enabled) and the embedding host still gets ready.

The two Node test harnesses also needed to follow main.ts's new imports (design card, refold, embed API, __STUDIO_VERSION__); no assertions changed. Web unit tests: 130/130 here, and 10 of the 12 new ones fail against main's source.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants