Skip to content

chore(gastown): remove manual request logging middleware#3158

Open
jrf0110 wants to merge 3 commits intogastown-stagingfrom
chore/gastown-remove-request-logging-v2
Open

chore(gastown): remove manual request logging middleware#3158
jrf0110 wants to merge 3 commits intogastown-stagingfrom
chore/gastown-remove-request-logging-v2

Conversation

@jrf0110
Copy link
Copy Markdown
Contributor

@jrf0110 jrf0110 commented May 9, 2026

Summary

Removes the redundant request-logging middleware from gastown.worker.ts that logged every HTTP request twice (incoming + outgoing) via logger.info(). This is already covered by the per-route instrumented(c, route, handler) wrapper from analytics.middleware.ts which emits structured AE events with route, userId, townId, rigId, agentId, beadId, durationMs, and error for every wrapped route.

Two pieces removed:

  1. The import { logger } from './util/log.util' line (now unused at the worker level)
  2. The entire request-logging middleware block (regex constants + app.use('*', ...) with logger.setTags, logger.info calls)

Preserved: timingMiddleware and useWorkersLogger middleware — these are independent infrastructure that other code depends on.

Verification

Manual review of the diff confirms 30 lines deleted, 0 added, single file modified.

Visual Changes

N/A

Reviewer Notes

The logger.setTags call from URL regexes is safe to remove — those tags were only consumed by the two logger.info lines being removed. Auth middleware already sets orgId/userId tags via JWT-derived values. Town.do.ts runs in a separate isolate and does its own setTags.

@kilo-code-bot
Copy link
Copy Markdown
Contributor

kilo-code-bot Bot commented May 9, 2026

Code Review Summary

Status: No Issues Found | Recommendation: Merge

This is a clean deletion of redundant request-logging middleware. The removed code:

  • Duplicated what instrumented() already covers (per-route structured AE events with all the relevant IDs and duration)
  • The logger import is fully removed and no longer referenced anywhere in the file
  • timingMiddleware and useWorkersLogger are correctly preserved
Files Reviewed (1 file)
  • services/gastown/src/gastown.worker.ts — 0 issues

Fix these issues in Kilo Cloud


Reviewed by claude-sonnet-4.6 · 220,254 tokens

@jrf0110 jrf0110 changed the base branch from main to gastown-staging May 10, 2026 00:08
Comment on lines -193 to -198
logger.setTags({
orgId: RE_ORG.exec(path)?.groups?.orgId,
townId: RE_TOWN.exec(path)?.groups?.townId,
rigId: RE_RIG.exec(path)?.groups?.rigId,
agentId: RE_AGENT.exec(path)?.groups?.agentId,
});
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd still be nice to set tags on requests, but maybe we can do it in a way more structured way like:

app.use('/api/towns/:townId', async (c, next) => {
  logger.setTags({ townId: c.req.param('townId' })
  await next()
})

jrf0110 and others added 2 commits May 10, 2026 22:55
…ayor tools on prewarm

Three independent fixes for the startAgentInContainer timeout
regression introduced by #2974, plus a tighter container-instance cap.

1. Hydration gate (control-server.ts, process-manager.ts)
   The control server starts accepting requests immediately at boot,
   while bootHydration runs concurrently and serialises every registry
   agent + the mayor prewarm through the global sdkServerLock. Fresh
   /agents/start, /refresh-token, and PATCH /agents/:id/model requests
   queued behind that work and the DO-side AbortSignal.timeout(60s)
   fired before they ever got the lock — surfacing as
   "TimeoutError: aborted due to timeout" and "timeout after 6000ms:
   ensureSDKServer for <agentId>". A new awaitHydration() promise is
   awaited at the top of those handlers (before any process.env
   mutation in the model PATCH path) so they don't compound the queue.

2. Prewarm config matches /agents/start (Town.do.ts, gastown.worker.ts,
   process-manager.ts)
   buildPrewarmEnv was constructing KILO_CONFIG_CONTENT from hardcoded
   defaults (anthropic/claude-sonnet-4.6 / claude-haiku-4.5), so the
   real /agents/start with the user's actual model triggered
   ensureSDKServer's "config mismatch, evicting prewarmed server" path
   on every warm restart — doubling lock-holding time on the critical
   path the prewarm was supposed to speed up. The /api/towns/:id/mayor-id
   endpoint now returns the full prewarm context (model, smallModel,
   kilocodeToken, organizationId) resolved the same way _ensureMayor
   resolves it, and the container builds the prewarm KILO_CONFIG_CONTENT
   to match. Falls back gracefully to a skip when the worker hasn't
   deployed the richer endpoint yet.

3. Mayor workdir + plugin env (agent-runner.ts, process-manager.ts)
   prewarmMayorSDK called mayorWorkdirForTown (which only returns a
   string) and went straight to ensureSDKServer's process.chdir,
   throwing ENOENT on cold containers because createMayorWorkspace
   only ran from runAgent. Exported ensureMayorWorkspaceForTown so
   prewarm materialises the workspace first.

   More critically, buildPrewarmEnv was missing GASTOWN_AGENT_ROLE,
   GASTOWN_AGENT_ID, and GASTOWN_TOWN_ID — env vars the kilo serve
   plugin (plugin/index.ts) reads at spawn to decide whether to
   register mayor tools. Without them the prewarmed server booted with
   NO mayor tools, and the cache hit on the next /agents/start handed
   that defective instance back to the user. Now mirrors the mayor-
   shaped subset of buildAgentEnv. Added an end-to-end test that
   intercepts createKilo and asserts the env at spawn time.

4. wrangler.jsonc: lower TownContainerDO max_instances from 800 to 500.

Verified with pnpm --filter gastown-container test (67/67 pass),
pnpm --filter cloudflare-gastown typecheck, oxlint, and pnpm format.
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