Skip to content

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

Open
evanjacobson wants to merge 9 commits into
gastown-stagingfrom
improvement/gastown-log-town-id
Open

fix(gastown): tag structured logs with town IDs#3428
evanjacobson wants to merge 9 commits 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.

jrf0110 and others added 8 commits May 19, 2026 20:32
…rm (#3372)

Bug 1: @kilocode/cli@7.2.14 doesn't read KILO_AUTH_CONTENT, causing all
kilo serve session-ingest to silently no-op. Bumped to 7.3.1 which has the
feature. Verified KILO_AUTH_CONTENT present in binary strings.

Bug 2: buildPrewarmEnv didn't set KILO_AUTH_CONTENT, KILO_PLATFORM, or
KILO_ORG_ID, so mayor sessions (which go through prewarm) were invisible.
Extracted buildKiloAuthEnv helper from buildAgentEnv and used it in both
buildAgentEnv and buildPrewarmEnv.

Refs #3307

Co-authored-by: John Fawcett <john@kilcoode.ai>
* perf(gastown): shorten mayor cold start path

* fix(gastown): address mayor latency review feedback

* fix(gastown): remove stale mayor setup parameter

* fix(gastown): remove stale mayor setup comment
* feat(cloud-agent): add Gastown filter option to ChatSidebar and mobile modal

* fix(cloud-agent-next): remove stale comment in default branch handling

---------

Co-authored-by: John Fawcett <john@kilcoode.ai>
Make worktree creation tolerate an existing local branch with a missing worktree directory, and allow internal @kilocode package updates to bypass release-age delays.
@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
@jrf0110 jrf0110 force-pushed the gastown-staging branch from 8e60feb to c52272a Compare May 28, 2026 16:08
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