@ckanner/flywheel 0.31.0 → 0.31.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (136) hide show
  1. package/CHANGELOG.md +48 -5
  2. package/CONTRIBUTING.md +19 -0
  3. package/LICENSE +21 -0
  4. package/README.en.md +4 -171
  5. package/README.md +152 -269
  6. package/README.zh-CN.md +116 -0
  7. package/bin/flywheel-claude-code-pro-worker.js +1 -1
  8. package/bin/flywheel-codex-pro-worker.js +1 -1
  9. package/bin/flywheel-dsh-worker.js +1 -1
  10. package/bin/flywheel.js +1 -1
  11. package/bin/runtime.js +1 -1
  12. package/docs/README.md +84 -0
  13. package/docs/README.zh-CN.md +64 -0
  14. package/docs/archive/README.md +13 -0
  15. package/docs/archive/codex-pro-adapter-handoff.md +197 -0
  16. package/docs/archive/design-v0.24.md +540 -0
  17. package/docs/design.md +681 -0
  18. package/docs/en/claude-code-pro.md +25 -16
  19. package/docs/en/configuration.md +306 -141
  20. package/docs/en/contributing.md +303 -0
  21. package/docs/en/flow-console.md +67 -13
  22. package/docs/en/getting-started.md +232 -126
  23. package/docs/en/investigation.md +219 -0
  24. package/docs/en/jev-shadow.md +67 -0
  25. package/docs/en/model-policy.md +147 -62
  26. package/docs/en/releasing.md +207 -0
  27. package/docs/en/session-evaluation.md +4 -2
  28. package/docs/en/session-recovery.md +49 -6
  29. package/docs/en/workflow.md +222 -114
  30. package/docs/evaluation/README.md +12 -0
  31. package/docs/evaluation/jev-historical-provisional.json +138 -0
  32. package/docs/evaluation/jev-historical-result-2026-11-10.json +174 -0
  33. package/docs/plans/2026-11-01-dsh-integration.md +67 -0
  34. package/docs/plans/2026-11-01-model-profiles-preflight.md +29 -0
  35. package/docs/plans/2026-11-01-npm-installation.md +19 -0
  36. package/docs/plans/2026-11-03-codex-pro-default.md +28 -0
  37. package/docs/plans/2026-11-06-adaptive-workflow.md +365 -0
  38. package/docs/plans/2026-11-07-session-lifecycle.en.md +424 -0
  39. package/docs/plans/2026-11-07-session-lifecycle.md +337 -0
  40. package/docs/plans/2026-11-08-flow-console.md +271 -0
  41. package/docs/plans/2026-11-10-jev-shadow.md +32 -0
  42. package/docs/plans/2026-11-10-task-discovery.md +17 -0
  43. package/docs/plans/2026-11-10-workbench-redesign.md +19 -0
  44. package/docs/plans/2026-11-12-feedback-driven-workflows.md +739 -0
  45. package/docs/plans/README.md +22 -0
  46. package/docs/reviews/2026-08-24-v0.18-review-fixplan.md +265 -0
  47. package/docs/reviews/2026-09-12-pr4-pr5-review.md +70 -0
  48. package/docs/reviews/README.md +12 -0
  49. package/docs/validation/2026-11-01-npm-installation.md +105 -0
  50. package/docs/validation/2026-11-01-profiles-preflight.md +67 -0
  51. package/docs/validation/2026-11-01-results.md +114 -0
  52. package/docs/validation/2026-11-03-codex-pro-default.md +90 -0
  53. package/docs/validation/2026-11-04-dsh-native-view.md +85 -0
  54. package/docs/validation/2026-11-04-release-0.28.1.md +33 -0
  55. package/docs/validation/2026-11-04-release-0.28.2.md +35 -0
  56. package/docs/validation/2026-11-05-dsh-0.2.2-compatibility.md +26 -0
  57. package/docs/validation/2026-11-05-registry-smoke-recovery.md +26 -0
  58. package/docs/validation/2026-11-05-release-0.28.3.md +32 -0
  59. package/docs/validation/2026-11-05-subscription-model-access.md +60 -0
  60. package/docs/validation/2026-11-05-view-order.md +14 -0
  61. package/docs/validation/2026-11-07-adaptive-workflow.md +79 -0
  62. package/docs/validation/2026-11-07-claude-code-pro.md +144 -0
  63. package/docs/validation/2026-11-07-session-lifecycle.md +136 -0
  64. package/docs/validation/2026-11-08-session-p3-p4.md +99 -0
  65. package/docs/validation/2026-11-09-flow-console.md +81 -0
  66. package/docs/validation/2026-11-10-jev-shadow.md +50 -0
  67. package/docs/validation/2026-11-10-task-discovery.md +45 -0
  68. package/docs/validation/2026-11-10-workbench-redesign.md +54 -0
  69. package/docs/validation/2026-11-11-release-0.30.2.md +65 -0
  70. package/docs/validation/2026-11-11-release-0.31.0.md +46 -0
  71. package/docs/validation/2026-11-12-dsh-0.2.2-rc.2.md +58 -0
  72. package/docs/validation/2026-11-12-feedback-driven-workflows.md +187 -0
  73. package/docs/validation/README.md +41 -0
  74. package/docs/validation/evidence/2026-11-08-session-p3-p4.json +5430 -0
  75. package/docs/validation/evidence/claude-node-bridges.txt +118 -0
  76. package/docs/validation/evidence/claude-npm-build.txt +15 -0
  77. package/docs/validation/evidence/claude-npm-candidate.json +54 -0
  78. package/docs/validation/evidence/claude-npm-install.txt +21 -0
  79. package/docs/validation/evidence/claude-npm-tests.txt +145 -0
  80. package/docs/validation/evidence/claude-plugin-tests.txt +205 -0
  81. package/docs/validation/evidence/claude-quality-gate.txt +29 -0
  82. package/docs/validation/evidence/claude-race.txt +7 -0
  83. package/docs/validation/evidence/codex-pro-070-probes.txt +4 -0
  84. package/docs/validation/evidence/dsh-bridge.txt +4 -0
  85. package/docs/validation/evidence/dsh-native-view-bridge-tests.txt +1 -0
  86. package/docs/validation/evidence/dsh-native-view-build.txt +15 -0
  87. package/docs/validation/evidence/dsh-native-view-candidate.json +54 -0
  88. package/docs/validation/evidence/dsh-native-view-inspect.txt +27 -0
  89. package/docs/validation/evidence/dsh-native-view-install-tests.txt +19 -0
  90. package/docs/validation/evidence/dsh-native-view-npm-tests.txt +143 -0
  91. package/docs/validation/evidence/dsh-native-view-plugin-tests.txt +99 -0
  92. package/docs/validation/evidence/dsh-native-view-quality-gate.txt +29 -0
  93. package/docs/validation/evidence/dsh-plugin-tests.txt +48 -0
  94. package/docs/validation/evidence/function-coverage.txt +378 -0
  95. package/docs/validation/evidence/npm-build.txt +13 -0
  96. package/docs/validation/evidence/npm-contract-tests.txt +65 -0
  97. package/docs/validation/evidence/npm-dsh-bridge.txt +18 -0
  98. package/docs/validation/evidence/npm-dsh-plugin-tests.txt +62 -0
  99. package/docs/validation/evidence/npm-function-coverage.txt +420 -0
  100. package/docs/validation/evidence/npm-install-tests.txt +20 -0
  101. package/docs/validation/evidence/npm-quality-gate.txt +29 -0
  102. package/docs/validation/evidence/npm-race.txt +7 -0
  103. package/docs/validation/evidence/pr-dsh-bridge.txt +4 -0
  104. package/docs/validation/evidence/pr-dsh-plugin-tests.txt +48 -0
  105. package/docs/validation/evidence/pr-function-coverage.txt +379 -0
  106. package/docs/validation/evidence/pr-quality-gate.txt +28 -0
  107. package/docs/validation/evidence/pr-race.txt +6 -0
  108. package/docs/validation/evidence/profiles-control-smoke.json +1 -0
  109. package/docs/validation/evidence/profiles-dsh-bridge.txt +18 -0
  110. package/docs/validation/evidence/profiles-dsh-plugin-tests.txt +59 -0
  111. package/docs/validation/evidence/profiles-function-coverage.txt +411 -0
  112. package/docs/validation/evidence/profiles-quality-gate.txt +29 -0
  113. package/docs/validation/evidence/profiles-race.txt +7 -0
  114. package/docs/validation/evidence/quality-gate.txt +28 -0
  115. package/docs/validation/evidence/race.txt +6 -0
  116. package/docs/validation/evidence/watchdog-startup-after.txt +2 -0
  117. package/docs/validation/evidence/watchdog-startup-before.txt +6 -0
  118. package/docs/validation/evidence/watchdog-startup-quality-gate.txt +29 -0
  119. package/docs/validation/evidence/watchdog-startup-race.txt +7 -0
  120. package/docs/{claude-code-pro.md → zh-CN/claude-code-pro.md} +23 -17
  121. package/docs/{configuration.md → zh-CN/configuration.md} +323 -139
  122. package/docs/zh-CN/contributing.md +240 -0
  123. package/docs/{flow-console.md → zh-CN/flow-console.md} +55 -12
  124. package/docs/zh-CN/getting-started.md +352 -0
  125. package/docs/zh-CN/investigation.md +182 -0
  126. package/docs/zh-CN/jev-shadow.md +79 -0
  127. package/docs/zh-CN/model-policy.md +123 -0
  128. package/docs/zh-CN/releasing.md +120 -0
  129. package/docs/{session-evaluation.md → zh-CN/session-evaluation.md} +4 -2
  130. package/docs/{session-recovery.md → zh-CN/session-recovery.md} +46 -12
  131. package/docs/zh-CN/workflow.md +270 -0
  132. package/npm/install.js +1 -1
  133. package/package.json +12 -25
  134. package/docs/getting-started.md +0 -418
  135. package/docs/model-policy.md +0 -65
  136. package/docs/workflow.md +0 -314
@@ -0,0 +1,424 @@
1
+ # Session lifecycles based on task, role, and runtime evidence
2
+
3
+ 2026-11-07. Original design proposal (PR #30 changed documentation only), replacing
4
+ the rule that every Execute or Review invocation must start a fresh session.
5
+ This document retains the original baseline analysis and full phased plan.
6
+ **Implementation note:** P1/P2 normal-terminal continuation and saved-receipt recovery are implemented. P3 adds public lifecycle v1, durable acknowledgements, supervisor journals, and exact read-only recovery. P4 adds role policy, bounded quality rebuilds, and pinned-source paired evaluation with an independent oracle. The [current design](../design.md), [configuration](../en/configuration.md), and [recovery guide](../en/session-recovery.md) define the effective contracts. Valid real-account quality, cache, and performance results remain unavailable; offline success does not substitute for them. The baseline analysis and phased proposal below are historical..
7
+ 中文:[按任务、角色与运行事实管理会话](2026-11-07-session-lifecycle.md).
8
+
9
+ ## 1. Decision
10
+
11
+ **Each session belongs to an explicit task, scope of work, and role. Ordinary repairs
12
+ should normally continue that role's context. Compatibility, recoverability,
13
+ context quality, and runtime evidence determine when to rebuild it.**
14
+
15
+ - A packet's Executor normally continues its own thread for L1 failures, Review returns, and additional work within the same scope.
16
+ - Reviewer context remains separate from Executor context. A review of repairs within the same scope may continue the Reviewer's own thread, while checking the entire current candidate again.
17
+ - Plan maintains continuity within the same planning goal; Judge does so within the same milestone. An explicit second opinion has its own independent context.
18
+ - New tasks, unrelated packets, and different roles do not share threads. Unrecoverable history, incompatible scope, or degraded context calls for rebuilding from authoritative material.
19
+ - Go chooses create, resume, rebuild, or wait from versioned policy and verifiable facts. This does not introduce a parent model to schedule work.
20
+ - Session history, individual invocations, and worker processes have separate lifecycles. Continuing history does not require a resident process or change cleanup, budget, verification, or delivery requirements.
21
+
22
+ This is an engineering choice whose benefits need evaluation, not a claim that
23
+ continuation always outperforms a fresh start. Historical documents retain the
24
+ earlier freshness rule as background; it is no longer an architectural invariant.
25
+
26
+ ## 2. Current implementation and evidence
27
+
28
+ The inspected baselines are Flywheel [`80deeed4`][fw-base], after PR #29 merged,
29
+ and `dsh-subagent-codex-pro@0.8.0` at [`04ecdb67`][plugin-base]. The following
30
+ facts describe those versions. Implementation work must recheck dependencies
31
+ and public interfaces.
32
+
33
+ | Area | Baseline behavior | Implication for this proposal |
34
+ |---|---|---|
35
+ | Scheduling | Go runs packets serially. Execute and Review start fresh sessions; retries retain workspaces and feedback. | A resident parent Agent does not schedule native Teams. Session changes do not implicitly add parallel scheduling. |
36
+ | Kimi Plan | History can resume when `resident-session` is explicitly enabled and the identity matches. | Process termination and history continuity can coexist; this does not establish support for every stage. |
37
+ | Codex Pro plugin | The machine API supports `ephemeral`, `persistent`, and an explicit `threadId`. | A public foundation exists for continuation after normal completion. There is no need to return to the old Codex CLI driver. |
38
+ | Flywheel bridge and driver | The bridge hardcodes ephemeral mode. The driver rejects a nonempty SessionID, requires no requested thread ID in the receipt, and accepts configuration evidence only from `thread/start`. | Requests, state, receipt validation, and call sites must change together. Changing one switch is insufficient. |
39
+ | DSH worker | Flywheel has not connected history restoration. | Default Flash Execute and GPT Review remain important implementation work. |
40
+ | Early machine events | Public options expose only signal, env, and text onProgress. Structured run identifiers arrive in the final receipt. | The first implementation cannot promise to recover a newly created thread after a crash at any point. |
41
+
42
+ Sources: [Flywheel design and current behavior][fw-design], [bridge][fw-bridge],
43
+ [driver][fw-driver], [plugin machine API][plugin-machine], and
44
+ [machine implementation][plugin-machine-src].
45
+
46
+ ### Why retain machine
47
+
48
+ `machine` is the plugin's programmatic interface for deterministic orchestrators.
49
+ It is neither a temporary computer nor a session type. Flywheel can request a
50
+ Codex harness run directly and receive configuration, outcome, cleanup, and usage
51
+ receipts. It does not need to create a DSH parent model and ask that model to call
52
+ `subagent_codex` first ([the tool registered by the plugin][plugin-readme]).
53
+
54
+ The original decision was based on the inspected DSH rc.5 SDK and plugin
55
+ interface constraints; it is not a claim about every future DSH version. See the
56
+ [original integration plan](2026-11-03-codex-pro-default.md) and
57
+ [validation record](../validation/2026-11-03-codex-pro-default.md).
58
+
59
+ | Dimension | Choice | Meaning |
60
+ |---|---|---|
61
+ | Invocation interface | machine API | Go calls the plugin and consumes machine-verifiable receipts. |
62
+ | Context | New thread or resume a specified thread | Whether this invocation inherits that role's previous interaction history. |
63
+ | History persistence | ephemeral or persistent | Whether the plugin requests recoverable Codex history; this does not imply zero filesystem writes. |
64
+ | Process lifetime | Start and clean up for each invocation, or remain running | How long processes live, independently of history persistence. |
65
+
66
+ A new worker and app-server can therefore run for each invocation and finish with
67
+ confirmed cleanup, while persistent history and an explicit thread ID preserve
68
+ context. A completely new, independent Reviewer thread can also retain history
69
+ for later reviews of repairs. The official [App Server documentation][oa-app-server]
70
+ and [Codex SDK documentation][oa-sdk] expose creation and continuation as explicit
71
+ operations. They describe capabilities; they do not choose Flywheel's policy.
72
+
73
+ ## 3. Context ownership and default policy
74
+
75
+ The following is the target policy. The first invocation creates context for its
76
+ own scope. Subsequent invocations must pass the eligibility checks in §4. A backend
77
+ without implemented support retains its currently available behavior with a
78
+ recorded reason; the engine does not silently change models or channels.
79
+
80
+ | Role | Session scope | Normally continue for | Normally rebuild or create separately for |
81
+ |---|---|---|---|
82
+ | Plan | A continuous planning goal within one task | Contract format corrections, revisions to the same goal, planning feedback from a verification gap | A new goal, incompatible key assumptions, or unavailable context |
83
+ | Execute | task + packet + executor | L1 repairs, Review returns, ordinary tests or reports, implementation iterations within the same scope | Unrelated packets, a materially different goal, uncontrolled context growth, or unrecoverable history |
84
+ | Review | Packet review in Full; final review of the entire single-packet requirement in Quick | Reviewing repairs within the same scope or correcting verdict format | A new review scope, a deliberate independent second opinion, contamination by Executor history, or unauthorized candidate changes |
85
+ | Judge | milestone + judge role; second opinions have separate ownership | Re-evaluating the same milestone after repairs | A new milestone, an explicit second opinion, or incompatible judgment scope |
86
+ | Verify | No model session | Running deterministic checks again | Not applicable |
87
+ | Intake / Garden | One explicit advisory task | Additions or revisions to that advice | Unrelated tasks; outside the first implementation phase |
88
+
89
+ Reviewer and Judge must not inherit the Executor's conversation, private reasoning,
90
+ or tool trajectory as a substitute for independent inspection. They consume current
91
+ contracts, the authoritative diff, valid reports, applicable verification evidence,
92
+ and their own previous findings. Every review of repairs checks the full current
93
+ scope, newly introduced problems, and whether earlier findings should close or
94
+ reopen. Every Quick final Review covers all requirements; it cannot merely tick
95
+ off the few issues raised previously.
96
+
97
+ Another independent opinion remains an explicit workflow requirement or an optional
98
+ evaluation technique. Session continuity does not add one automatically. A Quick
99
+ run that succeeds on its first attempt still has **two stage invocations: Execute
100
+ and independent final Review**. Full retains its existing integration verification
101
+ and Judge stages. Session policy does not determine Quick or Full eligibility.
102
+
103
+ ## 4. How Go chooses the next invocation
104
+
105
+ Before choosing a session action, Go checks stop intent, the run lease, budgets,
106
+ and attempt limits. A thread that still exists does not restart work after a user
107
+ stop. Session eligibility is reconsidered only after an explicit recovery entry
108
+ starts the task. Changing sessions, upgrading Quick to Full, or replacing a process
109
+ does not reset counters.
110
+
111
+ ### 4.1 Eligibility to resume
112
+
113
+ Ordinary resume requires all of the following:
114
+
115
+ 1. The thread belongs to the correct task, packet or milestone, and role. No other turn is active, and no conflicting writer owns the workspace.
116
+ 2. Dispatch, terminal outcome, and cleanup facts from the previous invocation are sufficiently established. No execution result or side effect remains unresolved.
117
+ 3. Persistent history and an explicit thread ID are available, and the backend's public restoration capability has been adapted and verified.
118
+ 4. Workspace provenance, contract revisions, and effective runtime bindings satisfy the versioned compatibility policy. Each invocation still receives current authoritative material.
119
+ 5. No context or stagnation limit, or explicit reset, has been triggered. The original task still has budget and attempt allowance.
120
+
121
+ Unavailable history does not require discarding the workspace. A new context may
122
+ be created once the previous execution and cleanup are confirmed safe. Unknown
123
+ outcomes or cleanup require reconciliation first. **A fresh session cannot bypass
124
+ that block either.**
125
+
126
+ ```mermaid
127
+ flowchart TD
128
+ A["Authorization, lease, and budget checks pass"] --> B{"Unconfirmed execution or cleanup?"}
129
+ B -->|Yes| C["Reconcile facts or stop"]
130
+ B -->|No| D{"Same role and scope, and resumable?"}
131
+ D -->|Yes| E["Resume role thread"]
132
+ D -->|No| F["Create context with authoritative handoff"]
133
+ E --> G["Run and persist receipt"]
134
+ F --> G
135
+ G --> H["Verify current candidate"]
136
+ H -->|Repair needed and still authorized| A
137
+ H -->|Evidence complete| I["Continue workflow delivery"]
138
+ ```
139
+
140
+ The diagram shows session selection and repair continuity. The existing state
141
+ machine still controls Plan, Review, Judge, budgets, and completion gates.
142
+
143
+ ### 4.2 Compatibility does not require every field to remain unchanged
144
+
145
+ Three identities must remain distinct: **session ownership**, **this attempt**,
146
+ and **the candidate and contracts being verified**. Repairs change the candidate;
147
+ that is a normal use of continuation. Candidate changes invalidate relevant old
148
+ evidence without automatically destroying the conversation. A revision within the
149
+ same goal can also continue with an authoritative contract diff. A changed Spec
150
+ hash does not by itself require a fresh context.
151
+
152
+ | Change | Handling principle |
153
+ |---|---|
154
+ | Task, role, or unrelated packet or milestone | Create context for the new scope; do not claim another scope's thread. |
155
+ | Candidate implementation, tests, or done-report | Record identities before and after the invocation, invalidate evidence under existing rules, and repeat relevant verification. Context may continue. |
156
+ | Contract revision | Record old and new fingerprints and structured revision grounds. Compatible revisions to the same goal may continue; unknown compatibility or a materially changed goal requires rebuilding or replanning. |
157
+ | cwd | Resolve the absolute physical path first. A path alias is not a new task. A real workspace move requires explicit checks of ownership and content before continuation. |
158
+ | Provider, account channel, or role permission boundary | Check effective bindings and existing authorization. Resume cannot mix accounts, expand permissions without authorization, or introduce an unauthorized paid fallback. |
159
+ | Model, effort, effective tools, or permission configuration | Evaluate supported per-turn or resume overrides and their evidence. Neither unconditional freshness nor unconditional continuation is valid. Initially, unverified combinations conservatively rebuild or fail. |
160
+ | Plugin, protocol, or harness version | Use a verified capability table. An upgrade does not automatically establish compatibility with stored history. |
161
+
162
+ Go does not make a semantic decision from free text saying that something “looks
163
+ like the same goal.” Revisions proposed by Plan or the user still undergo existing
164
+ authorization and contract validation. Implementation must define a versioned set
165
+ of mechanically checkable compatible changes. Changes that cannot be checked take
166
+ an explicit rebuild path or the existing planning or human escalation path.
167
+ Backend evidence that a request was accepted remains distinct from confirmation
168
+ that a configuration took effect; the engine must not overstate the evidence.
169
+
170
+ ### 4.3 Choose an action from the actual failure
171
+
172
+ | Event | Session action | Required constraint |
173
+ |---|---|---|
174
+ | L1 finds an implementation defect after a valid execution receipt and confirmed cleanup | Send failure evidence to the original Executor for repair. | Verify the new candidate; retain total attempts and budget. |
175
+ | Review returns work | The original Executor repairs it; the independent Reviewer reviews again. | Review the full current scope; an old pass cannot carry forward. |
176
+ | Report or verdict format is invalid, but the underlying run reliably ended | Continue the same role to correct its output. | Distinguish report errors from an untrustworthy runtime receipt; preserve existing retry limits. |
177
+ | verification-gap | Enter the existing Plan revision path, then assess compatibility for each role. | Persist Quick's upgrade first; invalidate affected evidence. |
178
+ | AUTH, QUOTA, or RATE_LIMIT | Pause, back off, or resume after authorization as prescribed by existing error policy. | A different thread does not fix credentials or quota; do not automatically switch to a paid channel. |
179
+ | Startup fails and non-dispatch is confirmed | Retry the known intent when allowed. | Record the attempt; unknown dispatch cannot be treated as non-dispatch. |
180
+ | History is missing or has no rollout, with confirmation that no new turn was sent and cleanup completed | Rebuild explicitly with a handoff. | No silent cold start; original task counters remain. |
181
+ | Context exceeds limits, becomes contaminated, or repeated failures make no progress | Use bounded compaction, rebuilding, or an existing escalation exit. | Use only public, verified capabilities; repeatedly replacing threads must not evade stopping rules. |
182
+ | Connection drops, a terminal receipt is lost, or cleanup is unconfirmed | Wait, reconcile, or stop. | Neither immediate resume nor replay through a fresh writer is allowed. |
183
+ | A person or external task changes the workspace | Reconcile provenance and candidate identity; invalidate relevant evidence. | Preserve files; a new thread does not resolve conflicts. |
184
+
185
+ Context length, consecutive repairs, and stagnation need bounded, configurable,
186
+ recorded policies. The first implementation uses existing attempt, no-progress,
187
+ and budget limits rather than claiming a universally optimal number or percentage.
188
+ Backend compaction does not establish that Flywheel can request, control, or
189
+ verify compaction itself.
190
+
191
+ ## 5. Target state and protocol contracts
192
+
193
+ The following are **proposed data responsibilities**, not current schema fields
194
+ or configuration that can be copied into a running installation. Implementation
195
+ must first update `templates/state.schema.json` and related configuration and
196
+ protocol definitions. `internal/state` then owns compatible loading and CAS writes.
197
+ Workers, models, skills, and the desktop UI do not write state directly.
198
+
199
+ | Record | Facts to retain |
200
+ |---|---|
201
+ | Session ownership | Task, packet or milestone, role, canonical worktree, generation, and policy version. |
202
+ | Resume binding | Harness and protocol versions, provider and channel, nonsecret account configuration reference, model, requested effort, effective permission and tool configuration, and compatibility policy version. |
203
+ | History handle | Backend opaque thread ID, persistence property, evidence of resumability, latest confirmed checkpoint, and retirement or rebuild reason. |
204
+ | Individual invocation | Engine invocation ID, requestId, backend runId and turnId, attempt, dispatch intent and timestamps, terminal receipt reference and digest. |
205
+ | Runtime facts | What is known about dispatch and outcome, cleanup confirmation, and lease or active invocation ownership. These cannot collapse into one success Boolean. |
206
+ | Candidate and contracts | Identities before and after the invocation, contract version, revision grounds, and associated verification or verdict evidence; old evidence is archived under existing rules. |
207
+ | Usage accounting | Attributable increment for this run, complete/partial/unknown status, and the identity of the accounted receipt to prevent replay from counting twice. |
208
+
209
+ Account identity stores only nonsecret references, never credentials. The backend
210
+ thread ID is an opaque handle; its format must not be parsed to infer task ownership.
211
+ `requestId` is a correlation identifier. The current plugin does not promise
212
+ idempotence or deduplication. A PID does not establish ownership or cleanup either.
213
+
214
+ Record the requested history persistence mode, what the adapter can confirm, and
215
+ the actual restoration result separately. A thread ID alone proves neither
216
+ persistence nor recoverability. The terminal receipt in `0.8.0` does not directly
217
+ echo `threadMode` or `resumable:true`; the engine must not invent these as
218
+ backend-confirmed values. The first implementation selects resume candidates from
219
+ the original request, verification of the pinned adapter, and terminal facts.
220
+ Actual restoration still requires acceptance by `thread/resume`.
221
+
222
+ Go persists dispatch intent before starting a worker. After validating and atomically
223
+ persisting a complete receipt, it updates state and accounting through CAS. A receipt
224
+ file is invocation evidence, not a second state machine. Only Go, while holding the
225
+ lease, may reconcile state from a matching invocation, content digest, and version.
226
+ An accounted receipt cannot be charged again. A done-report on disk does not prove
227
+ that the underlying run ended. Workers transport versioned requests and receipts;
228
+ they do not choose reuse, model changes, or retries.
229
+
230
+ At most one turn may be active in a thread, and at most one writer may be active
231
+ in a writable workspace. The existing task run lease remains in force. Future
232
+ parallelism requires explicit packet workspace and thread ownership. A busy thread
233
+ does not authorize creating another thread to write to the same workspace concurrently.
234
+
235
+ ## 6. Deliver ordinary continuation and crash recovery separately
236
+
237
+ ### 6.1 What the first implementation can guarantee
238
+
239
+ The first Codex Pro invocation requests persistent history. After its complete
240
+ terminal receipt arrives normally and is durably saved, the next eligible repair
241
+ passes that role's thread ID explicitly. Each invocation can still start separate
242
+ processes and complete their cleanup. Plugin `0.8.0` already exposes this normal
243
+ path; Flywheel must connect it. See the [plugin interface][plugin-machine-src].
244
+
245
+ The first implementation uses **normal invocations with reliably persisted receipts**
246
+ as resumable checkpoints. A crash after thread creation but before the terminal
247
+ receipt may leave no saved thread ID. Even a known ID may lack a recoverable rollout.
248
+ The plugin source records that an empty thread could not resume in its tested
249
+ version. Successful creation must not be treated as completed, resumable history.
250
+ See the [thread start and resume implementation][plugin-wire].
251
+
252
+ Text `onProgress` is not a recovery protocol. It lacks versioned structure and a
253
+ durability acknowledgement, callback errors do not reliably prevent execution,
254
+ and thread text appears before complete configuration validation. Parsing an ID
255
+ from logs does not close the crash window.
256
+
257
+ ### 6.2 Public APIs required for interruption recovery
258
+
259
+ Reliable reconciliation after interruption needs new public, versioned typed
260
+ lifecycle and recovery contracts in the plugin. They must cover at least:
261
+
262
+ 1. `thread-ready` after configuration validation, with explicit request/run/thread correlation, persistence properties, and evidence.
263
+ 2. A programmatic acknowledgement that Go has persisted the checkpoint before sending a new turn. This is protocol coordination, not an additional user approval.
264
+ 3. Separate facts for turn dispatch intent, a request that may have been sent, backend acceptance, and terminal outcome. Terminal events still include independent cleanup facts.
265
+ 4. A read-only reconciliation entry for known runs, stating which turn, process, and result facts can be re-established and which remain unknown.
266
+
267
+ These are proposed interfaces, not APIs already available in `0.8.0`. Even an early
268
+ checkpoint leaves a possible uncertainty window between sending a request and
269
+ persisting acknowledgement. Without a backend idempotent execution contract, the
270
+ system cannot promise exactly-once execution. It must reconcile facts, preserve
271
+ unknowns, and prevent blind replay.
272
+
273
+ | Interruption point | Recovery requirement |
274
+ |---|---|
275
+ | The first thread was created, but its final receipt is not durable | Preserve the workspace. Reconcile processes and results first; do not promise to recover an unknown thread. |
276
+ | A new turn on a known thread was sent before disconnecting | Knowing the thread ID does not authorize dispatching again. Establish the previous turn's facts first. |
277
+ | A complete receipt is durable, but state or accounting is incomplete | Apply the confirmed receipt idempotently; do not invoke the model again. |
278
+ | A report file exists, but the final receipt is lost | The report does not prove terminal outcome, cleanup, configuration, or usage. Keep these unknown until reconciled. |
279
+ | Resume is explicitly rejected before a new turn, with cleanup confirmed | Rebuild with a handoff under bounded policy; preserve the failure reason and original counters. |
280
+ | The guardian may clean up later, but confirmation is currently missing | The current invocation cannot report success or start a conflicting writer. Wait for verifiable evidence. |
281
+
282
+ Preserve and extend the existing [stop rule for unconfirmed cleanup][fw-cleanup].
283
+ Recovery on another machine also depends on history storage and environment
284
+ availability. Saving a thread ID in the task directory does not copy Codex history
285
+ from another machine.
286
+
287
+ ## 7. Repair inputs, rebuild handoffs, and accounting
288
+
289
+ A resumed invocation still receives concise, current authoritative input: goal and
290
+ constraint references, contract revisions, the candidate and diff, new verification
291
+ failures and review findings, confirmed progress, and this invocation's delivery
292
+ requirements. History cannot override those facts. A bare “continue” is insufficient.
293
+ Stable contracts remain separate from changing feedback; there is no reason to
294
+ repeat an entire transcript unnecessarily.
295
+
296
+ Rebuilding uses the Spec, packet, work on disk, valid reports, verification results,
297
+ and structured feedback. The handoff records the replaced thread or attempt and
298
+ the reason for rebuilding. It does not copy Executor private reasoning to Reviewer.
299
+ Summaries help navigation; authoritative code and verification still need inspection.
300
+ Preserve existing work and do not repeat external actions already confirmed complete.
301
+
302
+ Usage is accounted from the attributable increment for this run. A resumed thread's
303
+ cumulative total cannot be treated as new consumption on every invocation. Without
304
+ a trustworthy baseline or sufficient detail, retain unknown or partial status.
305
+ Unreported dollar cost remains unknown; subscription calls are not recorded as free.
306
+ Budgets include all prior attempts, failures, rebuilds, and upgrades under existing
307
+ soft and hard budget semantics. The plugin's existing run delta and thread totals
308
+ also require validation through the bridge protocol. See [usage receipts][plugin-machine].
309
+
310
+ Observability should show at least the role and scope, create/resume/rebuild/wait
311
+ decision, its reason, the latest invocation state, and usage completeness. The
312
+ task association in the DSH parent conversation remains a control surface; it
313
+ does not mean worker transcripts automatically merge into that conversation.
314
+ History persistence, archival, retention, and process cleanup are separate policies.
315
+ Process termination does not delete the workspace, deliveries, or audit material.
316
+ Implementation must specify retention rather than silently preserving every task
317
+ history forever, and it must not promise automatic visibility in a desktop list.
318
+
319
+ ## 8. Implementation phases
320
+
321
+ | Phase | Deliverable | Completion boundary |
322
+ |---|---|---|
323
+ | P0: this PR | Revised design principle, current and target behavior, links in both languages, and validation plan | Design review only; no source, schema, package version, or release changes. |
324
+ | P1: ordinary Codex Pro continuation | Go session records and policy, versioned worker requests, persistent/threadId support, start/resume receipt validation, normal repair and cancellation tests | Scoped continuation for enabled Codex Pro roles; only durable normal terminal receipts become checkpoints. |
325
+ | P2: other backends and role coverage | Verify and implement default DSH Execute and Review, plus Kimi Execute and scoped continuity for Plan and Judge | Verify each capability separately. Supporting hard does not complete the default Flash path. |
326
+ | P3: interruption reconciliation | Integrate public typed lifecycle, durability acknowledgement, and recovery contracts with the plugin | Fault injection demonstrates no blind replay. Parsing logs for IDs is insufficient. |
327
+ | P4: context quality and measured tuning | Verified compaction or rebuild policies, controlled evaluation on real tasks, and observable reasons | Adjust from quality and measured results, without assuming cache rates or savings. |
328
+
329
+ P2 and P3 can proceed separately after P1's contracts stabilize. P1 initially covers
330
+ the existing Codex Pro hard Execute route. If a user has already configured Review
331
+ or Judge explicitly for Codex Pro, the same adapter should use separate handles
332
+ for those roles. Demonstrating review continuity must not automatically switch the
333
+ default DSH GPT Review to Codex Pro.
334
+
335
+ P1 touches at least these responsibilities. Exact fields and protocol versions
336
+ belong in the implementation PR:
337
+
338
+ - `internal/state/` and `templates/state.schema.json`: session and attempt identity, receipt reconciliation, and migration of old state.
339
+ - `internal/machine/steps_execute.go`, `steps_verdict.go`, and `steps_plan.go`: shared eligibility selection, feedback, stopping, and budgets; no separate retry engine copied into each stage.
340
+ - `internal/drivers/`: transport thread/run/turn identities in requests and results, and validate the actual evidence for start and resume separately.
341
+ - `plugins/dsh/src/codex-pro-bridge.js` and the worker protocol: allow explicit persistence and restoration fields, validate ownership, and preserve cleanup and usage completeness.
342
+ - Configuration schema, inspect, doctor, and documentation in both languages: expose backend capabilities and effective policy. Preflight must not call a model to establish history recoverability.
343
+ - Controls and skills: document state and recovery entries once implemented. Skills still call Go; they do not pick threads or run repair loops themselves.
344
+
345
+ The production goal is ordinary scoped continuation for new tasks on verified
346
+ backends, with fresh context retained as a valid choice and explicit fallback.
347
+ Validate through a capability allowlist and explicit trials before updating
348
+ defaults. Every enabled capability needs versioned state and checkable evidence.
349
+ Existing tasks without handles start a new thread on the first invocation; the
350
+ engine does not scan user history or guess the “latest thread.” Existing budgets,
351
+ attempts, stop intent, and workflow semantics remain. Unknown policy versions or
352
+ corrupt records fail loading explicitly.
353
+
354
+ Do not reinterpret the existing Plan `resident-session` Boolean as a universal
355
+ switch for every stage, or change the user's explicit existing settings. New
356
+ policy configuration must distinguish context selection from history persistence.
357
+ This proposal provides no CLI flags or configuration examples that cannot yet run.
358
+ Unsupported backends keep their current fresh behavior with a capability reason,
359
+ without presenting that as a successful resume.
360
+
361
+ ## 9. Acceptance and evaluation
362
+
363
+ ### Behavioral acceptance
364
+
365
+ | Scenario | Required evidence |
366
+ |---|---|
367
+ | Quick succeeds on its first attempt | Exactly two stage invocations remain: Execute and independent final Review. All existing verification and delivery gates run. |
368
+ | Execute → Review return → Execute repair → Review | Both Executor invocations use the same Executor thread; Reviewer may continue its separate independent thread. All four invocations have their own attempt/run/turn, and old evidence is not reused automatically. |
369
+ | L1 failure or malformed output | Send precise feedback to the correct role. Existing attempt and budget limits remain. Do not confuse invalid reports with untrustworthy runtime receipts. |
370
+ | Reviewer checks repairs | Cover the entire current scope and new regressions, close or reopen prior findings, and produce a new decision for every Quick requirement. |
371
+ | Revision within the same goal or a materially different goal | The first may continue under checkable compatibility policy; the second rebuilds. Both invalidate and re-run affected verification. |
372
+ | New packet, role, or second opinion | Do not reuse context from another scope or introduce Executor transcripts into independent review. |
373
+ | Configuration or path changes | Test supported and unsupported overrides, normalize paths, and distinguish request acceptance from evidence of effective settings. |
374
+ | Missing or busy thread, or no rollout | Bounded rebuilding requires confirmed non-dispatch and cleanup. A busy thread must not start a second writer. |
375
+ | Interruption, invalid frames, or unknown cleanup | Block both resume and replay in a fresh session. Preserve the workspace and actual unknown state. |
376
+ | Durable receipt with interrupted CAS or accounting | Reconcile it once without another model call or recounting cumulative usage. |
377
+ | Cancellation or explicit stop | Complete cleanup. Opening a view or having recoverable history does not restart work. |
378
+ | Legacy tasks or unsupported backends | Load compatibly, preserve budgets and work, record reasons for new context, and do not scan history to claim a thread. |
379
+
380
+ Implementation PRs must run the applicable repository Go quality and coverage
381
+ gates, Node checks, and bridge checks across processes. Validate actual subprocesses,
382
+ Git candidates, fault windows, and public protocol behavior rather than writing
383
+ tests that mirror the implementation. Record offline checks separately from real
384
+ Codex, Kimi, and DSH account tests and Mac lifecycle acceptance. This design PR
385
+ checks documents, relative links, sources, the boundary between current and proposed
386
+ behavior, and independent review. It does not claim those implementation tests ran.
387
+
388
+ ### Effectiveness evaluation
389
+
390
+ For matched tasks, models, effort, permissions, contracts, and independent acceptance,
391
+ compare at least:
392
+
393
+ 1. The current policy of starting fresh every time.
394
+ 2. Executor continuation within the packet, with a new independent Reviewer context each time.
395
+ 3. Executor and Reviewer each continuing within their own scope.
396
+
397
+ Include first-attempt success, L1 repair, Review returns, long context, stop and
398
+ recovery, and configuration changes. Use repeated paired trials to record quality,
399
+ missed issues and regressions, repair rounds, repeated findings, elapsed time,
400
+ input/output/cache usage, rebuild reasons, and recovery failures. Unknown usage
401
+ remains unknown. Preserve original conditions and results without claiming a
402
+ percentage improvement in advance. Independent acceptance quality and runtime
403
+ correctness come before conclusions about less repeated investigation or lower cost.
404
+ Extra checks used for evaluation are part of the experiment; they do not become an
405
+ additional default model stage in Quick.
406
+
407
+ ## 10. References
408
+
409
+ - Flywheel: [fixed source baseline][fw-base], [design][fw-design], [bridge][fw-bridge], [driver][fw-driver], and [cleanup rules][fw-cleanup].
410
+ - Codex Pro: [fixed source baseline][plugin-base], [machine documentation][plugin-machine], [machine implementation][plugin-machine-src], and [thread implementation][plugin-wire].
411
+ - OpenAI: [App Server][oa-app-server] and [Codex SDK][oa-sdk]. These pages evolve. Implementation must validate the pinned plugin and actual Codex version; newer documentation does not establish capabilities in older interfaces.
412
+
413
+ [fw-base]: https://github.com/ckanner/flywheel/commit/80deeed4b62682585f82073e7bf9ce831728d6f7
414
+ [fw-design]: https://github.com/ckanner/flywheel/blob/80deeed4b62682585f82073e7bf9ce831728d6f7/docs/design.md
415
+ [fw-bridge]: https://github.com/ckanner/flywheel/blob/80deeed4b62682585f82073e7bf9ce831728d6f7/plugins/dsh/src/codex-pro-bridge.js
416
+ [fw-driver]: https://github.com/ckanner/flywheel/blob/80deeed4b62682585f82073e7bf9ce831728d6f7/internal/drivers/codex_pro.go
417
+ [fw-cleanup]: https://github.com/ckanner/flywheel/blob/80deeed4b62682585f82073e7bf9ce831728d6f7/internal/machine/cleanup.go
418
+ [plugin-base]: https://github.com/ckanner/dsh-subagent-codex-pro/commit/04ecdb677735d84f3a0f5dba01a9d9b28c324c0e
419
+ [plugin-readme]: https://github.com/ckanner/dsh-subagent-codex-pro/blob/04ecdb677735d84f3a0f5dba01a9d9b28c324c0e/README.md
420
+ [plugin-machine]: https://github.com/ckanner/dsh-subagent-codex-pro/blob/04ecdb677735d84f3a0f5dba01a9d9b28c324c0e/docs/machine.md
421
+ [plugin-machine-src]: https://github.com/ckanner/dsh-subagent-codex-pro/blob/04ecdb677735d84f3a0f5dba01a9d9b28c324c0e/src/machine.ts
422
+ [plugin-wire]: https://github.com/ckanner/dsh-subagent-codex-pro/blob/04ecdb677735d84f3a0f5dba01a9d9b28c324c0e/src/wire.ts
423
+ [oa-app-server]: https://learn.chatgpt.com/docs/app-server
424
+ [oa-sdk]: https://learn.chatgpt.com/docs/codex-sdk