Repository navigation
Feat/user context executor - #3341
Open
ppatel9703 wants to merge 3 commits into
Open
ppatel9703 wants to merge 3 commits into
ppatel9703 wants to merge 3 commits into
Conversation
Contributor
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
ppatel9703
marked this pull request as ready for review
November 19, 2026 19:25
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Gives a project's custom reactor a sanctioned way to run work on other threads as the user who is signed in. Today it has none: the sandbox blocks
Threadand the thread pools, theThreadStoresetters (setUser,setSessionId,setInsightId, ...) andInsightStore. A worker thread therefore has no user, and the engine access check refuses every engine or model call it makes ("Custom code runs only for the user signed in on the thread").Found while moving AIMES onto the sandboxed build. Its review step ran model calls four at a time on a pool, and every call failed with
NoClassDefFoundError: prerna/om/InsightStore. Apps that fan work out to threads cannot do it under the sandbox. This also covers the idea of looking an insight up by the current user. A lookup alone would not help, because the worker thread would still carry no user.prerna.util.UserContextExecutordoes the identity work on the platform's side. The reactor passes its ownInsight, never aUser, so there is nothing for it to forge.Changes Made
prerna.util.UserContextExecutor(AutoCloseable).create(insight, threads)runs on the reactor's thread and reads the signed-in user fromThreadStore.submit(Function<Insight, T>)returns aFuture<T>.close()stops the executor.createrefuses with aSemossPixelExceptionwhen no user is signed in on the thread, when the insight is missing, or when the insight's user is not the signed-in user. Users match if they are the same object or have the same login ids and types.InsightStoreonly while the task runs. An insight carries state that is not safe to share between threads. The child's folder is granted to the user whenCHROOT_ENABLEis on, then revoked and deleted afterwards.SandboxedJavaExecutiongets one package-private getter,sandboxRootOfCurrentThread(), so file work on the worker stays inside the user's chroot.PROJECT_USER_THREADS_MAX(default 8). Idle threads end after 60 seconds if nobody closes the executor.{}placeholders, ids only, exception last. Warn for refusals and for tasks dropped on close, info when the cap trims a request, debug for lifecycle.project_reactor_sandbox.mdgets a "Running work on other threads" section with an example and a rule/test table. The Threads row and "What custom reactors use instead" are updated.UserContextExecutorUnitTests.SandboxProbegets test helpers so a project class loaded through the sandbox can hand a task to the executor.No existing block list changes. The class is not blocked, like
EmailUtilityandHttpHelperUtility. No RDF_Map file change is needed, because the setting is optional.How to Test
Unit tests (new, plus the sandbox suites that share
SandboxProbeandSandboxedJavaExecution):Expected: all green. I ran them with the JUnit launcher on a hand-built classpath, not through Maven. Run them once with Maven before merge.
The tests that show the fix itself:
aCustomReactorsTaskSeesTheSignedInUserOnAnExecutorThread: a class loaded through the project sandbox hands a task to the executor, and the task sees the signed-in user.theSameTaskOnAThreadMadeByHandSeesNoUser: the same task on a bare thread sees no user. This is the failure the executor fixes.anInsightOfAnotherUserIsRefusedandaCreatorWithNoSignedInUserIsRefused: the same-user check.Manual, from a custom reactor (needs a project with a model engine the user can read):
execute(), run the following. Use a model call that needs the user's permission, such asUtility.getModel(id).ask(...), insidetaskInsight -> ...:new Thread(...)orExecutors.newFixedThreadPool. Expected: the class is blocked, as before.PROJECT_USER_THREADS_MAX=2in RDF_Map and ask for 8 threads. Expected: 2 threads, plus an info log line about the cap.Notes
close()drops tasks that have not started and interrupts running ones, so callers read their results first. The docs say so.InsightStorelookup: it would let project code reach other users' insights, and a worker would still have no user. Keeping the user comparison and the thread setup inside one platform class avoids both.RDF_Map.prop,project/platform__*) are not part of this PR.