xonecas.io
60255
Zn

Zoea-Nova / commit 439f0c9

Remove redundant game session management

MCP server handles game sessions transparently at protocol level.
Application-level tracking of session_id from login/register responses
is unnecessary and violates separation of concerns.

Changes:
- Remove currentSessionID field and getter from Mysis struct
- Remove extractSessionID() function that parsed tool results
- Update setCurrentAccount/releaseCurrentAccount to not track session_id
- Simplify AccountDetailsTemplate to username/password only
- Remove session_id from system prompt instructions
- Remove session_id from stub tool schemas
- Clean up tests and remove obsolete error rewriting tests

Error propagation verified: session_invalid and not_authenticated errors
flow through unchanged to myses, allowing them to re-login as needed.

xonecas2026-02-10 439f0c9eac97040171ab2954df7be3f1508015a3 parent 8a7a993

6 files changed

internal/constants/constants.go+1−6
@@ -21,8 +21,6 @@ Exlore the game, make goals and achieve them over time. You are part of a secret
2121 ## Critical Rules
2222 Context is limited - use search tools for older information.
2323
24-Use session_id in ALL game tools that require authentication. Your session_id is shown in the Account Details section above.
25-
2624 ### EVERY TURN:
2725 The game runs on 10-second ticks. Plan ahead. Use your tool calls efficiently.
2826
@@ -42,10 +40,7 @@ Continue to play the game.
4240
4341 // AccountDetailsTemplate is used when credentials are available
4442 const AccountDetailsTemplate = `Username: %s
45-Password: %s
46-Session ID: %s
47-
48-Use session_id in ALL game tools that require authentication.`
43+Password: %s`
4944
5045 // AccountDetailsFallback is used when no credentials are available
5146 const AccountDetailsFallback = `No active account. Call register()`
internal/core/mysis.go+9−41
@@ -45,7 +45,6 @@ type Mysis struct {
4545 lastError error
4646 currentAccountUsername string
4747 currentPassword string // Password for current account
48- currentSessionID string // Active session_id from login/register
4948 activityState ActivityState
5049 activityUntil time.Time
5150 lastServerTick int64
@@ -199,13 +198,6 @@ func (m *Mysis) CurrentPassword() string {
199198 return m.currentPassword
200199 }
201200
202-// CurrentSessionID returns the active session_id.
203-func (m *Mysis) CurrentSessionID() string {
204- m.mu.RLock()
205- defer m.mu.RUnlock()
206- return m.currentSessionID
207-}
208-
209201 // ActivityState returns the mysis current activity.
210202 func (m *Mysis) ActivityState() ActivityState {
211203 a := m
@@ -1127,8 +1119,7 @@ func (m *Mysis) executeToolCall(ctx context.Context, mcpProxy *mcp.Proxy, tc pro
11271119 }
11281120 json.Unmarshal(tc.Arguments, &args)
11291121
1130- // Extract session_id and password from tool result
1131- sessionID := extractSessionID(result)
1122+ // Extract password from tool result
11321123 password := args.Password
11331124
11341125 // For register, password might be in result instead of args
@@ -1142,8 +1133,8 @@ func (m *Mysis) executeToolCall(ctx context.Context, mcpProxy *mcp.Proxy, tc pro
11421133 actualUsername = args.Username // Fallback to requested username
11431134 }
11441135
1145- if actualUsername != "" && sessionID != "" {
1146- a.setCurrentAccount(actualUsername, password, sessionID)
1136+ if actualUsername != "" {
1137+ a.setCurrentAccount(actualUsername, password)
11471138
11481139 // Rebuild system prompt with new credentials
11491140 if err := a.rebuildSystemMemory(); err != nil {
@@ -1163,7 +1154,7 @@ func (m *Mysis) executeToolCall(ctx context.Context, mcpProxy *mcp.Proxy, tc pro
11631154 return result, err
11641155 }
11651156
1166-func (m *Mysis) setCurrentAccount(username, password, sessionID string) {
1157+func (m *Mysis) setCurrentAccount(username, password string) {
11671158 m.mu.Lock()
11681159 storeRef := m.store
11691160
@@ -1179,7 +1170,6 @@ func (m *Mysis) setCurrentAccount(username, password, sessionID string) {
11791170
11801171 m.currentAccountUsername = username
11811172 m.currentPassword = password
1182- m.currentSessionID = sessionID
11831173 m.mu.Unlock()
11841174
11851175 if storeRef != nil {
@@ -1199,27 +1189,6 @@ func (m *Mysis) releaseCurrentAccount() {
11991189 }
12001190 m.currentAccountUsername = ""
12011191 m.currentPassword = ""
1202- m.currentSessionID = ""
1203-}
1204-
1205-// extractSessionID extracts session_id from tool result content
1206-func extractSessionID(result *mcp.ToolResult) string {
1207- if result == nil || result.IsError {
1208- return ""
1209- }
1210-
1211- for _, block := range result.Content {
1212- if block.Type == "text" {
1213- // Parse JSON from text block
1214- var data map[string]interface{}
1215- if err := json.Unmarshal([]byte(block.Text), &data); err == nil {
1216- if sessionID, ok := data["session_id"].(string); ok {
1217- return sessionID
1218- }
1219- }
1220- }
1221- }
1222- return ""
12231192 }
12241193
12251194 // extractPassword extracts password from tool result (for register responses)
@@ -1592,7 +1561,7 @@ func (m *Mysis) findLastUserPromptIndex(memories []*store.Memory) int {
15921561 // Rationale:
15931562 // - Multi-step tool calling (login → get_status → get_notifications) requires complete tool history
15941563 // - Historical turns can be compressed without breaking current reasoning
1595-// - Preserves session_id and other tool results from within the current turn
1564+// - Preserves tool results from within the current turn
15961565 // - Prevents orphaned tool calls by keeping complete tool loops together
15971566 //
15981567 // Example context for multi-step turn:
@@ -1601,8 +1570,8 @@ func (m *Mysis) findLastUserPromptIndex(memories []*store.Memory) int {
16011570 // {role: system, content: "You are Mysis Alpha..."},
16021571 // {role: user, source: direct, content: "Check ship status"},
16031572 // {role: assistant, content: "[TOOL_CALLS]call_1:login:{}"},
1604-// {role: tool, content: "call_1:session_id: abc123"},
1605-// {role: assistant, content: "[TOOL_CALLS]call_2:get_status:{\"session_id\":\"abc123\"}"},
1573+// {role: tool, content: "call_1:Login successful"},
1574+// {role: assistant, content: "[TOOL_CALLS]call_2:get_status:{}"},
16061575 // {role: tool, content: "call_2:Ship health: 100%"}
16071576 // ]
16081577 func (m *Mysis) getContextMemories() ([]*store.Memory, bool, error) {
@@ -1966,10 +1935,9 @@ func (m *Mysis) buildSystemPrompt() string {
19661935 accountDetails := constants.AccountDetailsFallback
19671936 username := m.CurrentAccountUsername()
19681937 password := m.CurrentPassword()
1969- sessionID := m.CurrentSessionID()
19701938
1971- if username != "" && sessionID != "" {
1972- accountDetails = fmt.Sprintf(constants.AccountDetailsTemplate, username, password, sessionID)
1939+ if username != "" {
1940+ accountDetails = fmt.Sprintf(constants.AccountDetailsTemplate, username, password)
19731941 }
19741942
19751943 prompt = strings.Replace(prompt, "{{ACCOUNT_DETAILS}}", accountDetails, 1)
internal/core/mysis_test.go+7−10
@@ -349,9 +349,6 @@ func TestMysisStateEvents(t *testing.T) {
349349
350350 func TestSystemPromptContainsCaptainsLogExamples(t *testing.T) {
351351 // SystemPrompt should contain core game guidance
352- if !strings.Contains(constants.SystemPrompt, "session_id") {
353- t.Fatal("SystemPrompt missing session_id guidance")
354- }
355352 if !strings.Contains(constants.SystemPrompt, "get_notifications") {
356353 t.Fatal("SystemPrompt missing get_notifications reminder")
357354 }
@@ -416,12 +413,12 @@ func TestFormatToolResult_Success(t *testing.T) {
416413 }
417414
418415 func TestSystemPromptContainsSearchGuidance(t *testing.T) {
419- // SystemPrompt was simplified - check for core session management
420- if !strings.Contains(constants.SystemPrompt, "session_id") {
421- t.Fatal("SystemPrompt missing session_id guidance")
416+ // SystemPrompt was simplified - check for core game guidance
417+ if !strings.Contains(constants.SystemPrompt, "game") {
418+ t.Fatal("SystemPrompt missing game reference")
422419 }
423- if !strings.Contains(constants.SystemPrompt, "Use session_id in ALL game tools") {
424- t.Fatal("SystemPrompt missing session_id usage reminder")
420+ if !strings.Contains(constants.SystemPrompt, "EVERY TURN") {
421+ t.Fatal("SystemPrompt missing turn reminder")
425422 }
426423 }
427424
@@ -1935,7 +1932,7 @@ func TestGetContextMemories_CurrentTurnPreserved(t *testing.T) {
19351932 if err != nil {
19361933 t.Fatalf("AddMemory error: %v", err)
19371934 }
1938- err = mysis.store.AddMemory(mysis.id, store.MemoryRoleTool, store.MemorySourceTool, "call_1:session_id: abc123", "", "")
1935+ err = mysis.store.AddMemory(mysis.id, store.MemoryRoleTool, store.MemorySourceTool, "call_1:login successful", "", "")
19391936 if err != nil {
19401937 t.Fatalf("AddMemory error: %v", err)
19411938 }
@@ -1968,7 +1965,7 @@ func TestGetContextMemories_CurrentTurnPreserved(t *testing.T) {
19681965 if mem.Role == store.MemoryRoleAssistant && strings.Contains(mem.Content, "call_1:login") {
19691966 hasLoginCall = true
19701967 }
1971- if mem.Role == store.MemoryRoleTool && strings.Contains(mem.Content, "call_1") && strings.Contains(mem.Content, "session_id") {
1968+ if mem.Role == store.MemoryRoleTool && strings.Contains(mem.Content, "call_1") && strings.Contains(mem.Content, "login") {
19721969 hasLoginResult = true
19731970 }
19741971 if mem.Role == store.MemoryRoleAssistant && strings.Contains(mem.Content, "call_2:get_status") {
internal/mcp/proxy_test.go+15−74
@@ -3,7 +3,6 @@ package mcp
33 import (
44 "context"
55 "encoding/json"
6- "strings"
76 "testing"
87 )
98
@@ -35,6 +34,7 @@ type mockAccountStore struct {
3534 created []Account
3635 marked []string
3736 released []string
37+ assigned []string
3838 }
3939
4040 func (m *mockAccountStore) CreateAccount(username, password string, mysisID ...string) (*Account, error) {
@@ -42,6 +42,15 @@ func (m *mockAccountStore) CreateAccount(username, password string, mysisID ...s
4242 return &Account{Username: username, Password: password}, nil
4343 }
4444
45+func (m *mockAccountStore) GetAccountByMysisID(mysisID string) (*Account, error) {
46+ return nil, nil
47+}
48+
49+func (m *mockAccountStore) AssignAccount(username, mysisID string) error {
50+ m.assigned = append(m.assigned, username)
51+ return nil
52+}
53+
4554 func (m *mockAccountStore) MarkAccountInUse(username, mysisID string) error {
4655 m.marked = append(m.marked, username)
4756 return nil
@@ -52,6 +61,11 @@ func (m *mockAccountStore) ReleaseAccount(username string) error {
5261 return nil
5362 }
5463
64+func (m *mockAccountStore) ReleaseAccountByMysisID(mysisID string) error {
65+ m.released = append(m.released, mysisID)
66+ return nil
67+}
68+
5569 func (m *mockAccountStore) ReleaseAllAccounts() error { return nil }
5670
5771 func TestProxyPrefersLocalTool(t *testing.T) {
@@ -150,76 +164,3 @@ func TestProxyAuthInterceptionLogout(t *testing.T) {
150164 t.Fatalf("expected account released for pilot, got %+v", accounts.released)
151165 }
152166 }
153-
154-func TestRewriteSessionError_SessionRequired(t *testing.T) {
155- proxy := &Proxy{}
156-
157- original := "Error: session_required: You must provide a session_id. Get one by calling login() or register() first."
158- rewritten := proxy.rewriteSessionError(original)
159-
160- if strings.Contains(rewritten, "Get one by calling login()") {
161- t.Error("Should have replaced the instruction to login again")
162- }
163-
164- if !strings.Contains(rewritten, "Check your recent tool results") {
165- t.Error("Should instruct to check recent tool results")
166- }
167-}
168-
169-func TestRewriteSessionError_SessionInvalid(t *testing.T) {
170- proxy := &Proxy{}
171-
172- original := "Error: session_invalid: Session not found or expired. Call login() again to get a new session_id."
173- rewritten := proxy.rewriteSessionError(original)
174-
175- if !strings.Contains(rewritten, "session truly expired") {
176- t.Error("Should add clarification about true expiration")
177- }
178-}
179-
180-func TestRewriteSessionError_Other(t *testing.T) {
181- proxy := &Proxy{}
182-
183- original := "Error: some_other_error: This is not a session error."
184- rewritten := proxy.rewriteSessionError(original)
185-
186- if rewritten != original {
187- t.Error("Should not modify non-session errors")
188- }
189-}
190-
191-func TestProxyRewritesUpstreamErrors(t *testing.T) {
192- // Simulate upstream returning a session_required error
193- upstream := &mockUpstream{
194- result: &ToolResult{
195- Content: []ContentBlock{{
196- Type: "text",
197- Text: "Error: session_required: You must provide a session_id. Get one by calling login() or register() first.",
198- }},
199- IsError: true,
200- },
201- }
202- proxy := NewProxy(upstream)
203-
204- result, err := proxy.CallTool(context.Background(), CallerContext{}, "mine", json.RawMessage(`{}`))
205- if err != nil {
206- t.Fatalf("CallTool() error: %v", err)
207- }
208-
209- if !result.IsError {
210- t.Fatal("Expected error result")
211- }
212-
213- if len(result.Content) == 0 {
214- t.Fatal("Expected content in error result")
215- }
216-
217- rewrittenText := result.Content[0].Text
218- if strings.Contains(rewrittenText, "Get one by calling login()") {
219- t.Error("Error message should have been rewritten")
220- }
221-
222- if !strings.Contains(rewrittenText, "Check your recent tool results") {
223- t.Error("Error message should contain guidance to check tool results")
224- }
225-}
internal/mcp/stub.go+4−4
@@ -36,22 +36,22 @@ func (c *StubClient) ListTools(ctx context.Context) ([]Tool, error) {
3636 {
3737 Name: "get_status",
3838 Description: "Get player status (stub)",
39- InputSchema: json.RawMessage(`{"type": "object", "properties": {"session_id": {"type": "string"}}}`),
39+ InputSchema: json.RawMessage(`{"type": "object", "properties": {}}`),
4040 },
4141 {
4242 Name: "get_system",
4343 Description: "Get system info (stub)",
44- InputSchema: json.RawMessage(`{"type": "object", "properties": {"session_id": {"type": "string"}}}`),
44+ InputSchema: json.RawMessage(`{"type": "object", "properties": {}}`),
4545 },
4646 {
4747 Name: "get_ship",
4848 Description: "Get ship info (stub)",
49- InputSchema: json.RawMessage(`{"type": "object", "properties": {"session_id": {"type": "string"}}}`),
49+ InputSchema: json.RawMessage(`{"type": "object", "properties": {}}`),
5050 },
5151 {
5252 Name: "get_poi",
5353 Description: "Get POI info (stub)",
54- InputSchema: json.RawMessage(`{"type": "object", "properties": {"session_id": {"type": "string"}}}`),
54+ InputSchema: json.RawMessage(`{"type": "object", "properties": {}}`),
5555 },
5656 {
5757 Name: "get_notifications",
internal/mcp/stub_test.go+0−1
@@ -207,7 +207,6 @@ func TestStubClient_CallTool_WithArguments(t *testing.T) {
207207 ctx := context.Background()
208208
209209 args := map[string]interface{}{
210- "session_id": "test_session",
211210 "some_param": "test_value",
212211 }