Skip to content

OpenConceptLab/ocl_online#786 | Algorithm replies apply to the current list - #139

Merged
snyaggarwal merged 2 commits into
mainfrom
ocl_online-786-verify-custom-algo
Nov 25, 2026
Merged

snyaggarwal merged 2 commits into
mainfrom
ocl_online-786-verify-custom-algo

Conversation

@snyaggarwal

@snyaggarwal snyaggarwal commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Fixes OpenConceptLab/ocl_online#786.

Problem

verifyCustomAlgorithm awaited the algorithm's URL, then called updateSelected, which mapped over normalizedValue from the render that sent the request. Any edit to the algorithm list made while the check was pending (another field, another algorithm added or removed) was overwritten by the reply. The bridge canonical URL fetch had the same problem: its .then called the updateSelected captured by an earlier effect run.

Change

  • MultiAlgoSelector keeps the current list in a ref (latestValueRef). updateSelected, removeSelected and adding an algorithm all build on it through commitValue, which updates the ref right away, so changes made before the parent re-renders build on each other.
  • The ref is set in a useLayoutEffect after each commit, and commitValue writes it straight away.
  • A custom algorithm check is dropped when a newer check for the same algorithm has started or the algorithm was removed. If its URL or token changed while the check was pending, the reply is dropped and only the loading state is cleared.
  • A bridge canonical URL reply is dropped when the algorithm was removed or its target_repo_url changed while the fetch was pending.
  • Pure helpers patchSelected, isStaleReply and customCheckReply in selectedAlgos.js, with tests.

Testing

  • npm test: 766 pass (11 new in selectedAlgos.test.js).
  • ESLint clean on the changed files.
  • Not exercised in the browser: reproducing the race needs a slow custom algorithm endpoint.

🤖 Generated with Claude Code

…t list: custom algorithm check and bridge canonical URL no longer overwrite edits made while pending

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
const checkId = (customCheckIdRef.current[key] || 0) + 1;
customCheckIdRef.current[key] = checkId;

const token = tokenOverride ?? selected?.token;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Nit (optional): The stale-reply check only compares the URL. If the user edits the token while a check is pending, a 401 for the old token can still set tokenRequired after they typed a new one. Fix: also drop the reply (clearing isLoading) when the current token differs from the one sent.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed: the check compares the URL and token sent with the current entry; a change only stops loading.

// (ocl_online#786). Each change sets it straight away, so changes made
// before the parent re-renders build on each other.
const latestValueRef = React.useRef(normalizedValue)
latestValueRef.current = normalizedValue

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Nit (optional): latestValueRef is written during render. A render React discards under concurrent rendering can leave the ref holding a list that was never committed. Fix: assign it in a useLayoutEffect on normalizedValue, keeping commitValue's synchronous write.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed: the ref is set in a useLayoutEffect; commitValue still writes it straight away.

assert.equal(next[0].description, 'typed while waiting')
assert.equal(next[0].id, 'x')
assert.equal(next[1], search)
assert.notEqual(next, atRequest)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Nit (optional): assert.notEqual(next, atRequest) always passes, since patchSelected never receives atRequest. The reply decision (newer check, removed, URL changed) lives in the component and is untested. Fix: drop the assertion and move that decision into selectedAlgos.js with tests.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed: dropped the assertion; the reply decision is customCheckReply in selectedAlgos.js, with tests.

const next = normalizedValue.map(v => (v.__key === key ? { ...v, ...patch } : v));
onChange(next);
const current = latestValueRef.current
commitValue(patchSelected(current, key, patch));

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Important: A bridge algorithm can end up with the canonical URL of a repo the user has since moved away from. The fetchBridgeCanonical(url).then(...) reply (line 241) now patches the current list through this function without checking that target_repo_url is still the one fetched, so a slow reply for repo A lands after the user switched to repo B. Fix: skip the patch unless the current entry still has target_repo_url === url.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed: the canonical reply is skipped unless the entry still has the fetched target_repo_url.

…d for a changed repo URL, custom check reply dropped for a changed token, latest-list ref set after commit, reply decision tested

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@snyaggarwal snyaggarwal left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Verdict: ready to merge. Nothing blocking. The follow-ups below are optional.

This fixes OpenConceptLab/ocl_online#786. A custom algorithm check or a bridge canonical URL reply no longer resets the list to how it was when the request started. Edits to other algorithms and fields made while it was pending are kept. A reply is dropped if the algorithm was removed, its URL or token changed, or a newer check started. npm test passes (766, 11 new) and CI is green.

Checked and fine:

  • Removing and adding an algorithm both build on the current list. A remove then an add before the parent re-renders keeps both changes.
  • Removing an algorithm clears its check, so a pending reply for it is ignored.
  • The latest-list ref is set in a useLayoutEffect after each commit, so renders React throws away don't touch it.

Non-blocking:

  1. Fields the reply fills still win over typing. The check writes id, name and description, so text typed into those three while it is pending is replaced. That's reasonable, because the endpoint is the source for them. But the test "an edit made while a check was pending is kept" (selectedAlgos.test.js:22) patches only id and name, so it suggests more than the component does. Rename it, or have it use the real patch shape.
  2. A canonical URL typed while its fetch is pending is overwritten (MultiAlgoSelector.jsx:243). The reply is dropped only when target_repo_url changed. It could also send bridge_repo: sel.bridge_repo, so a typed value counts as a change.
  3. An update to the list from MapProject (for example pinVersion) can be lost. This happens if it is queued in the same gap before a render as a reply from this component, because commitValue passes a whole list to setAlgosSelected rather than a function. It's narrow, and it was worse before. Fully closing it needs a functional onChange.
  4. isLoading can stay true for a key the parent replaced while its check was pending, for example on project load. Nothing reads isLoading in the render today, so it can't be seen.
  5. Pre-existing: the duplicate id/name check matches the entry against itself (MultiAlgoSelector.jsx:219). Running the same check again can flag a conflict. Leave the entry's own key out of the search.

Nearby wording that belongs outside the open repo is noted on OpenConceptLab/ocl_online#532.

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.

1 participant