GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat(server): refresh usage limits while no client watches (usage pacing part 2) by scuttletoby · Pull Request #42 · scuttletoby/t3code

feat(server): refresh usage limits while no client watches (usage pacing part 2) #42

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
scuttletoby merged 1 commit into main from fork/pacing-2-refresher
Nov 14, 2026

Uh oh!

There was an error while loading. Please reload this page.

Merged

feat(server): refresh usage limits while no client watches (usage pacing part 2) #42

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
1 commit
Select commit
3779d13
feat(server): refresh usage limits while no client watches (usage pac…
scuttletoby Nov 14, 2026
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view
feat(server): refresh usage limits while no client watches (usage pac…
…ing part 2)

A Scheduler job asks each signed-in provider instance for its usage
through upstream's refreshUsage while no client lease would make
upstream's own loop do it, so the usage history gets readings on a
headless server. Never more often than upstream's loop, never a login,
backoff with one log line per failing streak.

New server setting headlessUsageRefreshInterval (default 10 min, 0 = off).
The Duration is replaced whole in settings patches and kept whole in the
sparse settings file, like the other interval settings.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
  • Loading branch information

Uh oh!

There was an error while loading. Please reload this page.

@scuttletoby @claude
scuttletoby and claude committed Nov 14, 2026
commit 3779d13753228881c1a533f7ce1c7bb230689b86

There are no files selected for viewing

2 changes: 1 addition & 1 deletion 2 apps/server/src/background/BackgroundPolicy.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ function hasThermalPressure(hostPower: HostPowerSnapshot): boolean {
return hostPower.thermalState === "serious" || hostPower.thermalState === "critical";
}

function isHostConstrained(
export function isHostConstrained(
hostPower: HostPowerSnapshot,
settings: ResolvedBackgroundActivitySettings,
): boolean {
Expand Down
2 changes: 2 additions & 0 deletions 2 apps/server/src/server.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ import * as ProviderAdapterRegistry from "./orchestration-v2/ProviderAdapterRegi
import * as ProviderRegistry from "./provider/ProviderRegistry.ts";
import * as ProviderUsageLimitsIngestion from "./provider/ProviderUsageLimitsIngestion.ts";
import * as UsageReadingsHistory from "./usage/UsageReadingsHistory.ts";
import * as HeadlessUsageRefresher from "./usage/HeadlessUsageRefresher.ts";
import * as UsageLimitSources from "./usage/UsageLimitSources.ts";
import * as ProjectFaviconResolver from "./project/ProjectFaviconResolver.ts";
import * as T3ProjectFileLoader from "./project/T3ProjectFileLoader.ts";
Expand Down Expand Up @@ -683,6 +684,7 @@ const layerRuntimeCoreDependenciesBase = Layer.mergeAll(
).pipe(Layer.provide(DelegatedTaskQuestionReactor.layer), Layer.provide(ProjectionStoreV2.layer)),
ProviderUsageLimitsIngestion.layer,
UsageReadingsHistory.layer,
HeadlessUsageRefresher.layer,
layerProviderInstallationRefresh,
ProviderInstallation.layer,
ReplayMarkers.layer,
Expand Down
1 change: 1 addition & 0 deletions 1 apps/server/src/serverSettings.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,7 @@ const ATOMIC_SETTINGS_KEYS: ReadonlySet<string> = new Set([
"backgroundActivity",
"automaticGitFetchInterval",
"providerHealthRefreshInterval",
"headlessUsageRefreshInterval",
"sourceControlWriterModelSelection",
"reviewGuideModelSelection",
"textGenerationModelSelection",
Expand Down
92 changes: 92 additions & 0 deletions 92 apps/server/src/usage/HeadlessUsageRefresher.settings.test.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/**
* Fork: `headlessUsageRefreshInterval` through the real settings service: old files, patches,
* the sparse settings file and restarts.
*/
import * as NodeCrypto from "@effect/platform-node/NodeCrypto";
import * as NodeServices from "@effect/platform-node/NodeServices";
import { DEFAULT_SERVER_SETTINGS, ServerSettings, ServerSettingsPatch } from "@t3tools/contracts";
import { applyServerSettingsPatch } from "@t3tools/shared/serverSettings";
import { assert, it } from "@effect/vitest";
import * as Duration from "effect/Duration";
import * as Effect from "effect/Effect";
import * as FileSystem from "effect/FileSystem";
import * as Layer from "effect/Layer";
import * as Schema from "effect/Schema";

import * as ServerSecretStore from "../auth/ServerSecretStore.ts";
import * as ServerConfig from "../config.ts";
import * as SqlitePersistence from "../persistence/Sqlite.ts";
import * as ManagedPolicy from "../policy/ManagedPolicy.ts";
import * as ServerSettingsModule from "../serverSettings.ts";

const decodePatch = Schema.decodeUnknownSync(ServerSettingsPatch);
const decodeSettingsJson = Schema.decodeUnknownEffect(Schema.fromJsonString(ServerSettings));

/** One settings service; each provide is one server run over the same settings file. */
const serverRun = () =>
ServerSettingsModule.layer.pipe(
Layer.provide(ServerSecretStore.layer),
Layer.provide(ManagedPolicy.layerTest()),
Layer.provideMerge(Layer.fresh(SqlitePersistence.layerMemory)),
);

const minutesOf = (value: Duration.Duration) => Duration.toMillis(value) / 60_000;

it("a patch keeps the interval a whole Duration and leaves it alone when unrelated", () => {
const set = applyServerSettingsPatch(
DEFAULT_SERVER_SETTINGS,
decodePatch({ headlessUsageRefreshInterval: 15 * 60_000 }),
);
assert.isTrue(Duration.isDuration(set.headlessUsageRefreshInterval));
assert.equal(minutesOf(set.headlessUsageRefreshInterval), 15);
const unrelated = applyServerSettingsPatch(set, decodePatch({ enableAgentBrowserAccess: false }));
assert.equal(minutesOf(unrelated.headlessUsageRefreshInterval), 15);
const off = applyServerSettingsPatch(set, decodePatch({ headlessUsageRefreshInterval: 0 }));
assert.equal(Duration.toMillis(off.headlessUsageRefreshInterval), 0);
});

it.layer(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))("settings file", (it) => {
it.effect("an old file gets the default; a saved interval survives a restart, unchanged", () =>
Effect.gen(function* () {
const { settingsPath } = yield* ServerConfig.ServerConfig;
const fs = yield* FileSystem.FileSystem;
// Old state: a settings file written before the setting existed.
yield* fs.writeFileString(settingsPath, `{ "enableAgentBrowserAccess": false }`);
const first = yield* Effect.gen(function* () {
const service = yield* ServerSettingsModule.ServerSettingsService;
assert.equal(minutesOf((yield* service.getSettings).headlessUsageRefreshInterval), 10);
const saved = yield* service.updateSettings(
decodePatch({ headlessUsageRefreshInterval: 30 * 60_000 }),
);
assert.isTrue(Duration.isDuration(saved.headlessUsageRefreshInterval));
assert.equal(minutesOf(saved.headlessUsageRefreshInterval), 30);
// A second, unrelated save keeps it.
yield* service.updateSettings(decodePatch({ enableAgentBrowserAccess: true }));
return JSON.parse(yield* fs.readFileString(settingsPath));
}).pipe(Effect.provide(serverRun()));
assert.equal(first.headlessUsageRefreshInterval, 30 * 60_000);
assert.equal(
minutesOf((yield* decodeSettingsJson(JSON.stringify(first))).headlessUsageRefreshInterval),
30,
);

// A restart reads it back; turning it off and back to the default keeps the file sparse.
const second = yield* Effect.gen(function* () {
const service = yield* ServerSettingsModule.ServerSettingsService;
assert.equal(minutesOf((yield* service.getSettings).headlessUsageRefreshInterval), 30);
yield* service.updateSettings(decodePatch({ headlessUsageRefreshInterval: 0 }));
const off = JSON.parse(yield* fs.readFileString(settingsPath));
yield* service.updateSettings(decodePatch({ headlessUsageRefreshInterval: 10 * 60_000 }));
return { off, back: JSON.parse(yield* fs.readFileString(settingsPath)) };
}).pipe(Effect.provide(serverRun()));
assert.equal(second.off.headlessUsageRefreshInterval, 0);
assert.notProperty(second.back, "headlessUsageRefreshInterval");
}).pipe(
Effect.provide(
Layer.fresh(
ServerConfig.layerTest(process.cwd(), { prefix: "t3code-headless-usage-settings-test-" }),
),
),
),
);
});
Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

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.
You are visitor 01402809 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.