fix(streaming): pass agentId to resolveStorePath and remove fallback#422
fix(streaming): pass agentId to resolveStorePath and remove fallback#422smallmj wants to merge 1 commit into
Conversation
PingThis PR replaces the earlier PR #386 which has been ignored for a while. Status: This fix has been locally verified to work correctly. After applying this change, each non-default agent now shows its own unique metrics values instead of all showing the same values from the main agent. The fix is simple and clean: extract agentId from sessionKey and pass it to resolveStorePath, removing the incorrect fallback mechanism. Please review. Thanks! |
Extract agentId from session key (format: 'agent:<agentId>:feishu:...') to route the store lookup to the correct per-agent session file. The fallback mechanism from larksuite#504 is incorrect because it reads from the default agent's session file when the correct agent's file doesn't have the entry, causing all non-default agents to show the same metrics values (from main). This approach avoids that by using the correct key directly without any fallback. Fixes larksuite#347
5d1756a to
3bbd18b
Compare
Why #422 is better than #504 (no fallback approach)The problem with fallback#504 correctly passes const defaultAgentId = resolveDefaultAgentId(cfg);
const fallbackKey = key.replace(/^(agent):[^:]+:/, `$1:${defaultAgentId}:`);
const candidateKeys = fallbackKey !== key ? [key, fallbackKey] : [key];
for (const candidate of candidateKeys) {
const val = store[candidate];
if (val && typeof val === 'object') { entry = val; break; }
}The fallback activates when the primary lookup returns no data. It substitutes the agent-id segment with
The fallback defeats the entire purpose of per-agent session isolation. Why #422's approach is cleaner#422 extracts agentId directly from the session key via regex, no fallback, no fallbackKey, no candidateKeys: const agentId = key.match(/^agent:([^:]+):/)?.[1];
// ...
const storePath = sessionApi.resolveStorePath(sessionStorePath, { agentId });
// ...
const entry = store[key]; // direct lookup, no fallbackThis is better because:
Reference
|
Summary
Extract agentId from session key to route the store lookup to the correct per-agent session file. The original fallback mechanism was incorrect because it would read from the default agent's session file when the correct agent's file didn't have the entry, causing all non-default agents to show the same metrics values.
Changes
key.match(/^agent:([^:]+):/)?.[1]store[key]Why remove fallback
The fallback was wrong because:
Fixes #347