Skip to content

fix: running sessions follow the permission mode from Settings - #1930

Merged
santoshkumarradha merged 4 commits into
app/v3from
fix/approval
Oct 25, 2026
Merged

santoshkumarradha merged 4 commits into
app/v3from
fix/approval

Conversation

@santoshkumarradha

Copy link
Copy Markdown
Member

What changes

A running conversation now follows Settings > Permissions (tools.approvalMode: prompt or allow) on its next tool decision, in both directions, without a relaunch.

  • allow → prompt: the next tool call asks.
  • prompt → allow: the next tool call stops asking.
  • A posture set inside the conversation, launch overrides, project rules and dangerous-command floors keep their precedence.
  • A decision already waiting for approval keeps its question.
  • No polling loop: the gate refreshes before each tool decision and reuses the content-keyed policy cache when settings have not changed.

Correctness

  • A dedicated approval mutex serializes settings build → publication → decision snapshot. Concurrent refreshes cannot publish an older allow over a newer prompt, and a decision never falls back to an old policy while a newer refresh is unfinished.
  • Lock order: approval mutex before the agent mutex, never the reverse. The agent mutex is not held across the settings build (file I/O), so a stalled read cannot block Interrupt, StopWork, consent resolution or Close.
  • Profile read and JSON errors now reach the gate builder; a failed refresh keeps the previous policy instead of falling back to allow.
  • Factory stages reuse their fixed allow policy instead of compiling it per decision. Clarification conversations follow the parent's live gate; ordinary task workers keep their fixed allow policy (PERF.md corrected).

Validation

  • New deterministic tests (no sleeps) for: both directions of a live mode change, posture precedence, stale-publication ordering, unreadable profile, and a blocked build not delaying Interrupt/StopWork/Close. Each failed before its fix.
  • make test-focus with -race -count=3 on internal/session and the cmd/codeaf approval tests: pass.
  • Four independent review rounds; the last found no remaining defects.

Known pre-existing failures (also on app/v3)

  • Changelog gate: 228 existing violations, identical before and after this branch. This PR's own entry gets its number below.
  • Three retrieval test failures and the go vet context-leak report at internal/factory/run/chatstage.go:402, both unchanged by this branch.

🤖 Generated with Claude Code

santoshkumarradha and others added 4 commits October 24, 2026 21:35
Running sessions kept launch policies, and overlapping settings refreshes
could publish an older allow policy after a newer prompt policy. Profile
read failures were also treated as missing settings, reopening the gate.

Refresh before decisions, version refresh publication, and copy the validated
policy snapshot under the same lock. Propagate profile read and JSON errors
so failed refreshes retain the previous policy. Reuse immutable settings and
factory allow policies; clarify that only clarification conversations follow
the parent gate, while ordinary task workers use fixed allow.

Tests: reproduced stale publication, profile failures and repeated factory
compilation red before fixing them. Focused approval and posture tests pass,
including three race-detector runs across session, command and config packages.
Factory unchanged builds drop from 10 allocations to zero; the settings-gate
benchmark retains 29 allocations per build. Build and formatting checks pass.

Validation limits: make test-quick was run once and fails on an unchanged
factory reportCancel vet warning. Remaining gates also expose existing manual
retrieval, help and structural-law failures. The original manual reproduces
the retrieval failures. Changelog validation flags existing entries and this
change's draft PR-0 entry; no pull request is opened by this change.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Cause: starting a competing refresh invalidated a tool's successful prompt
build before a replacement was published. The tool could then fall back to
the previous allow policy and run without consent.

Fix: hold the existing session mutex across settings Build, publication and
immutable decision snapshot selection. Posture builds and explicit policy
pushes share that mutex. Remove approvalVersion and stale-publication
branches, preserving conversation overrides, failed-read retention and the
content-keyed settings cache. Update the manual, change entry and performance
documentation to describe serialized refreshes.

Tests: reproduce the consent bypass before fixing it. Channel-controlled
Builds cover both completion orders and both posture/refresh orders, with a
mutex-ownership assertion that detects the old design deterministically.
The final regressions fail against the original implementation in all three
runs. Focused approval, posture, consent, clarification, settings-read and
cache-reuse tests pass via make test-focus, including -race -count=3 across
session, command and config packages. Focused source and packed manual checks
and git diff --check pass. Standards and spec reviews have no findings.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Cause: refreshApprovalGate and SetApprovalPosture held the general Agent.mu
across gate.Build filesystem work, so a stalled read blocked Interrupt,
StopWork, consent resolution and Close.

Fix: serialize builds, publication, explicit policy pushes and snapshot
selection with approvalMu. Hold Agent.mu only for state reads and writes,
and document approvalMu-before-mu ordering. Preserve refresh ordering,
failed-build retention and immutable decision snapshots. Update the manual,
change entry and performance documentation.

Tests: first reproduce all four refresh/posture and Interrupt/StopWork
combinations with channel-blocked Builds, without sleeps. All pass after the
fix and confirm cancellation before Build is released. Run 105 focused
approval, consent and related tests via make test-focus across internal/session
and cmd/codeaf with -race -count=3; both packages pass. Existing approval
ordering tests remain, with their ownership assertion using approvalMu.
Focused session/TUI manual gates and source/packed permission checks pass.
Full manual checks reproduce the same three retrieval assertion failures at
the starting commit. Changelog check reports 228 identical baseline/candidate
metadata violations. git diff --check passes. Standards and spec reviews
report no findings.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@santoshkumarradha
santoshkumarradha merged commit 9e2ce4c into app/v3 Oct 25, 2026
1 check passed
@santoshkumarradha
santoshkumarradha deleted the fix/approval branch October 25, 2026 03:52
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