Skip to content

fix(agent-isolation): give every signing context its own touch watcher - #1301

Merged
potiuk merged 1 commit into
apache:mainfrom
potiuk:fix/gpg-touch-overlay-ownership
Sep 20, 2026
Merged

potiuk merged 1 commit into
apache:mainfrom
potiuk:fix/gpg-touch-overlay-ownership

Conversation

@potiuk

@potiuk potiuk commented Sep 20, 2026

Copy link
Copy Markdown
Member

Summary

  • Two agent sessions signing at once, or a terminal git signing beside one, shared a single watcher pid file, so any of them could kill a watcher it had not started. The symptom is a hardware-key touch that blocks with no window on screen.
  • Two arms that raced both wrote that file, so the loser's watcher became unreachable and ran on with its window up until the ten-minute cap. The symptom is an overlay that will not go away.
  • Every signing context now owns its own watcher and can tear down no other. The window stays shared, leased rather than owned, so one touch still draws exactly one.

Type of change

  • Skill change (.claude/skills/<name>/) — eval fixtures updated below
  • Tool / bridge contract (tools/<system>/*.md)
  • Python package (tools/*/ with pyproject.toml)
  • Groovy reference impl
  • Cross-cutting (RFC, AGENTS.md, sandbox, privacy-LLM)
  • Documentation (docs/, README.md, CONTRIBUTING.md)
  • Project template (projects/_template/)
  • CI / dev loop (prek, workflows, validators)
  • Other: tools/agent-isolation/ shell substrate and its spec

What changed

A signing context is an agent session or a wrapped git. Each now registers under owners/, keyed by the harness session id that both hooks carry in their payload or by the wrapper's own pid, and records two pids: the owner, whose death means the context is gone, and the watcher, which is the only process that context may kill. The wrapper no longer reuses a watcher somebody else started, which is what made a terminal signature's window depend on an unrelated session's disarm timing.

The window is the one thing that must stay single, so it is leased by atomic directory create, the one primitive both macOS and Linux have without flock(1). A lease left behind by a watcher that died is reclaimed rather than locking the window out for good. Dismissal became shared for the same reason: dismissing once should not be undone by another watcher a fifth of a second later.

Stuck windows get a cure rather than a shorter wait. Each arm sweeps registrations whose owner process is gone and kills the watchers behind them, so a session that crashed without disarming costs nothing instead of a window that sits there until MAX_WAIT. Hook-armed watchers also exit on their own if the harness process dies.

Test plan

  • prek run passes on every changed file, including the whole-workspace pytest, ruff, mypy and lychee hooks
  • For Python packages touched: uv run pytest passes in tools/agent-isolation
  • For Groovy bridges touched: command-line invocation tested end-to-end
  • For skill changes: eval suite passes for the affected skill
  • For skill behaviour changes: a new or updated eval fixture is included in this PR
  • Other: seven new tests, each confirmed failing against the old script before the fix was written

The new tests are the concurrency the single pid file could not survive: two sessions get independent watchers; one session's disarm leaves another's watcher alone; re-arming the same session reuses its watcher; a dead owner's watcher is swept; only one of two racing watchers may hold the window lease; a lease is reclaimed from a dead holder; and the wrapper registers itself while leaving other owners untouched.

test_wrap_leaves_a_watcher_somebody_else_armed_alone is retired. It asserted the piggybacking that was itself the defect, and test_wrap_registers_itself_and_leaves_other_owners_alone covers the concern behind it properly.

RFC-AI-0004 compliance

  • HITL — any new mutation is gated on explicit user confirmation
  • Sandbox — no new host access; the change is confined to the runtime directory the overlay already used
  • Vendor neutrality — placeholders used in all skill / tool prose
  • Conversational + correctable — agentic-override path documented if behaviour is adopter-tunable
  • Write-access discipline — no autonomous outbound messages; drafts only, sent on confirmation
  • Privacy LLM — private content does not reach a non-approved LLM; redactor invoked where needed

Linked issues

None — reported from use.

Notes for reviewers

The behaviour this replaces was deliberate, not an oversight: one watcher covering whatever was in flight, with a test asserting the wrapper left it alone. That design is exactly what cannot survive concurrent owners, so the intent and the test both had to move. Worth a look at whether you agree with the trade.

Two places described the old behaviour and are updated in the same commit: the agent-isolation spec and the one-signature-one-window paragraph in the secure-agent-setup guide.

Worth knowing separately: the installed copy that actually runs in a session is usually a symlink into the operator's own dotfiles, and mine had already drifted from the repository before this change. Landing this does not update it.

Generative AI disclosure

Written with Claude Code (Opus 5) under human direction. The race was diagnosed from the script, the tests were written first and confirmed failing against the old behaviour, and the author reviewed the change before it landed.

🤖 Generated with Claude Code

Two agent sessions signing at once, or a terminal git signing beside
one, shared a single watcher pid file. Any of them could kill a watcher
it had not started, which left a touch blocking with no window, and two
arms that raced overwrote the only record of one, which left a window
nothing could close until the ten-minute cap.

Each signing context now owns its watcher, registered under owners/ and
keyed by the harness session id its hooks carry or by the wrapper's own
pid, and can tear down no other. A context whose owner process is gone
is swept by the next arm rather than waiting out the cap. The window
stays shared, leased by atomic directory create so one touch still
draws exactly one, with the lease reclaimed from a holder that died.

Generated-by: Claude Opus 5
@potiuk potiuk added the family:tools tools/* label Sep 20, 2026
@potiuk
potiuk merged commit 1001459 into apache:main Sep 20, 2026
9 checks passed
@potiuk potiuk added the substrate:sandbox Tool substrate: agent isolation, egress control, settings audit label Sep 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

family:tools tools/* substrate:sandbox Tool substrate: agent isolation, egress control, settings audit

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant