feat: add websocket for app streams - #398
Open
ppatel9703 wants to merge 2 commits into
Open
Conversation
✅ 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. |
This was referenced Aug 4, 2026
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
Delivery side of app-owner log visibility: pushes a project's app log live to the browser over the existing insight websocket, reusing infrastructure already built for a different feature (Claude Code transcript streaming) rather than a new endpoint. The file being tailed is written by Semoss#2616; the consumer is the Console panel in semoss-ui#3302.
Changes Made
src/prerna/websocket/AppLogStreamer.java(new)Tails a project's
app.log(via Semoss'sAppLogManager.getLogFilePath) and broadcasts new lines to clients watching that project's insight, modeled on the existingClaudeCodeHistoryStreamer:watch, sends the last ~50KB of the file immediately (so the console doesn't open blank), then tails going forward — re-stats and re-opens the file every 2s rather than holding one handle open, since CSI/NFS-backed volumes cache attributes per-handle and would otherwise never see another process's appends.EngineLoggeras a single line (observed: 150K+ characters, apparently a file-listing response logged whole) — without the cap, one such line dominates the entire history window and blows up a single WS message. The full line stays on disk untouched; only the broadcast is truncated.src/prerna/websocket/InsightWebsocket.javaAdds a new
"app_logs"watch type ({"action":"watch","type":"app_logs","projectId":"<id>"}), constructing anAppLogStreamer. Critically, this is gated before any streamer is created — the socket by itself only proves "logged in", not "allowed to see this project's logs" — sohandleWatchnow checks the requester is an owner ofprojectId(SecurityProjectUtils.getUserProjectPermission+AccessPermissionEnum.isOwner, same rule the reactor in Semoss#2616 uses) and sends an error frame instead of ever constructing a streamer for anyone else. Also fixes streamer-key collisions (type + ":" + roomId, which broke forapp_logssince it has noroomId) and addssynchronized (session)around thewatch_started/error sends (see concurrency fix below).src/prerna/websocket/SocketSessionHandler.javasendReturnDatanow wrapssession.getBasicRemote().sendText(...)insynchronized (session). Tomcat's WSRemoteEndpointthrowsIllegalStateExceptionif two threads callsendText()on the same session concurrently — this had no synchronization before, for any streamer type including the pre-existing Claude Code one, so it predates this PR. Streaming app logs made it far more likely to actually trip, since there's now regular background write traffic on sessions that also receive other messages (e.g. a streamer thread pushing a line at the same moment the message-handling thread sends an ack).How to Test
/insightSocket?insightId=<id>, send{"action":"watch","type":"app_logs","projectId":"<id-you-own>"}— expect{"action":"watch_started",...}followed by the last ~50KB of that project'sapp.log, then new lines as they're written.projectIdyou don't own — expect{"action":"error","message":"Only project owners can view app logs"}and no streamer ever starts....[truncated, N more chars]suffix, not the full payload.IllegalStateException/WsRemoteEndpointImplBase$StateMachine.checkStateerrors in the log (the concurrency fix).Notes
app_logswatch type.GetAppLogsReactor(Semoss) is deleted; this streamer covers both the live tail and the initial-history bootstrap it used to handle.InsightWebsocket.handlePixelhas a pre-existing NPE (insightIdstaysnullafter theifbranch creates a newInsight, then gets passed intoSocketSessionHandlerFactory.getHandler(null)) — not fixed in this PR, flagged as a separate follow-up since it's core pixel-execution infra a Console/app-logs socket never actually exercises (it only ever sendswatch/unwatch, neverpixel).Review Updates
Addressed the following from review:
AppLogStreamer.javaandInsightWebsocket.java— this repo's Maven compiler plugin also enforcescp1252source encoding.InsightWebsocket.isProjectOwner(): added agetPrimaryLoginToken() == nullcheck alongside the existinguser == nullcheck, before dereferencing the token — same guard as the analogous check in Semoss'sSearchAppLogsReactor.