Skip to content

Commit 311f8d6

Browse files
committed
spotbugs(WEM) Batch 3: enrich Session IllegalStateException messages (5 cleared)
Adds in-scope state (slotId + transcript size) to the 5 state-machine IllegalStateException messages thrown by Session.send / stream / commitStreamedReply / save / restore. Before: throw new IllegalStateException( "stream in progress; call commitStreamedReply(...) before send(...)"); After: throw new IllegalStateException( "stream in progress on slot " + slotId + " (transcript=" + turns.size() + " turns)" + "; call commitStreamedReply(...) before send(...)"); Why both fields: - slotId identifies which session got stuck in a multi-session setup (a process can hold many Sessions on the same model, one per slot). - turns.size() shows how far the transcript progressed before the state-machine violation — useful when triaging "the session went weird around message N" reports. Compatibility: - Session is final (line 41) — no subclass override risk. - No test asserts on the exception message text (verified across SessionConcurrencyTest, LlamaModelTest). THROWS_METHOD_THROWS_RUNTIMEEXCEPTION findings on Session.send and Session.stream (the catch+cleanup+rethrow pattern at line 112 / 138) are deliberately NOT addressed in this batch; they are deferred to their own investigation alongside the existing BAF suppression (spotbugs/spotbugs#3918 + PR #4087 lifecycle). SpotBugs Max+Low: WEM goes 10 -> 5. Total jllama: 39 -> 34.
1 parent 5fd7b4d commit 311f8d6

1 file changed

Lines changed: 19 additions & 5 deletions

File tree

src/main/java/net/ladenthin/llama/Session.java

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,10 @@ public Session(
9999
public String send(String userMessage) {
100100
synchronized (lock) {
101101
if (streamingActive) {
102-
throw new IllegalStateException("stream in progress; call commitStreamedReply(...) before send(...)");
102+
throw new IllegalStateException(
103+
"stream in progress on slot " + slotId
104+
+ " (transcript=" + turns.size() + " turns)"
105+
+ "; call commitStreamedReply(...) before send(...)");
103106
}
104107
turns.add(new Pair<String, String>("user", userMessage));
105108
InferenceParameters params = buildParams();
@@ -126,7 +129,10 @@ public String send(String userMessage) {
126129
public LlamaIterable stream(String userMessage) {
127130
synchronized (lock) {
128131
if (streamingActive) {
129-
throw new IllegalStateException("stream in progress; call commitStreamedReply(...) before stream(...)");
132+
throw new IllegalStateException(
133+
"stream in progress on slot " + slotId
134+
+ " (transcript=" + turns.size() + " turns)"
135+
+ "; call commitStreamedReply(...) before stream(...)");
130136
}
131137
turns.add(new Pair<String, String>("user", userMessage));
132138
try {
@@ -149,7 +155,10 @@ public LlamaIterable stream(String userMessage) {
149155
public void commitStreamedReply(String assistantText) {
150156
synchronized (lock) {
151157
if (!streamingActive) {
152-
throw new IllegalStateException("no stream in progress; call stream(...) first");
158+
throw new IllegalStateException(
159+
"no stream in progress on slot " + slotId
160+
+ " (transcript=" + turns.size() + " turns)"
161+
+ "; call stream(...) first");
153162
}
154163
turns.add(new Pair<String, String>("assistant", assistantText));
155164
streamingActive = false;
@@ -165,7 +174,10 @@ public void commitStreamedReply(String assistantText) {
165174
public String save(String filepath) {
166175
synchronized (lock) {
167176
if (streamingActive) {
168-
throw new IllegalStateException("stream in progress; call commitStreamedReply(...) before save(...)");
177+
throw new IllegalStateException(
178+
"stream in progress on slot " + slotId
179+
+ " (transcript=" + turns.size() + " turns)"
180+
+ "; call commitStreamedReply(...) before save(...)");
169181
}
170182
return model.saveSlot(slotId, filepath);
171183
}
@@ -181,7 +193,9 @@ public String restore(String filepath) {
181193
synchronized (lock) {
182194
if (streamingActive) {
183195
throw new IllegalStateException(
184-
"stream in progress; call commitStreamedReply(...) before restore(...)");
196+
"stream in progress on slot " + slotId
197+
+ " (transcript=" + turns.size() + " turns)"
198+
+ "; call commitStreamedReply(...) before restore(...)");
185199
}
186200
return model.restoreSlot(slotId, filepath);
187201
}

0 commit comments

Comments
 (0)