fix(gastown): propagate KILOCODE_TOKEN refresh to running containers#1759
Merged
jrf0110 merged 3 commits intogastown-stagingfrom Mar 31, 2026
Merged
fix(gastown): propagate KILOCODE_TOKEN refresh to running containers#1759jrf0110 merged 3 commits intogastown-stagingfrom
jrf0110 merged 3 commits intogastown-stagingfrom
Conversation
…sh and model swap Close 4 gaps where KILOCODE_TOKEN was never pushed to a running container after initial agent spawn, causing 401s after the 30-day JWT expired: 1. syncConfigToContainer() now includes KILOCODE_TOKEN in the env mapping so config updates propagate to the container. 2. LIVE_ENV_KEYS includes KILOCODE_TOKEN so model hot-swaps use the current process.env value instead of the stale startup snapshot. 3. CONFIG_ENV_MAP in the model update handler syncs kilocode_token to process.env before the SDK server restarts. 4. refreshContainerToken tRPC mutation now remints KILOCODE_TOKEN and pushes it via updateTownConfig + syncConfigToContainer. 5. Alarm loop proactively remints KILOCODE_TOKEN when within 7 days of its 30-day expiry, preventing silent expiration. Closes #1472
Contributor
Code Review SummaryStatus: 2 Issues Found | Recommendation: Address before merge Overview
Issue Details (click to expand)WARNING
Other Observations (not in diff)N/A Files Reviewed (4 files)
Reviewed by gpt-5.4-20260305 · 1,634,757 tokens |
jrf0110
added a commit
that referenced
this pull request
Mar 31, 2026
… by owner Address PR #1759 review comments: 1. KILOCODE_TOKEN now propagated to the running container process: - Extended POST /refresh-token to accept optional kilocodeToken field - Added pushKilocodeTokenToContainer() helper in container-dispatch.ts - syncConfigToContainer() now pushes KILOCODE_TOKEN via /refresh-token - Added KILOCODE_TOKEN to LIVE_ENV_KEYS (model hot-swap) and CONFIG_ENV_MAP (model update handler) 2. refreshContainerToken mutation now guards KILOCODE_TOKEN remint: - Only remints if the caller is the town owner (credentialUserId === user.id) - For org members, pushes the existing owner token instead of overwriting with the caller's identity
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.
Summary
Fixes KILOCODE_TOKEN not being refreshed on running containers (#1472). Closes 4 propagation gaps where token updates were not reaching the container, plus adds proactive alarm-based refresh:
KILOCODE_TOKENto the env mapping so config updates propagate to the container viasetEnvVar.KILOCODE_TOKENso model hot-swaps read the currentprocess.envvalue instead of the stale startup snapshot.kilocode_token→KILOCODE_TOKENmapping in the model update handler soprocess.envstays current before SDK server restart.KILOCODE_TOKENviamintKilocodeTokenand pushes it viaupdateTownConfig+syncConfigToContainer, so the "Refresh Token" button actually resolves 401s.refreshKilocodeTokenIfExpiring()that checks daily and proactively remints when within 7 days of the 30-day expiry, using decoded JWT payload claims to reconstruct user identity.Verification
generateKiloApiToken,resolveSecret,mintKilocodeToken,userFromCtx)Visual Changes
N/A
Reviewer Notes
refreshKilocodeTokenIfExpiringmethod decodes the JWT payload without signature verification — this is intentional since the DO is reading its own stored token to extract claims for re-signing. The Zod schema validates the parsed payload shape.lastKilocodeTokenCheckAt) resets on DO restart, which is fine — worst case is an extra check on first alarm after restart.