Personal Telegram developer console for GitHub
docs: harden workspace editor design for idempotency
davoodmehraban89 committed
Oct 3, 2026 at 11:47 UTC
06d53d36cc9358c41a057d7ac9cf9512472e0747
2 files changed
+68
-27
PROJECT_MEMORY.md
+3
-2
@@ -129,9 +129,10 @@ Conclusion:
129
- Phase 1: durable owner-scoped single-file text workspace, exact diff, conflict/staleness checks, branch-first GitHub commit, Safe Approval, commit SHA + CI handoff.
130
- Commit engine is based on Git Data blobs/trees/commits/refs so Phase 2 can atomically commit multiple files without redesign.
131
- Draft content is stored outside Telegram callback data/process memory, preferably in a dedicated `WORKSPACE_STORE` Durable Object; existing `APPROVAL_REPLAY_GUARD` remains dedicated to approval replay protection.
132
+- Commit intent is idempotent: committed result metadata/SHA is persisted so Telegram/network retries or a fresh approval cannot create a duplicate commit for the same unchanged workspace intent; ambiguous provider outcomes require ref reconciliation before retry.
133
- Direct writes to `main` are out of scope for Phase 1 and may be added later only as an explicitly enabled high-risk path that respects GitHub protection rules.
134
- Binary/LFS, automatic conflict resolution, secret/private-key-like files and arbitrary shell execution are out of scope for Phase 1.
134
-- Production acceptance requires owner-device evidence proving draft-only behavior before approval, exact diff, one approved commit, replay rejection, and GitHub/Cloudflare evidence agreement.
135
+- Production acceptance requires owner-device evidence proving draft-only behavior before approval, exact diff, one approved commit, replay rejection, idempotent retry, and GitHub/Cloudflare evidence agreement.
136
137
### Not yet implementation-complete
138
- Written spec requires owner review/approval before implementation planning.
@@ -143,7 +144,7 @@ Conclusion:
144
## Next Executable Actions
145
1. Owner reviews `docs/superpowers/specs/2026-10-03-repository-workspace-editor-design.md` and approves or requests changes.
146
2. After written-spec approval, create the implementation plan via the required planning workflow.
146
-3. Implement with TDD in vertical slices: workspace storage -> edit/diff UX -> Git Data commit engine -> Safe Approval integration -> CI handoff -> production smoke.
147
+3. Implement with TDD in vertical slices: workspace storage -> edit/diff UX -> Git Data commit engine -> Safe Approval + idempotency integration -> CI handoff -> production smoke.
148
4. Only after Repository Workspace Phase 1 production acceptance, continue remaining useful GitHub Advanced WRITE operations and then Cloudflare Ops.
149
150
## Remaining Roadmap
docs/superpowers/specs/2026-10-03-repository-workspace-editor-design.md
+65
-25
@@ -33,6 +33,7 @@ Phase 1 supports:
33
- exact diff before approval;
34
- conflict detection against the original base HEAD;
35
- Safe Approval before the GitHub mutation;
36
+- idempotent commit intent tracking;
37
- commit SHA feedback and CI handoff.
38
39
Phase 1 does not support:
@@ -79,11 +80,13 @@ The workspace records:
80
- source blob SHA;
81
- original content digest;
82
- draft content/digest;
83
+- commit message/digest when supplied;
84
+- target branch when supplied/generated;
85
- created/updated timestamps;
86
- expiration time;
87
- workspace state.
88
86
-The owner submits replacement text or a bounded line-range edit. Nexa validates size, encoding, path and workspace ownership before accepting it.
89
+The owner submits replacement text or a bounded line-range edit. Nexa validates size, UTF-8 encoding, source path, workspace ownership and configured input bounds before accepting it. Commit messages and branch names are normalized and bounded; branch names must satisfy Git ref safety rules.
90
91
### Review
92
@@ -103,10 +106,11 @@ No provider mutation happens during preview.
106
107
The default path is:
108
106
-`draft -> review diff -> Safe Approval -> create/update feature branch -> create commit -> return SHA -> monitor CI`
109
+`draft -> review diff -> Safe Approval -> Git Data commit flow -> target branch ref -> return SHA -> monitor CI`
110
111
The approval target binds at least:
112
- repository;
113
+- workspace id / commit-intent id;
114
- base HEAD SHA;
115
- target branch;
116
- changed path(s);
@@ -128,7 +132,7 @@ Nexa generates or accepts a safe branch name such as:
132
133
`nexa/edit-<short-workspace-id>`
134
131
-The final mutation may create the branch and commit as one approved composite action. This keeps drafts local while avoiding an unnecessary provider write before final confirmation.
135
+The final approved composite action creates Git objects and then the target branch ref. This keeps drafts local and avoids a visible provider branch write before final confirmation.
136
137
### Direct-main future mode
138
@@ -139,12 +143,16 @@ Direct commits to the default branch are deferred. If added later they must be e
143
The implementation should use GitHub Git Data primitives rather than designing around one-file Contents API behavior:
144
145
1. Read and pin the base HEAD commit/tree.
142
-2. Create blob(s) for staged content.
143
-3. Create a new tree from the pinned base tree.
144
-4. Create one commit pointing to that tree.
145
-5. Create or fast-forward the approved target branch ref.
146
+2. After approval is consumed, re-check staleness/conflicts.
147
+3. Create blob(s) for staged content.
148
+4. Create a new tree from the pinned base tree.
149
+5. Create one commit pointing to that tree.
150
+6. Create or fast-forward the approved target branch ref.
151
+7. Persist the provider result into the workspace before returning success to Telegram.
152
147
-This is slightly more work for the first single-file version, but it gives the correct atomic foundation for Phase 2 multi-file commits.
153
+All GitHub Git Data writes (blob/tree/commit/ref) occur only after Safe Approval has been successfully consumed. Provider object creation is considered part of the approved composite WRITE even if a later ref update fails.
154
+
155
+This is slightly more work for the first single-file version, but it gives the correct atomic file-set foundation for Phase 2 multi-file commits.
156
157
No branch ref may be moved if the repository state no longer matches the conflict checks described below.
158
@@ -155,13 +163,32 @@ A workspace is optimistic-concurrency controlled.
163
Before final mutation Nexa re-reads the relevant branch state.
164
165
Rules:
158
-- If the base branch HEAD no longer matches the workspace base HEAD, the commit is blocked as stale.
166
+- If the base branch HEAD no longer matches the workspace base HEAD, the commit is blocked as stale before GitHub object creation.
167
- Nexa does not silently rebase, merge or overwrite.
168
- The owner is shown the conflict/staleness reason and can refresh the workspace from the new base.
169
- If a target branch already exists unexpectedly or moved since approval, the action fails closed.
170
- A provider 409/422 or protection error is surfaced to Telegram and audited; success is never fabricated.
171
164
-## 7. Workspace Storage
172
+## 7. Idempotency and Ambiguous Provider Outcomes
173
+
174
+Approval replay protection alone is not enough. A provider call can succeed while the Telegram response fails, and the owner may then try again with a fresh approval.
175
+
176
+Each ready-to-commit workspace therefore gets a stable commit-intent digest derived from repository, base SHA, target branch, path(s), content/tree digest and commit-message digest.
177
+
178
+Workspace state transitions are monotonic, for example:
179
+
180
+`DRAFT -> READY -> COMMITTING -> COMMITTED | FAILED | STALE`
181
+
182
+Rules:
183
+- once `COMMITTED`, the workspace returns the recorded commit SHA and must not create another commit for the same intent;
184
+- the resulting commit SHA/target ref are persisted before Nexa reports success to Telegram;
185
+- if the provider result is ambiguous (timeout/network failure after a possible ref update), Nexa reconciles the target branch/ref against the expected commit intent before permitting a retry;
186
+- a fresh approval cannot bypass an already-committed workspace intent;
187
+- changing draft content, branch or commit message creates a new intent and invalidates any prior pending approval.
188
+
189
+This protects against duplicate commits even when the first successful provider result was not visible to the owner.
190
+
191
+## 8. Workspace Storage
192
193
Draft content must not be stored in Telegram callback data or process memory.
194
@@ -172,13 +199,14 @@ Properties:
199
- every operation checks owner identity;
200
- data is scoped by owner + workspace id;
201
- TTL cleanup removes abandoned drafts;
202
+- committed result metadata is retained long enough to support idempotent retry/reconciliation;
203
- no GitHub token, Telegram token or signing secret is stored in the workspace;
204
- audit logs store metadata/digests, not full sensitive file contents;
205
- draft state is never treated as a provider commit.
206
207
The existing `APPROVAL_REPLAY_GUARD` remains dedicated to one-time approval consumption.
208
181
-## 8. Editable File Policy
209
+## 9. Editable File Policy
210
211
Phase 1 accepts UTF-8 text only.
212
@@ -191,9 +219,9 @@ Reject or disable edit for:
219
220
Reads may remain available where already allowed, but the editor should fail closed for risky write targets.
221
194
-All rendered file content and diff text must be HTML-escaped and bounded for Telegram.
222
+All rendered file content and diff text must be HTML-escaped and bounded for Telegram. Editable input must never be silently truncated.
223
196
-## 9. Telegram UX
224
+## 10. Telegram UX
225
226
New controls should fit naturally into the existing GitHub plugin:
227
@@ -224,9 +252,9 @@ After commit:
252
- `🧪 CI / Actions`;
253
- optional later `Create PR` action, separately approval-gated.
254
227
-For content too large to edit comfortably in chat, Phase 1 should explain the limit rather than truncate editable input silently. The richer Mini App editor is the planned expansion path.
255
+For content too large to edit comfortably in chat, Phase 1 explains the limit rather than truncating editable input silently. The richer Mini App editor is the planned expansion path.
256
229
-## 10. Action Model and Risk
257
+## 11. Action Model and Risk
258
259
New actions should be explicit in the GitHub plugin manifest.
260
@@ -242,14 +270,15 @@ Provider WRITE examples:
270
271
Every provider WRITE must pass through the existing Action Policy, HMAC approval, durable replay guard and audit lifecycle.
272
245
-The commit provider call must not occur until approval is successfully consumed.
273
+The GitHub Git Data write sequence must not begin until approval is successfully consumed.
274
247
-## 11. Audit Requirements
275
+## 12. Audit Requirements
276
277
Audit events must let us reconstruct the control-plane decision without leaking source contents.
278
279
Record metadata such as:
280
- workspace id;
281
+- commit-intent digest;
282
- repo id;
283
- base SHA;
284
- target branch;
@@ -259,6 +288,7 @@ Record metadata such as:
288
- proposed tree/content digest;
289
- action/policy/approval outcome;
290
- resulting commit SHA on success;
291
+- reconciliation outcome after ambiguous provider failures;
292
- provider error category on failure.
293
294
Do not log:
@@ -266,7 +296,7 @@ Do not log:
296
- tokens/secrets;
297
- signed approval callback tokens.
298
269
-## 12. Testing Strategy
299
+## 13. Testing Strategy
300
301
Implementation must be TDD and include:
302
@@ -275,23 +305,31 @@ Implementation must be TDD and include:
305
- workspace owner isolation;
306
- TTL/stale workspace behavior;
307
- text/diff bounds and escaping;
308
+- branch/commit-message validation and bounds;
309
- blob/tree/commit/ref request construction;
310
- multi-file-capable tree construction even if UI initially stages one file;
311
- GitHub error propagation.
312
313
### Policy / security
314
- no GitHub WRITE before approval;
284
-- approval target binds repo/base/branch/path/content digest;
315
+- approval target binds repo/workspace/base/branch/path/content digest;
316
- replay rejected;
317
- expired approval rejected;
287
-- stale base HEAD blocks mutation;
318
+- stale base HEAD blocks mutation before object creation;
319
- unexpected target-branch movement blocks mutation;
320
- non-owner cannot read or mutate workspace;
321
- sensitive-file policy fails closed.
322
323
+### Idempotency
324
+- committed workspace returns recorded SHA on retry without another provider write;
325
+- fresh approval cannot duplicate an already-committed intent;
326
+- ambiguous provider timeout reconciles expected target ref before retry;
327
+- content/branch/message change invalidates prior approval and produces a new intent.
328
+
329
### Integration
330
- create draft -> edit -> diff -> approve -> branch commit;
331
- provider failure visibly updates Telegram;
332
+- successful commit persists exact SHA before Telegram success feedback;
333
- successful commit returns exact SHA and CI navigation.
334
335
### Production acceptance
@@ -301,9 +339,10 @@ CI alone is insufficient. Acceptance requires an owner-device smoke on a safe te
339
3. no GitHub write occurs before approval;
340
4. confirmation creates exactly one commit on the intended branch;
341
5. replay does not create a second commit;
304
-6. GitHub and Cloudflare audit/runtime evidence agree on the same operation.
342
+6. re-opening/retrying a committed workspace returns the same SHA without a duplicate commit;
343
+7. GitHub and Cloudflare audit/runtime evidence agree on the same operation.
344
306
-## 13. Acceptance Criteria
345
+## 14. Acceptance Criteria
346
347
Phase 1 is complete only when all are true:
348
@@ -313,6 +352,7 @@ Phase 1 is complete only when all are true:
352
- `main` is not directly mutated;
353
- stale-base conflicts fail closed;
354
- final GitHub mutation is Safe-Approval gated and one-time;
355
+- a committed workspace is idempotent across Telegram/network retries;
356
- resulting commit SHA/branch are shown from provider evidence;
357
- CI handoff is available;
358
- audit does not expose full draft/source contents or secrets;
@@ -320,7 +360,7 @@ Phase 1 is complete only when all are true:
360
- exact production deployment is verified;
361
- owner-device production smoke passes.
362
323
-## 14. Roadmap Placement
363
+## 15. Roadmap Placement
364
365
Updated order:
366
@@ -336,8 +376,8 @@ Updated order:
376
10. Telegram Mini App using the same workspace/control-plane APIs.
377
11. Plugin ecosystem, multi-project control plane and final hardening.
378
339
-## 15. Key Architecture Decision
379
+## 16. Key Architecture Decision
380
381
The editor is not a special bypass around GitHub controls. It is a first-class GitHub WRITE workflow built on the same policy, approval, replay-protection and audit boundary already proven in production.
382
343
-The initial UI is deliberately small, but the underlying workspace + Git Data commit model is designed for later multi-file atomic commits and a richer editor without changing the security contract.
383
+The initial UI is deliberately small, but the underlying durable workspace + idempotent Git Data commit model is designed for later multi-file atomic commits and a richer editor without changing the security contract.