Repository navigation
Policy: the coding pack reads more of what a shell command does before it decides, and stays fast - #664
Merged
Conversation
…e it decides, and stays fast
…t note on the latency caps
…nly literals with an escape A process call's arguments in inline code were read one character at a time, and every plain literal went through ast.literal_eval, so 64 KiB of subprocess.run([ took 7 to 10 times main's time to decide. Runs where no literal can start are now read in one step, and a literal with no backslash or carriage return is its own text. Verdicts are unchanged. Also: the decide-time child times with perf_counter (Windows' monotonic clock read a fast decision as 0 s), and E21's robustness result records the current policy hash.
…on reads A decision's sub-reads each had a budget of their own: each argument read as a command was a full decision with a fresh budget (6,500 quoted arguments took 0.75 s), a line the parser couldn't read was read again in pieces on a fresh budget, and a function body's dry read had its own. The parse, its other readings, what is read of an unreadable line and each argument read as a command (128 more each) now spend one budget and one fallback deadline. Once the budget is spent nothing more is read and the call is held (TK-SHELL-PARSE, cause budget), never allowed. A head the decision can't afford to read again isn't read again; an arithmetic expansion costs what a command does; an argument with no letter (blank escapes aside) and no $'...' isn't read as a command; the argv form with WORD_SPACE is built only where a word before the last has a space, so sqlite3's SQL is searched once.
…he same verdicts - shell: read a run of plain arguments, a run of blanks, and double-quoted or heredoc text in one step each - classes: read a run of SQL text that opens no comment, literal or quote in one step - compile and engine: a pattern whose top level is a group of alternatives is searched only on a subject that holds a string of each set of one alternative (requirements): TK-A039's sqlite3 branch isn't searched on a SELECT - engine: look for a dot or // before the dotted-path search; don't combine the ways of no expansion - tests: the pipeline that spends the whole work budget is held to 2 s (CI's py3.9 Linux runner took 1.07 s); the prefilter tests check requirements too, and TK-A039 is not searched on a SELECT The corpora (every pack, both engines), the week's 39,890 calls, E17 and the parser oracle decide as before. Signed-off-by: LoopGlitch26 <53336715+LoopGlitch26@users.noreply.github.com>
… pattern The Tracekit-paths reading searched each of a command's words for a pathname pattern; a line of 21,800 words spent 3 ms on it. A word with no *, ? or [ holds none, so the words joined are checked first. Decisions are unchanged on the corpora (every pack, both engines) and the week's 39,890 calls. Signed-off-by: LoopGlitch26 <53336715+LoopGlitch26@users.noreply.github.com>
…iB or more Checking them on every subject made E21's calls decide 2-4% slower at p99 (CI's Linux runner then measured default/regex at 1,092 us, over its 1 ms check); a short subject's search costs no more than the check. With the check from 1 KiB, E21's p99 is back at the previous commit's on both engines, and a 60 KiB SELECT still isn't searched for TK-A039. Decisions are unchanged on the corpora (every pack, both engines), the week's calls and E17. Signed-off-by: LoopGlitch26 <53336715+LoopGlitch26@users.noreply.github.com>
…'s bound on slow runners Both decisions read the statement as a command, which the decision's budget caps: about 70-80 ms on a laptop, and about 10x that on CI's Windows runners (0.737 s for the mongosh case on py3.13, over the 0.5 s bound). They are held to 2 s, as the budget-spending pipeline is; a runaway search still fails them, as nondeterministic. The other speed tests stay within their bounds at 10x their laptop times, or scale with the machine. Signed-off-by: LoopGlitch26 <53336715+LoopGlitch26@users.noreply.github.com>
…her speed tests do The mongosh whitespace, indented-SELECT and long-pipeline bounds were a flat 2 s. Each is now about five times its laptop time, scaled by machine_scale (1 to 4): 0.4 s for the statement read as a command (up to 80 ms on a laptop), 0.35 s for the SELECT (about 70 ms) and 1.25 s for the pipeline that spends the whole work budget (about 0.26 s). A runner ten times slower than the laptop passes where it runs the scale's search at least 2.5 times slower. Signed-off-by: LoopGlitch26 <53336715+LoopGlitch26@users.noreply.github.com>
Signed-off-by: LoopGlitch26 <53336715+LoopGlitch26@users.noreply.github.com>
Signed-off-by: LoopGlitch26 <53336715+LoopGlitch26@users.noreply.github.com>
…arser holds it, too #673's check for typed text that sets state a later line runs read the line with the policy's shell parser and left a line it can't read to the signer. This branch's parser holds a state variable set to text it can't name (PS1, BASH_ALIASES, BASH_CMDS), a nameref to one and `hash -p`, so `read PS1` or `BASH_CMDS[ls]=/tmp/x` were held, not denied (tests/test_agent_hooks.py's typed-state test). Such a line is now read as the engine reads an unreadable one, each piece's words as written, with an assignment as its first word; one with no state word still goes to the signer. Signed-off-by: LoopGlitch26 <53336715+LoopGlitch26@users.noreply.github.com>
… a rule matched in any case TK-D007 matches in any case, and RE2 folds a long s (U+017F) to s and the Kelvin sign to k. The prefilters read a subject lower-cased, which keeps both, so a read of ~/.tracekit-ſigner/… past 1 KiB held none of TK-D007's alternatives' strings, wasn't searched, and was allowed where d7beb4c denied it (the review of dde5208). casefold() maps those two to the same letters and keeps every ASCII letter lower() makes, so a subject is read casefolded; a requirement string that isn't ASCII gives its rule no requirements. Signed-off-by: LoopGlitch26 <53336715+LoopGlitch26@users.noreply.github.com>
… long s as s and the Kelvin sign as k RE2's case-insensitive match folds U+017F to s and U+212A to k, as macOS's file system does; the fallback engine's ASCII mode folds neither. TK-D007 still held most such reads through their casefolded path forms, but not one whose casefolded form is the installed package's (`~/.tracekit-ſigner/dist-packages/tracekit/…`: st is st), which RE2 denied and the fallback allowed. A pattern matched in any case is now also searched, on the fallback, with those two characters as their ASCII letters, within the decision's deadline (two linear searches at most). Signed-off-by: LoopGlitch26 <53336715+LoopGlitch26@users.noreply.github.com>
…r fifteen times the laptop On CI's macOS py3.13 runner the mongosh whitespace case took 1.217 s, about 15 times its laptop time, while machine_scale read 1.6: this work, reading the statement as a command, slows more there than the regex search the scale times. Both database-statement tests now allow 1.0 s times the scale, about twelve times the laptop at a scale of 1, so a runner 15 to 20 times slower passes. The pipeline test keeps its bound. Signed-off-by: LoopGlitch26 <53336715+LoopGlitch26@users.noreply.github.com>
… microseconds Signed-off-by: LoopGlitch26 <53336715+LoopGlitch26@users.noreply.github.com>
LoopGlitch26
added a commit
that referenced
this pull request
Nov 10, 2026
Main's parser and rules (#664 and the 1.6.0 work) are the base; #605's changes are re-applied on top: - engine: main's rule entries (requirements, memo key, hidden-command pass) carry #605's prefilter set and the harness class (_reaches); main's skip of a rule whose read subjects hold none of its strings uses _holds too. - engine._finer: a pattern's requirements are left out where each alternative needs one string of a single set and those sets are its literals, so the set search isn't followed by a scan of every string (the literals check made it). - coding.yaml: TK-D003 keeps main's send-pack and adds hub and --attr-source; TK-F009 and TK-F015 move to ask with main's newer text ($XDG_CONFIG_HOME); version 2026.11-v2-78. - tests: a forced update of main through the API, and a + push refspec given with -c, are TK-D003's deny on main now (it reads the force field and the config); the push tests expect that, with TK-A056 still among the rules. - docs: main's rows with #605's edits; eval results taken from main, to be regenerated. Signed-off-by: LoopGlitch26 <53336715+LoopGlitch26@users.noreply.github.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The coding pack reads more of what a shell command does before it decides, and holds what it can't read.
TK-SHELL-PARSE, causebudget), never allowed or read again on a fresh budget.ſand the Kelvin sign assandkon both engines, as case-insensitive file systems do.Tests for each change are in tests/test_policy2.py and tests/test_signer_approvals.py.