Repository navigation
feat: productize durable Deep Research workflow - #1227
Conversation
Deep Research architecture walkthroughBottom line: This PR upgrades Deep Research from a read-only mode prompt and an empty-state UI into a durable, resumable, auditable workflow with an explicit handoff to implementation. 1. What problem does it solve?Before this PR, Deep Research already had:
However, it did not have a durable runtime protocol for executing and recovering a research run. In particular:
Conceptually, the PR introduces a two-stage state machine: stateDiagram-v2
[*] --> active
active --> completed: deep_research_complete
completed --> handoff_ready: deep_research_handoff
handoff_ready --> [*]
A run cannot be completed until its required research steps and report sections are satisfied. The implementation handoff is a separate transition, so research completed and ready for downstream implementation are no longer conflated. 2. Related modulesThe design has two authorities:
flowchart LR
AI["AI model"] --> RT["Runtime Deep Research tools"]
RT --> CORE["Core run state machine"]
RT --> STORE["Artifact Store"]
CORE --> LEDGER["Deep Research ledger artifact"]
STORE --> SRC["Source artifacts"]
STORE --> SEC["Report section artifacts"]
STORE --> FINAL["Final report artifact"]
STORE --> HANDOFF["Implementation handoff artifact"]
LEDGER --> HOOK["useDeepResearchRun"]
SRC --> PANE["Artifact Pane"]
SEC --> PANE
FINAL --> PANE
HANDOFF --> PANE
HOOK --> VIEW["Deep Research workspace UI"]
PANE --> VIEW
The main responsibilities are split as follows:
The runtime exposes eight workflow tools to the model:
Under normal Deep Research operation, these tools are visible to the AI. The prompt explicitly tells the model to use the durable workflow, and the runtime registers the tools for Deep Research sessions. The user-facing Artifact Store tools remain a separate concern from the model-facing workflow tools. 3. Main sequencesequenceDiagram
participant AI as AI model
participant RT as Runtime tools
participant Core as Core state machine
participant Store as Artifact Store
participant UI as Desktop UI
AI->>RT: deep_research_start(plan)
RT->>Core: create run and initial ledger
RT->>Store: persist ledger
Store-->>UI: artifact/deep-research change
loop Research steps
AI->>RT: deep_research_step(...)
RT->>Core: update active step
AI->>RT: deep_research_save_artifact(source)
RT->>Store: persist source body
RT->>Core: append source reference and hash
AI->>RT: deep_research_update_report(section)
RT->>Store: persist section body
RT->>Core: update section reference
AI->>RT: deep_research_checkpoint(...)
RT->>Core: append checkpoint
RT->>Store: persist updated ledger
Store-->>UI: refresh projected run
end
AI->>RT: deep_research_complete(...)
RT->>Core: validate completion gates
RT->>Store: persist final report and completed ledger
Store-->>UI: show completed state
AI->>RT: deep_research_handoff(...)
RT->>Store: persist handoff artifact
RT->>Core: transition to handoff_ready
RT->>Store: persist final ledger
Store-->>UI: show implementation handoff
4. Scope and review focusThis PR is primarily the durable orchestration layer. It does not attempt to redesign the general Artifact Store or turn Deep Research into an independent execution engine. The most important review areas are:
At the time of review, the PR is still a draft, contains 2 commits and 33 changed files ( |
Blocking review findingsI would block merge on the first two issues below. 1. Completion can seal a run whose authoritative artifacts are missing or corrupt
Relevant code:
This creates a split-brain state between the ledger and the Artifact Store. A source, report section, final report, or handoff artifact can be deleted or modified after its reference and hash have been recorded. The completion gate can still succeed because it trusts the ledger metadata. The UI can then show a completed run even though a later artifact read fails integrity or liveness checks. There is also a UI invalidation gap: Suggested fix: before completion and handoff, re-read every required current artifact and validate:
At minimum this should cover all referenced sources, all five current report sections, the final report, and the handoff artifact. The UI should also subscribe to artifact changes that can invalidate the run, or Deep Research-owned artifacts should not be deletable without updating the ledger. 2. Semantic tool-call idempotency is incompleteThe replay comparison for saved artifacts checks role, locator, content hash, source IDs, and section metadata, but it does not compare As a result, the same Terminal-state retry handling is also inconsistent. Several mutating tools call Suggested fix:
Additional safety issue: forged workspace envelopes are not fully strippedThe sanitization helper removes An untrusted source artifact can therefore inject a forged Suggested fix: strip or escape both workspace and artifact envelope tags at every untrusted-content boundary, and add adversarial tests for opening source artifacts containing forged envelopes. Merge stateGitHub currently reports this draft PR as The focused Core, Storage, UI, Runtime Deep Research, and Desktop test suites passed locally, but the negative paths above are not covered by those tests. |
32a9c93 to
2a733f9
Compare
2a733f9 to
717c000
Compare
|
Addressed the blocking findings in 1. Completion integrity / deletion safety
2. Semantic idempotency
3. Workspace-envelope sanitization
Architecture clarification: the current protocol has one terminal Verification
The full Runtime build and Desktop main typecheck still hit pre-existing errors in untouched AI SDK and MCP files ( |
|
@likun666661 The blocking findings have been addressed and the PR is ready for review. Could you please take another look when convenient? The detailed fix and verification summary is in the comment immediately above. |
Summary
Why
Deep Research already existed as a read-only session profile and empty-state prompt surface, but it had no durable authority for long-running state. A resumed session could not reliably inspect prior evidence, checkpoints, or report progress, and implementation handoff semantics were implicit.
This change productizes the workflow requested in #566 while keeping research visibly read-only and source-grounded. The filesystem-backed design is informed by FS-Researcher: research state is persisted as inspectable artifacts and append-only events rather than hidden model context.
What changed
Durable research workspace
toolCallIdwith conflicting semantic inputRuntime and Desktop integration
Reviewability
deep-research-progressvisual-smoke scenarioUser/developer impact
Users can inspect and resume long-running research without silently switching into write mode. Developers get a stable storage/runtime/UI contract with explicit evidence provenance and focused tests for replay, recovery, completion, and permission boundaries.
Validation
npm run lint— 1,806 files checkednpm --workspace @maka/desktop run typechecknpm --workspace @maka/desktop run buildnpm --workspace @maka/desktop run test:checksgit diff --checklight-1280-motionanddark-990-reduced-motionCloses #566