Skip to content

refactor: unify resolve_session_id() + wire pytest-gate recording (#904, #802)#1020

Open
akaszubski wants to merge 4 commits into
masterfrom
refactor/unify-resolve-session-id
Open

refactor: unify resolve_session_id() + wire pytest-gate recording (#904, #802)#1020
akaszubski wants to merge 4 commits into
masterfrom
refactor/unify-resolve-session-id

Conversation

@akaszubski
Copy link
Copy Markdown
Owner

Summary

Net diff: +196 / -64.

Provenance disclosure

This work appeared in the working tree during session b6970545 (W0 implementation, issue #1012) without being authored by the session coordinator. Most likely cause: the autonomous-dev plugin source is symlinked from the realign repo (verified — pytest output shows test files resolving via <- ../../../realign/plugins/autonomous-dev/tests/...). A session running on realign's copy of the plugin wrote these files; they appeared here through the symlink during this session's runtime.

Filed as #1019 with acceptance: identify root cause (this PR's symlink hypothesis is the leading candidate) + add a defense-in-depth PreToolUse gate that blocks plugin source-tree writes from any actor, not just the coordinator.

The work is being merged because:

  1. It's correct (8/8 tests pass, addresses tracked issues [ROOT-CAUSE] Pipeline state + session-ID propagation contract is undocumented infra (#898 #902 #875) #904 + [INCOMPLETE] researcher-local, researcher, security-auditor absent in full-mode pipeline for #1040 (TemplateEvaluator) #802)
  2. It directly addresses one mechanism of feat(hooks): user-gated bypass mechanism — /bypass-hooks slash command + expiry, replace silent file marker #1018 (silent enforcement bypass via session-id divergence)
  3. Discarding good work that fixes real bugs because of how it arrived would throw the baby out with the bathwater

Test plan

  • 8 new unit tests pass: pytest plugins/autonomous-dev/tests/test_pipeline_completion_state.py plugins/autonomous-dev/tests/test_stop_quality_gate.py -v
  • Spot-check commands/implement.md STEP 0 / STEP 2 still resolve session_id correctly (manual review of the 3 replaced call sites)
  • Verify record_pytest_gate_passed exists at pipeline_completion_state.py:732 (referenced by new stop_quality_gate.py auto-record path) — ✅ confirmed

Related issues

Branch

refactor/unify-resolve-session-idmaster

🤖 Generated with Claude Code

akaszubski and others added 4 commits May 3, 2026 11:38
…cording (#904, #802)

Eliminates 3 inline copies of the session-id fallback chain in implement.md
(STEP 0 ordering check, STEP 0 pipeline state init, STEP 2 alignment-gate
state update) by extracting them into pipeline_completion_state.resolve_session_id().
Wires Issue #802's pytest-gate completion recording into stop_quality_gate.py
so end-of-turn pytest passes auto-record under the resolved session_id (with
a guard that excludes 'unknown' sessions to avoid polluting state from non-
pipeline runs).

Files:
- lib/pipeline_completion_state.py: +46 LOC adding resolve_session_id() + module
  constants _IMPLEMENT_STATE_SENTINEL + _SESSION_SENTINEL_TTL_SECONDS. Docstring
  cites Issue #904 with the divergence example.
- commands/implement.md: -49 net LOC; 3 inline copies replaced with one import.
- hooks/stop_quality_gate.py: +15 LOC auto-record on pytest pass (Issue #802 wiring).
- tests/test_pipeline_completion_state.py: 5 tests (env-var precedence, sentinel
  fallback, stale sentinel ignored, no-signal returns 'unknown', env 'unknown'
  treated as no signal).
- tests/test_stop_quality_gate.py: 3 tests (records under real session_id, skips
  on 'unknown' session, skips when pytest failed).

All 8 new tests pass.

Provenance disclosure: this work appeared in the working tree during session
b6970545 (W0 implementation, issue #1012) without being authored by the session
coordinator. The most likely cause is the symlinked plugin sharing between
autonomous-dev and the realign repo (verified: pytest output shows test files
resolving via '<- ../../../realign/plugins/autonomous-dev/tests/...'). A session
running on realign's plugin copy wrote these files; they appeared here through
the symlink. Filed as #1019 for investigation + defense-in-depth (PreToolUse
gate on plugin source-tree writes by ALL actors, not just the coordinator).

The work is committed because:
1. It's correct (all tests pass, addresses tracked issues #904 and #802)
2. It directly addresses one mechanism of #1018 (silent enforcement bypass via
   session-id divergence)
3. Discarding good work that fixes real bugs because of *how* it arrived would
   throw the baby out with the bathwater

Issues:
- #904 — session-id propagation contract (this commit unifies the fallback chain)
- #802 — agent completeness gate (this commit wires the pytest-gate recording)
- #1019 — provenance investigation (filed in this same session)

Refs: #1017 (CLAUDE.md hook deadlock protocol), #1018 (user-gated bypass),
#1019 (silent agent/hook source-tree writes audit)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…1017)

Adds two Critical Rules and two harness-philosophy sections:

- **Hook deadlock protocol** (#1017): When a hook blocks legitimate work,
  surface the block to the user with the proposed bypass and wait for
  approval. Do NOT autonomously create .claude/.bypass or set
  AUTONOMOUS_DEV_BYPASS=1 — those are user-authorized signals, not
  model-invokable. Replicated into ~/.claude/CLAUDE.md so foreign-repo
  sessions see the same rule.

- **Process applies WHEN doing software development**: Replaces the older
  "Don't simplify, redesign, or consolidate agents" rule. Codifies the
  intent-aware-enforcement direction from PROJECT.md — gates apply on
  real feature work for repos, not on testing/exploration/scratch edits.

- **Documentation Alignment** + **Maintaining Core Philosophy** sections:
  Document the validate_claude_alignment.py pipeline and the priority
  order for keeping PROJECT.md / orchestrator.md / settings in sync.

Closes #1017.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.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