When code performs expensive IO (git/network/subprocess/clipboard capture), it must (1) avoid redundant work, (2) avoid over-scoped enumeration before it’s necessary, and (3) degrade gracefully when caps are hit.
Apply this standard
{ state: "partial" } (or equivalent) instead of failing into { state: "unavailable" }.Example pattern (reuse snapshot once)
// BAD: captures twice (expensive clipboard round-trip)
await returnCurrentTerminalContents();
telemetry.captureTerminalOutputFailure(TerminalOutputFailureReason.TIMEOUT);
// GOOD: capture once and reuse
const snapshot = await returnCurrentTerminalContents(); // should return what it fetched
telemetry.captureTerminalOutputFailure(
snapshot.success
? TelemetryReason.SUCCESS
: TelemetryReason.TIMEOUT,
snapshot
);
Example pattern (partial under caps)
const { stdout, state } = await readGitSnapshotWithCaps(cwd);
if (state === 'partial') {
emitPartialSnapshot({ /* include HEAD/branch, omit noisy sections */ });
} else {
emitFullSnapshot(stdout);
}