xonecas.io
60255
Zn

Zoea-Nova / commit 1c8d566

fix: inject password into pool account login results for mysis extraction

Bug: When proxy substituted register with pool account login, the mysis
couldn't extract password from the result, leaving currentPassword empty
and system prompt showing 'Password:' with no value.

Root cause: Game server API difference between login and register:
- register response: {session_id, username, password}
- login response: {session_id, username} (no password - client has it)

When proxy intercepts register and substitutes pool account login, mysis
receives login response format without password field, breaking extraction.

Fix: Add injectPasswordIntoResult() to modify login result before returning
to mysis. Injects password into JSON payload so mysis can extract it via
existing extractPassword() logic. This makes substituted login match the
register response format the mysis expects.

Also fixed:
- Don't release account when transitioning to idle (preserve login session)
- Don't overwrite password in cacheSnapshotToolResult() with empty string

Result: Myses using pool accounts now extract complete credentials and
display them in system prompt, maintaining game transparency while using
account pool for testing.

xonecas2026-02-09 1c8d566bf00e3fa8b1de5eff8052a8a150c5ade1 parent 6c43b12

2 files changed

internal/core/mysis.go+9−10
@@ -1447,7 +1447,9 @@ func (m *Mysis) setIdle(reason string) {
14471447 }
14481448
14491449 a.emitStateChange(oldState, MysisStateIdle)
1450- a.releaseCurrentAccount()
1450+ // NOTE: Don't release account when going idle - idle is a "sleeping" state
1451+ // and the mysis should maintain its logged-in session for when it resumes.
1452+ // Account is only released on: Stop(), setError(), or explicit logout tool call.
14511453 }
14521454
14531455 // extractLatestToolLoop finds the most recent tool-call message (assistant role
@@ -2094,7 +2096,7 @@ func (m *Mysis) cacheSnapshotToolResult(toolName string, result *mcp.ToolResult,
20942096 return
20952097 }
20962098
2097- // Try to extract username from result (for myses with pre-provided credentials)
2099+ // Get username from current account
20982100 username := m.CurrentAccountUsername()
20992101 if username == "" {
21002102 // Try to extract from result payload (nested under player.username)
@@ -2102,14 +2104,11 @@ func (m *Mysis) cacheSnapshotToolResult(toolName string, result *mcp.ToolResult,
21022104 if player, ok := payloadMap["player"].(map[string]interface{}); ok {
21032105 if extractedUsername, ok := player["username"].(string); ok && extractedUsername != "" {
21042106 username = extractedUsername
2105- // Also extract session_id if present
2106- sessionID := m.CurrentSessionID()
2107- if sessionID == "" {
2108- // Try to get from current tool arguments or system prompt
2109- // For now, just set the username without session
2110- }
2111- // Set the account so future caching works
2112- m.setCurrentAccount(username, "", sessionID)
2107+ // NOTE: Don't call setCurrentAccount here - we don't have the password
2108+ // and would overwrite it with empty string. The username extraction
2109+ // is only for caching purposes when account isn't set yet.
2110+ // If account needs to be set, it should be done during login/register
2111+ // tool execution where we have the full credentials.
21132112 }
21142113 }
21152114 }
internal/mcp/proxy.go+35−4
@@ -186,10 +186,16 @@ func (p *Proxy) CallTool(ctx context.Context, caller CallerContext, name string,
186186 "password": poolAccount.Password,
187187 }
188188 result, err := p.callUpstreamWithRetry(ctx, "login", loginArgs)
189- if result != nil && !result.IsError && accountStore != nil {
190- // Mark account as in use
191- loginArgsJSON, _ := json.Marshal(loginArgs)
192- p.interceptAuthTools("login", loginArgsJSON, result, caller.MysisID)
189+ if result != nil && !result.IsError {
190+ // Inject password into result so mysis can extract it
191+ // (login response doesn't include password, but register does)
192+ p.injectPasswordIntoResult(result, poolAccount.Password)
193+
194+ if accountStore != nil {
195+ // Mark account as in use
196+ loginArgsJSON, _ := json.Marshal(loginArgs)
197+ p.interceptAuthTools("login", loginArgsJSON, result, caller.MysisID)
198+ }
193199 }
194200 return result, err
195201 }
@@ -366,6 +372,31 @@ func (p *Proxy) handleLogoutResponse(arguments json.RawMessage, result *ToolResu
366372 }
367373 }
368374
375+// injectPasswordIntoResult adds the password field to a tool result payload.
376+// This is used when substituting register with pool account login, since login
377+// responses don't include the password but the mysis expects it (to match register behavior).
378+func (p *Proxy) injectPasswordIntoResult(result *ToolResult, password string) {
379+ if result == nil || len(result.Content) == 0 {
380+ return
381+ }
382+
383+ // Find the text content block with JSON payload
384+ for i := range result.Content {
385+ if result.Content[i].Type == "text" {
386+ var data map[string]interface{}
387+ if err := json.Unmarshal([]byte(result.Content[i].Text), &data); err == nil {
388+ // Add password to the payload
389+ data["password"] = password
390+ // Re-marshal and update the content
391+ if updatedJSON, err := json.Marshal(data); err == nil {
392+ result.Content[i].Text = string(updatedJSON)
393+ }
394+ return
395+ }
396+ }
397+ }
398+}
399+
369400 // tryClaimPoolAccount attempts to claim an available account from the pool.
370401 // Returns the account if one is available, nil otherwise.
371402 func (p *Proxy) tryClaimPoolAccount(mysisID string) *Account {