Skip to content

Connect approved agent apps when the Agent tab is open (#31) - #34

Merged
lseongjoo merged 22 commits into
integration/issue-31from
claude/project-thread-snd6be
Nov 28, 2026
Merged

lseongjoo merged 22 commits into
integration/issue-31from
claude/project-thread-snd6be

Conversation

@lseongjoo

@lseongjoo lseongjoo commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Requested by 이성주 · project thread

Closes the implementation part of #31. Base integration/issue-31 = 0d961e0 (integration/issue-13). 최종 HEAD 9b0703c.

바뀐 동작

  • 에이전트 탭이 선택되고 관리 창이 화면에 보이면 "탭 열림"입니다. 탭이 열리면 사용자가 끄지 않은 한 전체 받기를 켜고, 내용 없는 준비 신호(Darwin <앱 ID>.agent.ready.<uid>)를 보냅니다.
  • 도우미는 첫 페어링 전에 신호를 구독하고, 신호가 오면 status → hello → prove를 다시 수행합니다. 승인한 앱은 클릭·도구 호출 없이 연결되고, 새 앱은 여전히 승인이 한 번 필요합니다(에이전트 앱별 독립 연결과 승인 관리 #13 규칙 그대로).
  • 앱에 닿지 못하면 2초부터 최대 5분까지 백오프합니다(±20%). 신호 기반 시도는 이전 시도가 끝난 뒤 최소 1초 + 0~250ms 지터 간격을 둡니다.
  • 신호는 앱 시작, 잠금 해제, 받기 켜기, 앱별 받기 켜기, 도우미 종료, 승인 파일 복구 때도 나갑니다. 탭을 닫아도 연결은 유지합니다(사용자 결정).
  • receiptChoice: auto|off: 사용자가 끈 받기는 탭을 열어도 켜지지 않습니다.
  • 승인 파일은 agent-approvals.json이고, 페어링 소켓을 가진 인스턴스만 씁니다. 에이전트 앱별 독립 연결과 승인 관리 #13 빌드의 agent-clients.json은 배포된 적이 없어 가져오지 않습니다(그 빌드에서 승인한 앱은 한 번 다시 승인).
  • 파일 변경은 소켓 인수, 탭 열기, 상태 확인·증명, 설정 변경 때 감지합니다. 이미 연결된 도우미에도 철회·끄기가 바로 적용됩니다.
  • 저장하지 못한 사용자 거부(전체 끄기, 앱별 끄기, 철회, 키 교체로 밀려난 키)는 바로 적용됩니다. 다시 읽은 파일이 그 거부를 담을 때까지 대기로 남고, 파일을 다시 읽을 때 재적용·저장합니다.
  • 허용(받기 켜기, 재개, 승인)은 다시 읽은 파일에서 확인될 때만 적용합니다.
  • 파일이 사라지면 그 자리에 쓰지 않습니다. 읽을 수 없는 파일은 덮어쓰지 않고 탭에 안내하며, 사용자가 받기를 켤 때만 빈 목록으로 바꿉니다.
  • 화면 잠금과 콘솔 비활성은 따로 추적하고, 시작 시 콘솔 비활성도 확인합니다.
  • 로그: presence, receipt, ready post, policy adopt|change refused, helper attempt|retry|wait. 수집법은 docs/mcp-explanation-drafts.md에 있습니다.

참여 에이전트

  • 구현: Claude Code(클라우드 세션 + 사용자 Mac의 Remote Control 세션).
  • 독립 검토: Codex(codex-cli 0.169.1, CLI 표시 모델 gpt-6.2-astra, read-only), Antigravity "재민"(agy 1.5.19, 모델 미확인).

운영 로그 (요약)

환경: macOS 27.2.1, Swift 6.4.2, SDK MacOSX26.5, 애드혹 서명. fixture는 rcodesign과 일회용 인증서로 실행했습니다.

  • 1~4차: 이 PR의 이전 본문과 댓글에 있습니다.
  • 517차: 매 HEAD에서 build exit 0, test exit 0(5차 컴파일 수정 1회, 9차 이 브랜치와 무관한 불안정 1회), fixture 20/20입니다. 위조 신호 구간의 도우미별 trigger=ready 최소 간격은 1.061.15초였습니다. 전체 표는 에이전트 탭이 열려 있으면 별도 조작 없이 연결 #31 댓글에 있습니다.

검토 결과

  • 1~16차: 지적을 반영했습니다. Antigravity는 8차부터 동의, Codex는 16차까지 반대(파일 소실·복원 경계 사례)였습니다.
  • 17차(9b0703c): Codex 동의, Antigravity 동의. 남은 [차단]은 없습니다.

알려진 한계·후속

미검증

  • 실제 에이전트 앱(Claude Code 등)에서 탭 열기만으로 연결되는지는 사용자 클릭이 필요해 별도로 진행합니다.
  • 앱 UI(탭·창 가시성 감지)는 fixture 범위 밖입니다.

되돌리기

이 PR의 병합 커밋을 revert합니다. 새 파일 agent-approvals.json은 지워도 됩니다(승인 없음으로 시작).

🤖 Generated with Claude Code

https://claude.ai/code/session_015LJG7KnMPqFcfTZ8A1C2qh

claude and others added 7 commits November 28, 2026 11:59
Opening the Agent tab turns draft receipt on unless the user turned it off,
and posts a content-free ready signal. Live helpers listen for it and run the
normal status/hello/prove exchange again, so approved apps connect without a
click or tool call; unreachable apps are retried with backoff. Closing the tab
keeps connections. New apps still need one approval.

Receipt saved off by an older version stays off with a one-time notice.

Agent: Claude Code

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015LJG7KnMPqFcfTZ8A1C2qh
Darwin does not re-export the notify module with the macOS 26.5 SDK, so
the app and helper failed to compile. Mechanical fix; no behavior change.

Agent: Claude Code

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
10 * (0.8 + 0.4) is 12.000000000000002 in IEEE doubles, so the exact
equality precondition trapped. Test-only change.

Agent: Claude Code

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Reload the trust file before every change and when taking the pairing
  socket, opening the tab, proving or approving, so a revocation or receipt-off
  saved by another app instance is adopted and never written back over.
- Helper listens for the ready signal before its first pairing; signal-driven
  attempts are limited to one per second with up to 250 ms jitter, and it stops
  listening after a terminal status.
- Post the ready signal also when a vanished helper is found before its exit
  watcher fires; opening the tab posts it once.
- The tab's retry button reconnects as opening the tab does; the Preview
  window counts as the Agent tab.
- Fixture: check that a helper's own timed retry reaches the app.

Agent: Claude Code

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015LJG7KnMPqFcfTZ8A1C2qh
Second review found that re-reading the trust file before each change still
let two instances overwrite each other. Instead:

- Only the instance that holds the pairing socket changes approvals or receipt;
  a second instance refuses with a message and a policy log line.
- A standby that takes the socket over adopts the saved file once
  (unreadable file: no trust, receipt off) and drops leases of revoked apps.
- The tab can never turn on receipt the user turned off, also in the store.
- A tab left open while locked connects again on unlock.
- Helper: the first pairing result is not scheduled after a newer signal
  attempt, signal attempts start at least 1 s apart measured after the
  previous one, a signal during an attempt gets one more attempt, a failed
  registration is not marked listening, and the signal name includes the uid.
- Fixture: tab open, unlock, restart and receipt-on reconnect within 2 s.

Agent: Claude Code

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015LJG7KnMPqFcfTZ8A1C2qh
Agent: Claude Code

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015LJG7KnMPqFcfTZ8A1C2qh
…rs (#31)

Third review (Codex objected, Antigravity agreed):

- The socket holder notices when the approvals file changed since its own last
  read or write (for example an older app version running beside it) and adopts
  it before proving, approving or any change. A missing or unreadable file after
  approvals were known means no trust and receipt off; revocations are kept, and
  an unsaved denial is merged on top of what is on disk.
- A change attempted without the socket first tries to take it over, so a window
  left after the previous holder quit works; the refusal message clears once it
  holds the socket.
- Screen lock and an inactive console session are tracked separately; receipt
  resumes only when neither holds.
- Retry restarts the "no session" check. Docs and comments say the old-version
  notice stays until the user turns receipt on or off.
- Fixture reconnect waits: 3 s (one signal interval plus jitter and margin).

Agent: Claude Code

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015LJG7KnMPqFcfTZ8A1C2qh
@lseongjoo lseongjoo self-assigned this Nov 28, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 28, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-28T12:46:18.110301Z f3ddb9a PR opened
🔒 Security Review ✅ Completed 2026-11-28T12:47:49.670747Z f3ddb9a PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f3ddb9abe2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread Sources/Core/AgentTrustStore.swift Outdated
Comment on lines +105 to +108
if let loaded = Self.read(url) {
guard hasUnsavedDenial else { file = loaded; return }
var merged = loaded
merged.revoked = loaded.revoked + file.revoked.filter { !loaded.revoked.contains($0) }

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Preserve saved revocations when adopting external policy

When an older app instance overwrites the trust file using its stale client list, this branch discards even revocations successfully saved by the current instance: hasUnsavedDenial is false after a successful forget. For example, forget an approved app in the socket-owning instance, then toggle receipt in an already-running older instance and enable receipt in the owner. adoptIfChanged() reloads the stale approval and removes its tombstone, allowing a fresh helper process holding the forgotten key to reconnect without approval. Preserve locally known revoked keys and exclude their clients during every adoption, not only after failed denial writes.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed and fixed in a7aeb83. Whenever this instance adopts the file, it now merges in its own revoked keys, drops their clients, and writes the tombstones back to disk. This happens on every adoption, not only after a denial that failed to save. I added a unit test for this case to AgentTrustStoreTests: forget the client, write back the stale pre-revocation file, then adopt. After that the key stays revoked, both in memory and on disk. The build and test runs on the Mac are next.


Generated by Claude Code

claude and others added 15 commits November 28, 2026 12:46
…#31)

Codex bot P1 on #34: a stale file written by an older app instance could
remove a tombstone this instance had saved, letting the forgotten key reconnect.
Adoption now always unions the local revoked keys, drops their clients and
writes the tombstones back.

Agent: Claude Code

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015LJG7KnMPqFcfTZ8A1C2qh
…t overwriting (#31)

- connectionStatus adopts a changed trust file, so a bound helper sees an
  external revoke or receipt-off before each receive or share.
- Trust file stamp comes from the fd that was read and includes ctime and mode.
- An unreadable file is adopted as no trust but never written over; it is
  adopted again once readable. A read failure no longer marks a denial.
- A failed write-back of tombstones or denials keeps them pending.
- When the revoked list is full, the disk's newer entries are kept.
- Launch while another user has the console counts as session-locked.
- Docs: old-version concurrent writer race (no file lock) as a known limit.

Agent: Claude Code
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015LJG7KnMPqFcfTZ8A1C2qh
`try` inside precondition's autoclosure does not compile; read the file
into a local first. Test-only change.

Agent: Claude Code

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…unreadable trust files (#31)

- Read the console flag under its real key string (kCGSSessionOnConsoleKey).
- At the 64-entry revoked cap the disk's oldest entries make room; this
  instance's revocations are all kept.
- After a write, remember the file only if a re-read shows what was written;
  otherwise the next check adopts the other writer's version.
- A failed write-back clears the stamp so the next check retries it.
- An unreadable file records the stamp of the file that failed (or none when
  it cannot be opened), so recovery is noticed. Only a user's change replaces
  it; automatic writes still never do. Launch on an unreadable file is the
  same state, and the Agent tab explains it.
- An unsaved denial that meets an unreadable file is applied against what was
  held before, not against the empty closed state.
- An older version's "on" (no receipt choice in its file) does not undo the
  user's off here.
- Bound helpers dropped by an unreadable file are not blocked; they get a
  ready signal when the file is readable again.
- prove() adopts external changes before returning an existing binding.

Agent: Claude Code
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015LJG7KnMPqFcfTZ8A1C2qh
…r own file (#31)

The adoption merge (tombstone union, intersection with an unsaved denial,
old-writer receipt guard) kept producing edge cases. It is replaced by two
simpler rules:

- Approvals live in agent-approvals.json. The #13 builds' agent-clients.json
  is imported once when the new file does not exist and renamed to
  .migrated. No released version ever wrote either file, so earlier builds
  running beside this one no longer share a file with it.
- A user's denial (receipt off, one app's receipt off, revoke) that cannot be
  saved is kept as a pending operation and replayed on top of whatever the
  file holds when it is next read, then written. Only the user's own actions
  are replayed, so revocations at the 64 cap and apps approved elsewhere are
  kept.

Also:
- needsAdopt flag instead of a nil stamp, so a pending write-back still
  notices the file vanishing; a read error after open keeps no stamp.
- Over an unreadable file only the user turning receipt on writes (a new,
  empty list); denials there stay pending. The tab notice says so.
- disconnect/forget capture what was clicked before re-reading the file and
  record the denial even if the row is not loaded right now.
- Opening the tab checks the file again.

Agent: Claude Code
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015LJG7KnMPqFcfTZ8A1C2qh
… file shows them (#31)

- No import of the #13 builds' agent-clients.json (never released): nothing
  writes the approvals file outside socket ownership, and those builds never
  share a file with this one. Apps approved there are approved again once.
- A denial that fails to save sets needsAdopt, so the next check replays and
  writes it even if nothing else changed the file.
- Pending denials are cleared only when a re-read shows the written file; on
  a mismatch they stay and are applied to whatever is read next.
- Replay that changes nothing does not write.
- A user's "turn receipt on" that is the first to find the file unreadable
  does not overwrite it; the next click does, after the notice.
- Docs: policy_readable and policy_unreadable log values.

Agent: Claude Code
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015LJG7KnMPqFcfTZ8A1C2qh
…l gaps (#31)

- turnOnReceive reads readFailed before startPairing, whose takeover re-reads
  the file, so the first click that finds it unreadable never overwrites it.
- Unsaved denials while the file is missing are written to a new file, or
  retried at the next check.
- A user's later on removes an unsaved receipt-off (or that app's off) from
  the pending list, so it cannot be replayed over the on.
- A denial whose re-read does not show it is reported as unsaved.
- The unreadable notice clears once receipt is turned on.

Agent: Claude Code
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015LJG7KnMPqFcfTZ8A1C2qh
…only after a save (#31)

- Adopting the file clears a remembered instruction choice whose app record
  was removed or now holds a different key, even with no live binding, so a
  rotated key never inherits an earlier instruction share.
- A pending receipt-off (or one app's off) is removed only after the user's
  on is saved; a failed on leaves the off in effect.
- Nothing is written in place of a missing file; unsaved denials stay and
  apply to the file if it is restored.
- A denial counts as saved when the re-read file holds it, even if unrelated
  rows differ.
- The unreadable notice is kept while other denials are still unsaved.

Agent: Claude Code
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015LJG7KnMPqFcfTZ8A1C2qh
Agent: Claude Code
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015LJG7KnMPqFcfTZ8A1C2qh
#31)

Pending denials are removed only when the file holds them (receipt off,
the app's row present and off, the key revoked and absent). An app's off for
a row the file lacks stays pending and applies when the row comes back.

Agent: Claude Code
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015LJG7KnMPqFcfTZ8A1C2qh
…ng (#31)

- setReceiptEnabled(false) for a row that is not loaded (file vanished or
  unreadable) records the off as pending and writes nothing.
- A matching commit reports a denial as saved only if the written file
  holds it.

Agent: Claude Code
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015LJG7KnMPqFcfTZ8A1C2qh
Closes the class "denial reported saved but held by neither the file nor
the pending list" instead of single instances:

- Every denial (receipt off, one app's off, revoke, and the key replaced by a
  rotation approval) is added to the pending list first and removed only when
  a write is read back unchanged and holds it.
- Nothing is written in place of a file that vanished or cannot be read;
  denials made then apply when it is back.
- An off for a row missing from a readable file stays pending as well.
- The "nothing changed" shortcut applies only when memory reflects a file
  this instance read or wrote and nothing is pending.
- A user's on removes a pending off only if the write was read back.
- A failed rotation approval still revokes the replaced key in memory.

Agent: Claude Code
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015LJG7KnMPqFcfTZ8A1C2qh
…, end a replaced key's lease on failure (#31)

- Turning receipt on, resuming an app, and approving a key count only when
  the written file is read back unchanged; otherwise the file is read again
  with pending denials applied and the grant is refused.
- A file written where the previous one vanished does not settle pending
  denials, since the original may be restored over it.
- A rotation approval that fails to save re-adopts at once, so the replaced
  key's live lease and share end.

Agent: Claude Code
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015LJG7KnMPqFcfTZ8A1C2qh
… denials across later writes to a re-created file (#31)

- resume, approve (existing key) and turning receipt on run the controller's
  adoption when the store refuses a grant, so leases revoked by the file it
  read end at once.
- A refused grant leaves nothing granted in memory, even if the file vanished.
- Writes to a file this run created where the previous one vanished never
  settle pending denials until another file appears there.

Agent: Claude Code
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015LJG7KnMPqFcfTZ8A1C2qh
…ated (#31)

Agent: Claude Code
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015LJG7KnMPqFcfTZ8A1C2qh
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.

2 participants