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
{{ message }}
Repository navigation
Commit 586909e
Browse filesBrowse the repository at this point in the historyBrowse files
// How long past the deadline the shim keeps its stdin listener for a payload already in the pipe: on Windows the pipe read completes on a worker thread, so the completion can land many event-loop turns after the listener attaches. Measured resume-to-data under 52 busy loops on 26 CPUs: p50 5.7 ms, max 204 ms.
/** Switch this process to the short waits of {@link HOOK_DB_WAIT_MS} for every connection it opens from now on. Called once by the one-shot `hook` command and by no other path: the worker, the indexer and every other CLI command keep the 15 s budget `initConnection` documents, because a patient wait is right for them. Connections opened before the call keep the budget they were opened with. `on = false` restores the patient budget, for tests. */
507
+
/** Set the hook/patient busy timeout on all cached connections and select that budget for future connections; `on = false` restores the patient budget. */
/** The busy_timeout and the WAL-switch deadline, in milliseconds, that a connection opened now gets: the patient indexing budgets, or the hook's short ones after {@link limitDbWaitsForHook}. */
Copy file name to clipboardExpand all lines: src/fingerprint.ts
+11-8Lines changed: 11 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -5,9 +5,7 @@ import * as fs from 'node:fs'
5
5
6
6
/** Return the hex-encoded SHA-256 of `content`. A `string` is encoded as UTF-8 before hashing so the digest matches Python's `hashlib.sha256(text.encode("utf-8")).hexdigest()` for identical text. A `Buffer` is hashed verbatim, matching `hashlib.sha256(raw).hexdigest()` for identical bytes. */
/** Return the first 16 hex chars of the SHA-256 of `content`, used for short cache keys. Extracted from ≥11 call sites that all use `.slice(0, 16)`. */
/** Return the hex-encoded SHA-256 of the file at `filePath`, or `null` if the file cannot be read (missing, permission denied, is a directory, etc.). Reads the raw bytes and hashes them verbatim, so the digest matches a content fingerprint computed over the same bytes. Never throws: any read failure collapses to `null` so callers on the hot hook path can branch without a try/catch. */
/** Read the raw bytes at `filePath` once and return both them and their hex-encoded SHA-256, or `null` if the file cannot be read. Never throws: any read failure collapses to `null` so callers on the hot hook path can branch without a try/catch. */
// Missing file, permission error, directory, or transient lock — the caller treats "no fingerprint" the same regardless of the cause.
41
39
returnnull
42
40
}
43
-
returnfingerprintContent(data)
41
+
return{sha: fingerprintContent(bytes), bytes }
42
+
}
43
+
44
+
/** Return the hex-encoded SHA-256 of the file at `filePath`, or `null` if the file cannot be read. Hashes the raw bytes verbatim, so the digest matches a content fingerprint computed over the same bytes. */
/** Is there genuinely no file at `filePath`? `true` only for ENOENT. A file that is present but cannot be examined right now -- a Windows ACL denial, EACCES on a parent directory, a disconnected network share -- answers `false`, because "I cannot tell" is not the same as "it is gone", and every caller here does something destructive or user-visible with a `true`. This is what `fs.existsSync` cannot give: existsSync is a stat inside a bare catch, so it answers `false` for a permission or I/O error exactly as it does for a missing file. Measured on Windows against a directory with a deny ACE for the current user: `existsSync` returned false for a file that was still there, while `statSync(p, { throwIfNoEntry: false })` threw EPERM. `throwIfNoEntry: false` returns `undefined` for ENOENT and only ENOENT, and throws for everything else, which is precisely the distinction. */
/** How long a slot gets to answer the handshake before the next slot is asked beside it. An idle server answers in 1 to 3 ms, so a slot silent this long is in synchronous work, and the caller now waits on it and the next slot at once instead of spending its whole budget on one slot and then the next: two slots each held past the handshake allowance used to use up the budget before the third, possibly idle, was ever asked. */
36
36
constHEDGE_MS=40
37
-
/** A dispatched hook request that has not answered by now is failed open. Matches the hook relay's own queue wait. A CLI request has no such limit (see attempt). */
37
+
/** Legacy wait for dispatched requests outside Copilot CLI hooks. CLI requests have no response limit (see attempt). */
38
38
constRESPONSE_TIMEOUT_MS=120_000
39
+
/** Default response wait for Copilot CLI hooks, well below their 60-second harness limit. */
40
+
constCOPILOT_HOOK_RESPONSE_TIMEOUT_MS=12_000
41
+
/** Leave 15 seconds before Copilot CLI's installed 60-second hook limit, even with an override. */
42
+
constMAX_COPILOT_HOOK_RESPONSE_TIMEOUT_MS=45_000
39
43
/** How long `status` and `stop` keep asking a slot whose handshake timed out. */
/** What lets several attempts wait on different slots at once while at most one of them dispatches: `claim` is asked on a verified challenge, with the canceller the attempt registered, and answers whether this attempt may send its request; `onCancel` registers what to run once another attempt has claimed. */
/** One attempt against one slot. Resolves exactly once. With `race`, an attempt that loses the claim, or is cancelled before its challenge arrives, hangs up without dispatching and resolves `busy`. */
// A CLI command waits for its answer however long it runs. The server cannot abandon a command it has started (the work is synchronous and nothing interrupts it), so giving up here only made the caller run the same command a second time beside it, on the same index, never faster (a 342.8 s `symbol` miss on a large project was 120 s of waiting here and then the whole command again). A server that dies mid-command still closes the connection, which reads as lost below, and the caller still runs it itself.
/** Record that the bytes behind each file's `sha` carried its `stamp.mtimeSec`, in one transaction. Each file is judged, and its `indexed_at` written, from the clock read before that file's hash, never from a clock read at the end of a sweep: a file saved again after the hash but before such a clock would otherwise look older than the index time it was given and never be hashed again. When the mtime is at least one tick older than that clock, `mtime` and `indexed_at = clockSec` are written together, so the row satisfies the racy-clean rule from the next sweep on. A newer mtime is not stamped with an index time: the file may still be mid-write, so it stays racy and is hashed again until it ages past the tick (only a moved mtime is recorded, as the pre-read probe's equality gate needs), and an `indexed_at` later than that clock, which only a clock that stepped back leaves, is lowered to it: a stamp is never left later than the clock that judged it, or a same-tick edit would read as proven unchanged. Guarded on the sha, so a row rewritten since keeps its stamp. Best-effort: a database error leaves the rows as they were. */
/** Record that the bytes behind each file's `sha` carried its `stamp.mtimeSec`, in one transaction. Each file is judged, and its `indexed_at` written, from the clock read before that file's hash, never from a clock read at the end of a sweep: a file saved again after the hash but before such a clock would otherwise look older than the index time it was given and never be hashed again. When the mtime is at least one tick older than that clock, `mtime` and `indexed_at = clockSec` are written together, so the row satisfies the racy-clean rule from the next sweep on. A newer mtime is not stamped with an index time: the file may still be mid-write, so it stays racy and is hashed again until it ages past the tick (only a moved mtime is recorded, as the pre-read probe's equality gate needs), and an `indexed_at` later than that clock, which only a clock that stepped back leaves, is lowered to it: a stamp is never left later than the clock that judged it, or a same-tick edit would read as proven unchanged. Guarded on the sha, so a row rewritten since keeps its stamp. Best-effort: a database error leaves the rows as they were and returns false. */
/** A symbol hit's preview: its docstring, else the first 140 characters of its body from the declaration on, so a decorated symbol previews as `def area(...)` rather than `@property`. */
// A byte budget, not a file count: a count of 300 stopped this repo's scan at src/ while its 1,874 indexed files came to 22.8 MB, read in under 200 ms.
// Through the reader seam, not a plain utf-8 read: the matching line is printed as the preview, so a dotenv value has to come back masked the way `read` shows it, and a UTF-16 file has to be decoded before a query can match it.
0 commit comments