You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
add the Gastown usage-billing specification and integrate the merged @kilocode/container-usage client
bind Gastown to container-usage-meter#ContainerUsageMeter through a typed WorkerEntrypoint service binding
always report container usage to the meter (start, 5-min heartbeat, stop) whenever the CONTAINER_USAGE binding is present, independent of any feature flag, so real usage can be monitored before charging
gate enforcement (admission blocks, low-balance stops, billing-blocked draining) behind GASTOWN_BILLING_ENABLED; add an enforcing field to billing status so the UI blocks cold starts only under enforcement while still showing the run estimate
report durable, retry-safe start/heartbeat/final-stop segments using gastown-standard-2026-07, with SKU-rated cost estimates read from the catalog
add a durable user circuit breaker (automatic-start toggle) that saves work, stops the container, and prevents automatic restarts
recover stale pre-integration billing state, self-heal missing remote intervals, and force-close locally after repeated meter failures
fix a new-town bug where a transient boot-time runtime status force-closed the just-started interval
enable enforcement and announcement UI automatically in development while retaining production defaults
polish the terminal resize handle, bottom tab alignment, and cost-explanation tooltip
ensure dev:start gastown always launches the meter under the shared Wrangler dev registry (with regression tests)
Feature flags
GASTOWN_BILLING_ENABLED — enforcement only (does not gate metering).
Metering runs whenever the CONTAINER_USAGE binding exists.
Verification
Manual end-to-end customer charging not performed: production enforcement is off and the merged meter returns continue for every heartbeat (no wallet admission/debit yet). Metering runs for shadow monitoring.
Reviewer notes
Production SKU gastown-standard-2026-07 must exist in the catalog before enabling enforcement.
Automated checks passing: Gastown typecheck/lint and 317 unit tests, web typecheck + targeted lint, focused meter integration tests, launcher tests, and git diff --check.
The only in-scope commit since the last review is a pure refactor extracting nested ternaries into two named helper functions (idleBillingState, openIntervalBillingState) in container-usage-state.billing.ts, with identical logic and no new issues; all prior findings remain resolved as reported previously.
Files Reviewed (1 file changed since last review)
services/gastown/src/billing/container-usage-state.billing.ts - refactor only, logic verified equivalent to prior ternary chain, no new issues
Note
services/container-usage-meter/package.json appears in the commit range but is identical to main (net-zero vs. the PR base) and is correctly excluded from the PR diff.
All 8 previously reported issues (billing error handling in Town.do.ts/TownContainer.do.ts, error classification in router.ts, and degraded-state terminal gating in MayorChat.tsx/TerminalBar.tsx) are fixed in this commit, and no new issues were found in the changed code.
Files Reviewed (5 files changed since last review)
apps/web/src/components/gastown/MayorChat.tsx - previous CRITICAL (degraded state disconnecting terminal) fixed
apps/web/src/components/gastown/TerminalBar.tsx - previous CRITICAL/WARNING (degraded state omitted from Mayor and agent terminal gating) fixed
Status: 8 Issues Found | Recommendation: Address before merge
Overview
Severity
Count
CRITICAL
3
WARNING
4
SUGGESTION
1
Issue Details (click to expand)
CRITICAL
File
Line
Issue
services/gastown/src/dos/Town.do.ts
990
prepareContainerBilling throws for towns with unresolved billing owner fields, breaking unrelated config/token updates -- now reachable in strictly more environments since metering runs whenever CONTAINER_USAGE is bound, independent of enforcement
services/gastown/src/dos/TownContainer.do.ts
241
Uncaught INSUFFICIENT_CREDITS from completeBillingStart skips low-balance shutdown handling; phase stays stuck on starting
apps/web/src/components/gastown/MayorChat.tsx
82
degraded billing state still disconnects the terminal when enforcement is on, contradicting the spec's "keep running" requirement (check renamed from enabled to enforcing, same gap remains)
WARNING
File
Line
Issue
services/gastown/src/dos/Town.do.ts
960
getBillingStatus can throw uncaught; tRPC endpoint doesn't map the error
services/gastown/src/dos/Town.do.ts
5989
Unguarded destroyWithBilling() can block storage teardown in destroy() on a billing-settlement failure
services/gastown/src/trpc/router.ts
103
Fragile error classification in mapContainerBillingError misclassifies unrelated failures as billing errors
apps/web/src/components/gastown/TerminalBar.tsx
1431
terminalEnabled (line 1434, also affecting agent-terminal gating at line 1571) and creditPaused/automaticStopInProgress (line 1431) omit degraded, disconnecting the Mayor terminal and showing misleading paused-overlay copy during a transient billing hiccup
SUGGESTION
File
Line
Issue
services/gastown/src/dos/Town.do.ts
5625
getAlarmStatus has an unguarded dependency on the container DO
Files Reviewed (14 files changed since last review)
services/gastown/src/dos/TownContainer.do.ts - fixed the enforcement-off low-balance stop, added settlement-retry/force-close handling, and narrowed runtime-stopped detection to fix the new-town force-close bug
degraded billing state disconnects the terminal, contradicting the spec's "keep running" requirement
WARNING
File
Line
Issue
services/gastown/src/dos/Town.do.ts
959
getBillingStatus can throw uncaught; tRPC endpoint doesn't map the error
services/gastown/src/dos/Town.do.ts
5968
Unguarded destroyWithBilling() can block storage teardown in destroy() on a billing-settlement failure
services/gastown/src/trpc/router.ts
103
Fragile error classification in mapContainerBillingError misclassifies unrelated failures as billing errors
apps/web/src/components/gastown/TerminalBar.tsx
1433
terminalEnabled omits degraded, disconnecting the Mayor terminal during a transient billing hiccup (also affects agent-terminal gating at line 1564, and the paused overlay at line 1431)
SUGGESTION
File
Line
Issue
services/gastown/src/dos/Town.do.ts
5605
getAlarmStatus has an unguarded dependency on the container DO
Status: 8 Issues Found | Recommendation: Address before merge
Executive Summary
The billing state machine still leaves a container running with a stuck starting phase when completeBillingStart fails, and the degraded billing state still incorrectly disconnects Mayor/agent terminals in violation of the spec.
Overview
Severity
Count
CRITICAL
3
WARNING
4
SUGGESTION
1
Issue Details (click to expand)
CRITICAL
File
Line
Issue
services/gastown/src/dos/Town.do.ts
989
prepareContainerBilling throws for towns with unresolved billing owner fields, breaking unrelated config/token updates
services/gastown/src/dos/TownContainer.do.ts
233
Uncaught billing error (BILLING_UNAVAILABLE, previously also INSUFFICIENT_CREDITS) skips shutdown handling; phase stays stuck on starting
apps/web/src/components/gastown/MayorChat.tsx
82
degraded billing state disconnects the terminal, contradicting the spec's "keep running" requirement
apps/web/src/components/gastown/TerminalBar.tsx
1403
terminalEnabled omits degraded, disconnecting the Mayor terminal during a transient billing hiccup
WARNING
File
Line
Issue
services/gastown/src/dos/Town.do.ts
959
getBillingStatus can throw uncaught; tRPC endpoint doesn't map the error
services/gastown/src/dos/Town.do.ts
5968
Unguarded destroyWithBilling() can block storage teardown in destroy() on a billing-settlement failure
services/gastown/src/trpc/router.ts
103
Fragile error classification in mapContainerBillingError misclassifies unrelated failures as billing errors
apps/web/src/components/gastown/TerminalBar.tsx
1534
Agent terminal enabled gating inconsistent with the Mayor terminal panes, also omits degraded
apps/web/src/components/gastown/TerminalBar.tsx
1401
creditPaused/paused overlay omits degraded, showing misleading "never started" copy during a transient billing hiccup
SUGGESTION
File
Line
Issue
services/gastown/src/dos/Town.do.ts
5605
getAlarmStatus has an unguarded dependency on the container DO
Status: 8 Issues Found | Recommendation: Address before merge
Executive Summary
The billing state machine has a critical gap where insufficient-credit detection during container start can leave a container running unbilled/unstopped, and the web UI's degraded billing state incorrectly disconnects terminals in violation of the spec.
Overview
Severity
Count
CRITICAL
4
WARNING
3
SUGGESTION
1
Issue Details (click to expand)
CRITICAL
File
Line
Issue
services/gastown/src/dos/Town.do.ts
968
prepareContainerBilling throws for towns with unresolved billing owner fields, breaking unrelated config/token updates
services/gastown/src/dos/TownContainer.do.ts
209
Uncaught INSUFFICIENT_CREDITS skips low-balance shutdown; phase also stays stuck on starting
apps/web/src/components/gastown/MayorChat.tsx
76
degraded billing state disconnects the terminal, contradicting the spec's "keep running" requirement
apps/web/src/components/gastown/TerminalBar.tsx
1305
terminalEnabled omits degraded, disconnecting the Mayor terminal during a transient billing hiccup
WARNING
File
Line
Issue
services/gastown/src/dos/Town.do.ts
956
getBillingStatus can throw uncaught; tRPC endpoint doesn't map the error
services/gastown/src/trpc/router.ts
100
Fragile error classification in mapContainerBillingError misclassifies unrelated failures as billing errors
apps/web/src/components/gastown/TerminalBar.tsx
1413
Agent terminal enabled gating inconsistent with Mayor terminal panes, also omits degraded
SUGGESTION
File
Line
Issue
services/gastown/src/dos/Town.do.ts
5546
getAlarmStatus now has an unguarded dependency on the container DO
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
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
@kilocode/container-usageclientcontainer-usage-meter#ContainerUsageMeterthrough a typed WorkerEntrypoint service bindingCONTAINER_USAGEbinding is present, independent of any feature flag, so real usage can be monitored before chargingGASTOWN_BILLING_ENABLED; add anenforcingfield to billing status so the UI blocks cold starts only under enforcement while still showing the run estimategastown-standard-2026-07, with SKU-rated cost estimates read from the catalogdev:start gastownalways launches the meter under the shared Wrangler dev registry (with regression tests)Feature flags
GASTOWN_BILLING_ENABLED— enforcement only (does not gate metering).GASTOWN_BILLING_ANNOUNCEMENT_ENABLED— upcoming-billing announcement UI.CONTAINER_USAGEbinding exists.Verification
continuefor every heartbeat (no wallet admission/debit yet). Metering runs for shadow monitoring.Reviewer notes
gastown-standard-2026-07must exist in the catalog before enabling enforcement.git diff --check.