Skip to content

feat(ops): log who made each request and each process's memory - #554

Merged
artempartos merged 1 commit into
developfrom
artempartos/observability-memory-log-principal
Oct 24, 2026
Merged

artempartos merged 1 commit into
developfrom
artempartos/observability-memory-log-principal

Conversation

@artempartos

Copy link
Copy Markdown
Contributor

Summary

Two gaps that made the web memory leak (#552) slow to find and incidents slow to trace.

Who made a request

  • ApplicationController#append_info_to_payload sets user again — only when the request already resolved its user. Calling current_user there would resolve the session for requests that never asked (webhooks, the login page), which touches or forgets session rows.
  • MCPController records its principal: the user for a personal amcp_ token, the terminal session for an agent's session key.
  • Lograge keeps never logging params for /mcp, /action_mcp and the credential endpoints, but those lines now carry host/ip/ff/user/session instead of nothing. Every line gains a session= field.

Memory over time

  • MemoryStats logs one [memory] line every five minutes per long-running process: role, pid, RSS, heap_live_slots, old_objects, heap pages, GC counts, malloc_increase_bytes. Slots and old objects climbing means retained Ruby objects; RSS climbing while they stay flat means native memory.
  • Started from after_booted in config/puma.rb (web) and config/puma_mcp.rb (mcp), from bin/temporal_worker, and from the Solid Queue supervisor/worker/dispatcher/scheduler start hooks (each forked process has its own memory). Off in development and test.

Tests

  • LogrageOptionsTest: sensitive endpoints log who called but never params; other requests log params and user.
  • RequestLogPrincipalTest (new): a signed-in page request carries its user; a request that never looked one up carries none; a personal MCP call carries the token's user, an agent's call its session.
  • MemoryStatsTest (new): line format; not started in test.

Run locally in a dev image: those files plus mcp_controller_test.rb and personal_mcp_board_test.rb (71 runs, 0 failures); repo-wide rubocop clean. CI is the verification for the full suite.

🤖 Generated with Claude Code

Request logs had an always-empty user field, and MCP calls logged nothing but
the path, so tracing a request to an account meant matching SQL binds by
request id. The web memory leak fixed in #552 grew for weeks before anyone
noticed; a periodic GC.stat/RSS line shows the next one as a trend within a
day and tells retained Ruby objects from native memory.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>
@artempartos
artempartos force-pushed the artempartos/observability-memory-log-principal branch from 6882595 to 0fdc0bd Compare October 24, 2026 10:37
@artempartos
artempartos merged commit 8fabfc7 into develop Oct 24, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant