Personal Telegram developer console for GitHub

docs: update safe actions spec for durable replay guard

davoodmehraban89 committed Oct 3, 2026 at 07:23 UTC 53a766ac9a2fab49a2bde29d0c5ae9b586f4c555
1 file changed +32 -20
docs/superpowers/specs/2026-10-03-safe-github-ops-design.md
+32 -20
@@ -5,10 +5,10 @@ Turn the production-accepted read-only plugin foundation into a safe write-capab
5
6 ## Scope
7 This phase delivers two tightly coupled capabilities:
8 -1. A reusable Telegram approval flow for `WRITE` and `DESTRUCTIVE` plugin actions.
8 +1. A reusable Telegram approval flow for `WRITE` and `DESTRUCTIVE` plugin actions with durable one-time consumption.
9 2. GitHub Advanced operations for workflow visibility/control and repository operational views.
10
11 -Out of scope for this phase: AI model execution, paid browser automation, Supabase, Cloudflare rollback, Mini App UI, and any new paid resource. Those remain later phases.
11 +Out of scope for this phase: AI model execution, browser automation, Supabase, Cloudflare rollback and Mini App UI. A Cloudflare Durable Object namespace with SQLite storage is in scope because it is required for cross-isolate approval replay protection.
12
13 ## Success criteria
14 - `READ` actions continue to execute immediately for the authorized owner.
@@ -16,16 +16,17 @@ Out of scope for this phase: AI model execution, paid browser automation, Supaba
16 - Approval tokens are single-use, owner-bound, action-bound, short-lived, and tamper-evident.
17 - Approval UI exposes explicit Confirm and Cancel choices.
18 - Replayed, expired, malformed, wrong-owner, or mismatched approvals fail closed and do not execute provider code.
19 +- One-time consumption remains enforced across Worker isolates through a Durable Object replay guard.
20 - GitHub workflow actions can list runs, inspect jobs/steps, re-run failed jobs, and cancel an in-progress workflow when the configured GitHub token has sufficient scope.
21 - Missing GitHub permissions produce an explicit operational error; they are not reported as success.
22 - Every attempted and completed action emits redacted audit events.
23 - Existing repository/file navigation remains unchanged.
23 -- All existing tests stay green, new tests cover approval and GitHub operator behavior, CI passes, production deploy succeeds, and live Telegram READ smoke remains healthy.
24 +- All existing tests stay green, new tests cover approval, durable replay and GitHub operator behavior, CI passes, production deploy succeeds, and live Telegram READ smoke remains healthy.
25
26 ## Approval architecture
27
27 -### ApprovalStore
28 -Use an in-memory request-scoped approval registry only for encoding/decoding signed approval payloads; persistence is not required because the approval state itself is carried in a signed callback token.
28 +### Signed approval token
29 +Approval state needed for verification is carried in a signed callback token; no server-side session is required to reconstruct the requested action.
30
31 The token payload contains:
32 - `v`: schema version `1`
@@ -38,17 +39,26 @@ The token payload contains:
39 - `expiresAt`
40 - `nonce`
41
41 -The token is authenticated with HMAC-SHA-256 using `TELEGRAM_WEBHOOK_SECRET` as the signing secret. The raw secret is never logged or returned.
42 +The token is authenticated with HMAC-SHA-256 using `APPROVAL_SIGNING_SECRET` when configured, otherwise `TELEGRAM_WEBHOOK_SECRET` as the fail-closed fallback signing secret. Raw secrets are never logged or returned.
43
43 -Telegram callback data has a strict size budget, so approval tokens must not embed verbose objects. GitHub operations use compact numeric/string identifiers (repository ID, workflow run ID, job ID) and the token encoder rejects oversized payloads instead of truncating security-relevant data.
44 +Telegram callback data has a strict size budget, so approval tokens must not embed verbose objects. GitHub operations use compact numeric identifiers (repository ID and workflow run ID) and the token encoder rejects oversized payloads instead of truncating security-relevant data.
45
46 ### ApprovalService
47 `ApprovalService.issue()` creates a signed token. `ApprovalService.verify()` validates signature, schema, owner, expiry, risk, and expected action before returning the decoded payload.
48
48 -A verified token does not by itself execute an action. The router receives an explicit `approved: true` context only after verification. The action policy then allows the matching `WRITE`/`DESTRUCTIVE` action.
49 +A verified token does not by itself execute an action. `ApprovalService.consume()` must first persist one-time consumption through the replay store. Only then does the router receive explicit `approved: true` context. The action policy then allows the matching `WRITE`/`DESTRUCTIVE` action.
50
50 -### One-time semantics
51 -Telegram duplicate callbacks are possible. A process-local nonce cache prevents duplicate execution within one Worker isolate. Provider operations chosen for this phase are also idempotent or safe to retry at the API level: re-running failed jobs may create a new attempt only once per accepted callback in the active isolate; cancel on an already completed run is surfaced as a provider error. No destructive repository mutation is introduced in this phase.
51 +### Durable replay protection
52 +`DurableApprovalReplayStore` maps the `(ownerId, nonce)` pair to a Cloudflare Durable Object identity. `ApprovalReplayGuard` performs an atomic check-and-write in Durable Object storage and schedules cleanup at token expiry.
53 +
54 +Security behavior:
55 +- first valid consume before expiry: accepted and persisted;
56 +- repeated consume for the same `(ownerId, nonce)`: rejected;
57 +- expired consume: rejected;
58 +- missing `APPROVAL_REPLAY_GUARD` binding: consume fails closed;
59 +- cleanup occurs after expiry via the Durable Object alarm.
60 +
61 +`wrangler.jsonc` declares `APPROVAL_REPLAY_GUARD` bound to exported class `ApprovalReplayGuard` with SQLite storage.
62
63 ## Policy changes
64 `ActionPolicy.evaluate()` accepts `approved` in addition to `action` and `isOwner`.
@@ -56,9 +66,9 @@ Telegram duplicate callbacks are possible. A process-local nonce cache prevents
66 - unknown action/risk: denied
67 - READ: allowed
68 - WRITE/DESTRUCTIVE without approval: `requiresApproval`
59 -- WRITE/DESTRUCTIVE with verified approval: allowed with distinct audit reason
69 +- WRITE/DESTRUCTIVE with verified and consumed approval: allowed with distinct audit reason
70
61 -The router remains `resolve -> policy -> execute`; approval verification occurs before the second dispatch that carries `approved: true`.
71 +The router remains `resolve -> policy -> execute`; approval verification and durable consume occur before the second dispatch that carries `approved: true`.
72
73 ## Telegram UX
74 When a plugin route returns `requiresApproval`, the bot edits the same message to a confirmation view:
@@ -75,7 +85,7 @@ Confirmation callbacks use reserved prefixes:
85 - `approve:<token>`
86 - `cancel:<token>`
87
78 -Malformed/expired callbacks return a concise Persian error and a Back button.
88 +Malformed/expired/replayed callbacks return a concise Persian error and never reach provider mutation.
89
90 ## GitHub Advanced plugin
91 The existing GitHub plugin is extended instead of creating a second overlapping GitHub plugin.
@@ -84,7 +94,6 @@ The existing GitHub plugin is extended instead of creating a second overlapping
94 - `github.workflow.runs.list`
95 - `github.workflow.run.detail`
96 - `github.workflow.jobs.list`
87 -- `github.workflow.job.detail`
97
98 ### New WRITE actions
99 - `github.workflow.run.rerun_failed`
@@ -104,7 +113,7 @@ All methods resolve numeric repository IDs through the existing trusted reposito
113
114 ## Menu changes
115 Repository detail adds an `🧪 CI / Actions` entry. Workflow views remain bounded for Telegram:
107 -- maximum 10 runs per page in v1
116 +- maximum 10 runs in the current view
117 - concise status/conclusion/branch/SHA summary
118 - job details show step status/conclusion without full raw logs
119
@@ -122,7 +131,8 @@ Audit payloads may include IDs and status but never secrets or signed approval t
131
132 ## Error handling
133 - Missing signing secret: fail closed for write approval; READ remains available.
125 -- Signature mismatch/expiry/owner mismatch/action mismatch: reject before provider call.
134 +- Missing Durable Object replay binding: approval consume fails closed before provider call.
135 +- Signature mismatch/expiry/owner mismatch/action mismatch/replay: reject before provider call.
136 - GitHub 401/403: explicit permission/authentication error.
137 - GitHub 404: explicit not-found error.
138 - GitHub 409/422: explicit current-state conflict; do not fabricate success.
@@ -131,7 +141,8 @@ Audit payloads may include IDs and status but never secrets or signed approval t
141 ## Testing
142 Add unit coverage for:
143 - policy approved/unapproved semantics
134 -- approval issue/verify/tamper/expiry/owner mismatch/oversize/replay behavior
144 +- approval issue/verify/tamper/expiry/owner mismatch/oversize behavior
145 +- durable replay consume, expiry, missing binding and Wrangler export/binding contract
146 - router execute gating with approved context
147 - GitHub REST method/path/body behavior and non-2xx failures
148 - plugin route ownership and risk mapping
@@ -144,6 +155,7 @@ Regression suite must retain all existing Foundation tests.
155 1. PR CI green with non-zero test discovery.
156 2. Merge to `main` and post-merge CI green.
157 3. Cloudflare deployment succeeds for exact verified commit.
147 -4. Owner-device smoke: `/start -> Repositories -> project -> CI / Actions`.
148 -5. Live write-action smoke is only attempted if GitHub token permissions already support it; otherwise the capability is marked implemented but provider-permission smoke is `NOT VERIFIED` and no secret/token rotation is performed automatically.
149 -6. Cloudflare telemetry shows current-version webhook HTTP 200 and redacted audit events with no new webhook error.
158 +4. Active deployment exposes `APPROVAL_REPLAY_GUARD` and exported SQLite `ApprovalReplayGuard`.
159 +5. Owner-device smoke: `/start -> Repositories -> project -> CI / Actions`.
160 +6. Live write-action smoke is only attempted after the owner confirms the action in Telegram; if the configured GitHub token lacks Actions write permission, provider-permission smoke is recorded as `NOT VERIFIED` and no secret/token rotation is performed automatically.
161 +7. Cloudflare telemetry shows current-version webhook HTTP 200 and redacted audit events with no new webhook error.