Harden VCS polling and CLI shutdown handling #3573
Closedbmdavis419(GitHub profile, opens in a new tab)wants to merge 15 commits into
main fromcodex/fix-vcs-poller-lifecycleopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XXL
- apps/server/src/vcs/VcsStatusBroadcaster.ts lines 384 to 388Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -355,4 +371,8 @@355371 cwd: string,356372 options?: { readonly refreshUpstream?: boolean },357373 ) {374+ const refreshExit =375+ options?.refreshUpstream === false376+ ? Exit.void377+ : yield* workflow.refreshStatusUpstream(cwd).pipe(Effect.exit);358378 if (options?.refreshUpstream !== false) {apps/server/src/vcs/GitVcsDriverCore.ts lines 53 to 53OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -48,4 +50,4 @@4850 const REVIEW_UNTRACKED_DIFF_MAX_OUTPUT_BYTES = 80_000;4951 const WORKSPACE_FILES_MAX_OUTPUT_BYTES = 120_000;5052 const STATUS_UPSTREAM_REFRESH_INTERVAL = Duration.seconds(15);51-const STATUS_UPSTREAM_REFRESH_TIMEOUT = Duration.seconds(5);53+const STATUS_UPSTREAM_REFRESH_TIMEOUT = Duration.minutes(1);apps/server/src/provider/Layers/EventNdjsonLogger.ts lines 593 to 593Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -279,0 +562,21 @@562+ ...state,563+ pending,564+ pendingBytes,565+ };566+ if (!shouldFlush) {567+ return Effect.succeed([null, nextState] as const);568+ }569+ return Effect.sync(() => {570+ const [drainResult, drainedState] = drainPending({571+ directory,572+ options: resolved,573+ state: nextState,574+ now,575+ close: false,576+ });577+ return [drainResult, drainedState] as const;578+ });579+ });580+ if (result) {581+ yield* reportDrainResult(result);582+ }apps/server/src/vcs/GitVcsDriverCore.ts lines 111 to 122Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -96,0 +101,21 @@101+ readonly objectDir: string;102+ readonly remoteName: string;103+ readonly cwd: string;104+105+ constructor(objectDir: string, remoteName: string, cwd: string) {106+ this.objectDir = objectDir;107+ this.remoteName = remoteName;108+ this.cwd = cwd;109+ }110+111+ [Equal.symbol](that: unknown) {112+ return (113+ that instanceof StatusRemoteRefreshCacheKey &&114+ this.objectDir === that.objectDir &&115+ this.remoteName === that.remoteName116+ );117+ }118+119+ [Hash.symbol]() {120+ return Hash.string(`${this.objectDir}\0${this.remoteName}`);121+ }apps/server/src/provider/Layers/EventNdjsonLogger.ts line 39OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -21,8 +21,19 @@21212222 import { toSafeThreadAttachmentSegment } from "../../attachmentStore.ts";232324-const DEFAULT_MAX_BYTES = 10 * 1024 * 1024;24+const MEBIBYTE = 1024 * 1024;25+const DAY_MS = 24 * 60 * 60 * 1_000;26+const MIN_RECORD_BYTES = 256;27+const DEFAULT_MAX_BYTES = 10 * MEBIBYTE;2528 const DEFAULT_MAX_FILES = 10;26-const DEFAULT_BATCH_WINDOW_MS = 200;29+const DEFAULT_BATCH_WINDOW_MS = 1_000;30+const DEFAULT_MAX_TOTAL_BYTES = 512 * MEBIBYTE;31+const DEFAULT_MAX_AGE_MS = 14 * DAY_MS;32+const DEFAULT_RETENTION_CHECK_INTERVAL_MS = 5 * 60 * 1_000;33+const DEFAULT_MAX_BUFFERED_BYTES = MEBIBYTE;34+const DEFAULT_MAX_BUFFERED_RECORDS = 512;35+const DEFAULT_MAX_RECORD_BYTES = MEBIBYTE;36+const DEFAULT_MAX_CACHED_SINKS = 64;2737 const GLOBAL_THREAD_SEGMENT = "_global";2838 const LOG_SCOPE = "provider-observability";39+const PROVIDER_LOG_FILE_PATTERN = /\.log(?:\.\d+)?$/u;
- apps/server/src/vcs/VcsStatusBroadcaster.ts line 196Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -188,6 +189,7 @@188189 const broadcasterScope = yield* Effect.acquireRelease(Scope.make(), (scope) =>189190 Scope.close(scope, Exit.void),190191 );191- const cacheRef = yield* Ref.make(new Map<string, CachedVcsStatus>());192+ const statusCache = new Map<string, CachedVcsStatus>();192193 const pollersRef = yield* SynchronizedRef.make(new Map<string, ActiveRemotePoller>());193194195+ const setCachedStatus = (cwd: string, status: CachedVcsStatus) => {apps/server/src/provider/Layers/EventNdjsonLogger.ts lines 297 to 299OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -123,8 +285,15 @@285+ failures.push({ filePath: file.filePath, cause });286+ return false;287+ }288+ };289+290+ const retained = files.filter((file) => {291+ if (input.now - file.mtimeMs <= input.maxAgeMs) return true;292+ return !remove(file);123293 });124294125- if (!sinkResult.ok) {126- yield* logWarning("failed to initialize provider thread log file", {127- filePath: input.filePath,128- errorTag: errorTag(sinkResult.error),129- });130- return undefined;295+ for (const file of retained.toSorted(296+ (left, right) => left.mtimeMs - right.mtimeMs || left.filePath.localeCompare(right.filePath),297+ )) {298+ if (totalBytes <= input.maxTotalBytes) break;299+ remove(file);
juliusmarminge closed this
Sign in to join this conversation.
Important
Review skipped#
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID:
cced1734-0611-493f-bdb1-bd2a98fcf64dYou can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
✨ Finishing Touches
🧪 Generate unit tests (beta)
Comment `@coderabbitai help` to get the list of available commands.