Skip to content

fix(gastown): tag structured logs with town IDs#3428

Open
evanjacobson wants to merge 1 commit into
gastown-stagingfrom
improvement/gastown-log-town-id
Open

fix(gastown): tag structured logs with town IDs#3428
evanjacobson wants to merge 1 commit into
gastown-stagingfrom
improvement/gastown-log-town-id

Conversation

@evanjacobson
Copy link
Copy Markdown
Contributor

Summary

Gastown logs were hard to correlate across worker, Durable Object, container, plugin, and tRPC paths because several structured logging sites did not include the town identifier even when it was available.

This adds town ID tagging to the structured logging paths that can derive it, following the existing workers-tagged-logger context pattern in the worker and the container logger/app-log payload conventions in container code.

Implementation notes
  • Tags town-scoped HTTP, WebSocket, DO, and tRPC log paths with townId.
  • Adds townId fields to container process logs where the town is available from env, request, or agent state.
  • Carries plugin town context through the SDK-supported extra payload.

Verification

Not manually tested; this is an observability-only logging change.

Visual Changes

N/A

Reviewer Notes

Review focus: confirm each new townId source matches the relevant request, agent, or container scope.

@kilo-code-bot
Copy link
Copy Markdown
Contributor

kilo-code-bot Bot commented May 22, 2026

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Executive Summary

All townId tagging follows existing workers-tagged-logger context patterns correctly, with no security vulnerabilities, runtime errors, or logic bugs found across the worker, container, DO, and tRPC paths. No new changes since the previous review — the PR head commit is identical in content to the previously reviewed commit.

Files Reviewed (11 files)
  • services/gastown/container/plugin/index.ts
  • services/gastown/container/src/agent-runner.ts
  • services/gastown/container/src/control-server.ts
  • services/gastown/container/src/main.ts
  • services/gastown/container/src/process-manager.ts
  • services/gastown/container/src/token-refresh.ts
  • services/gastown/src/dos/Town.do.ts
  • services/gastown/src/dos/town/container-idle-stop.ts
  • services/gastown/src/gastown.worker.ts
  • services/gastown/src/trpc/init.ts
  • services/gastown/src/trpc/router.ts
Reviewer Notes
  • getTownIdFromPath regex (/(?:^|\/)towns\/([^/]+)/): Used in cfAccessDebugMiddleware and app.onError for best-effort townId extraction. It correctly covers /api/towns/… and /debug/towns/… paths but will not match /api/mayor/:townId/… routes. This is an intentional observability gap — mayor routes already have per-route logger.setTags({ townId }) middleware, so the onError fallback is only needed for paths outside that coverage.
  • reapTownId closure capture in refreshTokenForAllAgents: Correctly snapshots agent.townId into a local const before the .then() callback runs, avoiding stale-closure mutation. Good defensive pattern.
  • extra: { townId } in plugin: Consistent with the SDK-supported extra payload convention described in the PR.
  • tRPC analyticsProcedure: getRawInput() + UUID-shaped safeParse is a sound, non-throwing approach to tag propagation for procedures that carry townId in their input.

Reviewed by claude-sonnet-4.6 · 736,918 tokens

Review guidance: REVIEW.md from base branch gastown-staging

@jrf0110 jrf0110 changed the base branch from main to gastown-staging May 22, 2026 17:44
@jrf0110 jrf0110 changed the base branch from gastown-staging to main May 22, 2026 17:45
@jrf0110 jrf0110 changed the base branch from main to gastown-staging May 22, 2026 17:47
@jrf0110 jrf0110 force-pushed the improvement/gastown-log-town-id branch from b5e8679 to c8d2aa9 Compare May 22, 2026 17:51
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.

2 participants