Repository navigation
tier2: verify in-workspace repos against the session-start snapshot (r3 M1, delta LOW-1) - #6
Open
Vibherpunk wants to merge 1 commit into
Open
Vibherpunk wants to merge 1 commit into
Vibherpunk wants to merge 1 commit into
Conversation
Follow-up r3 M1 from the PR #3 review. Repositories inside the workspace still used get_or_set_session_baseline, which is lazy (HEAD after whatever tool ran first; PostToolUse calls it for every tool cwd) and falls back to a git ref and a halt-dir cache the agent can write. A conftest tamper committed through the shell before the first edit therefore became the baseline and passed Phase 5, Phase 8 and the Tier 2 tamper check. When SessionStart snapshotted the repository (trusted_repo_baseline): - Phase 5: lineage against the snapshot; stash compared by value with the session-start refs/stash instead of by its agent-settable %ct. - Phases 6 and 8: changed lines and assertion counts against the snapshot (git show <sha>:./<rel>, so a workspace below the top-level works). - Phase 9: check_outside_repo_integrity (lineage, stash, manifest/conftest tamper with the explicit baseline, assertion deletion, tautologies) now runs for in-workspace targets too, anchored at the target's git top-level. No snapshot for an in-workspace repository (another harness, hook installed mid-session, id-less session, SessionStart budget exhausted): today's lazy behaviour is kept, because failing closed would halt every such session. HARDTRUTH_REQUIRE_SESSION_SNAPSHOT=1 opts into failing closed (non-remediable). Repositories outside the workspace still always fail closed without one. Snapshots under id-less session ids ("unknown", "default") are never trusted: every such session shares one daemon key. delta LOW-1: the snapshot_repos_at_session_start docstring now says the hook can outlive its budget by up to 3s (a running worker makes two sequential 1.5s calls), not one call; a test measures it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.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.
Follow-up to #3: round-3 review r3 M1 and delta LOW-1.
Problem (r3 M1)
Repositories inside the workspace still used
get_or_set_session_baseline. That function is lazy: it records HEAD after whatever tool ran first, andhandle_post_tool_usecalls it for every tool cwd. It falls back torefs/hardtruth/baseline/<conv_hash>and a halt-dir cache, both of which the agent can write. A conftest tamper committed through the shell before the first edit therefore became the baseline, and it passed Phase 5, Phase 8 and the Tier 2 tamper check.Change (
client/hardtruth_hook.py)If SessionStart registered a snapshot for the workspace repo, or for an in-workspace target's git top-level (
trusted_repo_baseline):refs/stash, not by its%ct, which can be backdated. The code is factored out ascheck_repo_lineage_and_stash.git show <sha>:./<rel>is used so that a workspace below the top-level works.check_outside_repo_integritynow also runs for in-workspace targets. It checks lineage, stash, manifest/conftest tamper with the explicit baseline, assertion deletion and tautologies, anchored at the target's toplevel.unknown,default) are never trusted, because every such session shares one daemon key.No snapshot for an in-workspace repo (the decision)
Today's lazy behaviour is kept by default. A snapshot can be missing because:
Failing closed by default would halt every one of those sessions.
HARDTRUTH_REQUIRE_SESSION_SNAPSHOT=1opts into failing closed, with a non-remediable halt. Repositories outside the workspace still always fail closed without a snapshot. The policy is documented in the "Repositories inside the workspace" comment block.delta LOW-1
The
snapshot_repos_at_session_startdocstring now gives the overrun bound as up to 3s. A worker already running makes two sequential 1.5s calls, and the process exits only after in-flight workers finish. Previously it said one call (1.5s). A new test measures this: the last call ends more than budget + 1.5s and less than budget + 3s (+0.5s slack) after the start.Tests
New file
tests/test_tier2_in_workspace_snapshot.py(13 tests). They run end to end through the realhandle_session_startandhandle_stopwith the fake first-write-wins daemon; the class subclassesTestStopHookOutsideReposwith the workspace being the repo. Cases:refs/hardtruth/baseline/*ref plus halt-dir cache files are ignored;HARDTRUTH_REQUIRE_SESSION_SNAPSHOT=1;unknownordefaultare ignored;With
hardtruth_hook.pyfrom main, 6 of the halt tests fail (they allow the Stop).Full suite:
python3 -m pytest tests/ -q -p no:cacheprovidertest_concurrency_load(load-flaky).test_concurrency_load(test_concurrent_secret_isolation_and_no_data_leakage, connection resets; it also failed on main).Not changed / notes
get_git_modified_source_filesstill lists modified files against the lazy baseline. Committed test weakening outsidemodified_pathsis now caught by the Phase 9 whole-repo diff for snapshotted repos.check_manifest_tamperingwithout an explicit baseline) is unchanged. The hook now runs the snapshot-anchored check before the handoff.trusted_repo_baselineand the stash lookup routed through the manifest, and the LOW-1 docstring/test reworked for the one-call design. The in-workspace wiring (workspace_snapshot_baseline, Phases 5/6/8/9) stays as is.Not installed into
~/.hardtruth.🤖 Generated with Claude Code