fix(agent): attribute rebalance logs per user/position, not first user#172
Open
bakarezainab wants to merge 1 commit into
Open
fix(agent): attribute rebalance logs per user/position, not first user#172bakarezainab wants to merge 1 commit into
bakarezainab wants to merge 1 commit into
Conversation
Problem: logAgentAction queried db.user.findMany({ take: 1 }) and pinned
every agent log row to an arbitrary first user, making auditing and
per-user analytics unreliable.
Changes:
- schema.prisma: make AgentLog.userId nullable (system-level actions
produce rows with userId=null, distinguishable from user-level ones);
add positionId field; add composite index [userId, createdAt] for
hot query paths
- prisma/migrations/20260617000000_fix_agent_log_attribution: SQL
migration altering agent_logs accordingly
- router.ts: remove first-user lookup from logAgentAction; accept
optional userId + positionId params; in triggerRebalance, fetch all
affected positions and write one log row per (userId, positionId)
pair; system-level REBALANCE/ANALYZE calls leave userId=null
- tests/unit/agent/logAgentAction.test.ts: 9 unit tests covering
system-level (null userId), user-level attribution, multiple-user
isolation, and error-handling
- tests/integration/agent/rebalance.integration.test.ts: 6 integration
tests verifying per-user log creation for each impacted position,
no arbitrary-user attribution, deduplication guard, and null-userId
system-level fallback
All 50 tests pass (5 suites), tsc --noEmit clean.
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.
Problem: logAgentAction queried db.user.findMany({ take: 1 }) and pinned every agent log row to an arbitrary first user, making auditing and per-user analytics unreliable.
Changes:
All 50 tests pass (5 suites), tsc --noEmit clean
Closes #166