Skip to content

Policy: the coding pack reads more of what a shell command does before it decides, and stays fast - #664

Merged
LoopGlitch26 merged 16 commits into
mainfrom
agent/policy-reading-160
Nov 8, 2026
Merged

LoopGlitch26 merged 16 commits into
mainfrom
agent/policy-reading-160

Conversation

@LoopGlitch26

@LoopGlitch26 LoopGlitch26 commented Nov 8, 2026 •

Copy link
Copy Markdown
Member

The coding pack reads more of what a shell command does before it decides, and holds what it can't read.

  • The shell reader follows more of bash: parameter expansions read in every way they can combine (with a cap; past it the line is held), arrays, values a line gives a variable, wrappers and runners, commands inside arguments and option values, interpreter one-liners' literal arguments, config files a line writes and then uses, and typed keys. What it still can't read is held for a person, and the limits page lists what stays out of reach.
  • Each decision has one work budget, shared by every reading of the line (arguments read as commands, second readings, interpreter decoding). A line that spends it is held (TK-SHELL-PARSE, cause budget), never allowed or read again on a fresh budget.
  • Rules matched in any case read ſ and the Kelvin sign as s and k on both engines, as case-insensitive file systems do.
  • The signer refuses to use an approval for a call that already ran (TK-APPROVAL-UNBOUND; tests/test_signer_approvals.py).
  • A few more paths count as the actions they are: a force-update of a branch through the API, deletes of a home folder by other tools, and approvals answered through a copy or wrapper of the CLI.
  • Speed: about 400 µs at p99 on E21's default profile on a laptop, with the same verdicts as before the speed work (52,182 corpus decisions and a 39,890-call replay identical). CI now gates E21's latency on each runner's own reference time (p99 within 12x) instead of absolute microseconds, which measured the runner.
  • Coding pack 2026.10-v2-77. E17: 833 of 833 harmful calls stopped, 1 false alarm in 887.

Tests for each change are in tests/test_policy2.py and tests/test_signer_approvals.py.

…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
LoopGlitch26 merged commit 703583d into main Nov 8, 2026
34 checks passed
@LoopGlitch26
LoopGlitch26 deleted the agent/policy-reading-160 branch November 8, 2026 20:46
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant