Skip to content

fix(sessions): reset Main archived by restart recovery - #176086

Closed
enki wants to merge 2 commits into
openclaw:mainfrom
enki:fix/reset-archived-main-recovery
Closed

enki wants to merge 2 commits into
openclaw:mainfrom
enki:fix/reset-archived-main-recovery

Conversation

@enki

@enki enki commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an explicit reset being refused when restart recovery has archived and tombstoned the agent’s canonical Main session, leaving its default chat route unusable.

User Impact

An authorized operator can reset the affected Main session through the existing API. Reset retains its physical session identity and transcript and starts a fresh model context; it does not resume or replay the interrupted task. No configuration change or migration is required.

Why This Change Was Made

The reset-only exception requires both a restart-recovery tombstone and a restart-recovery archive reason on the configured canonical Main key. Ordinary archives and archived non-Main sessions retain their existing refusal behavior. Provider-review, model-selection, expected-session identity, plugin ownership, and runtime cleanup guards remain in their existing owners.

Related: #173412, #137264. This complements #173579’s in-place recovery for unarchived sessions; it does not change its UI or continuation contract. #130196’s shared work-start tombstone fence remains intact.

Behavior decision

The review asks whether authorized reset may restore canonical Main archived and tombstoned by restart recovery. I recommend the narrow exception because Main is a stable ingress target: requiring replacement-session routing leaves callers unable to use their established conversation even when they invoke the prescribed reset remedy.

The security invariant in #130196 is that ordinary work cannot cross a tombstone fence; an already-authorized reset owns that transition. The eligibility change stays inside that owner and requires canonical Main, a recovery tombstone, and restart-recovery archival. Ownership, model-lock, stale-session, manual-archive and non-Main restrictions remain. Reset starts fresh context and does not replay the interrupted request; physical identity and retained history stay available.

The original PR explicitly retained archived-row refusal, so this is a deliberate policy extension. The owner choice is whether recovery-created archival should prevent an otherwise-authorized operator from using the existing reset. The exact-head Gateway/reset/fresh-turn proof supports the narrow exception without arguing for general reopening of archived sessions.

Current upstream conflict repair

Refreshed head 794f1dc77381dd1c3bb3306fd22faf7610f69200 is a true merge of the prior PR head and pinned upstream 00575becc9fce53efc73b319a16fa71e6f4123b9. The narrow canonical-Main reset condition is unchanged. The test conflict retains upstream's controller admission coverage and the PR's transcript-history checks, while removing the retired embedded-run mock import.

Fresh checks on the merged source pass: the complete reset-cleanup owner suite (21 tests; 93.18 seconds wrapper wall time), production core types, owner Gateway-server test types, scoped typed lint, formatting, whitespace, and independent P0–P2 review. The reviewer found no actionable issue in the two-file PR diff; unprovided surrounding upstream modules were outside its independent coverage. The merge preserves both parent histories and adds no schema or permission change beyond the existing proposed reset exception.

New-head CI is pending. Earlier full Gateway/reset/fresh-turn captures retain their original source qualifications; they are not presented as a new runtime capture on this merged head. The behavior decision above remains unresolved.

Evidence

The existing Gateway reset-cleanup handler fixture reproduces the defect: default and custom-key Main reset cases fail before the repair while three archive-policy controls pass. Afterward, all 23 owning cases pass, including the new model-lock and stale-identity controls. The successful cases read the persisted transcript before and after reset, retaining its prior events and physical session ID while adding the reset boundary and clearing recovery/archive metadata.

Strict targeted production/test types, type-aware scoped lint, formatting, and fresh independent review through P2 pass. All fixtures are synthetic. The final full owning run took 103.50s Vitest / 111.74s wrapper, including 52.49s cold artifact preparation; it extends the existing Gateway cleanup owner rather than introducing another fixture or suite. Exact-head broad PR CI now passes (CI gate); hosted per-file timing has not been extracted. No operator Gateway or live session was changed for this proof.

Real Gateway reset and usable-turn proof

On exact head f1c01bab5aee, an isolated real Gateway accepted an authenticated sessions.reset for synthetic canonical Main with both restart-recovery archive metadata and a tombstone. The physical session ID stayed the same, archive/tombstone state cleared, and the original synthetic message remained exactly retrievable through the canonical history messageId reopen. The default history tail correctly showed the new Reset context boundary.

A fresh authenticated turn then traversed the production embedded runtime, real HTTP/OpenAI SDK, and actual read-tool filesystem I/O. The second provider request contained the synthetic file receipt; the correlated assistant final confirmed completion. Provider response frames were scripted on loopback; no external provider or operator state was used. The task Gateway/provider stopped and fixture state was removed. Existing 23-case owner coverage separately proves archive/model-lock/stale-identity refusals. This does not resolve the maintainer policy decision.

Captured output from the synthetic Gateway run

The following is the test process’s captured terminal result, formatted as JSON. It ran the exact PR head; all inputs and identifiers belong to the disposable fixture.

{
  "syntheticOnly": true,
  "head": "f1c01bab5aee2355881c3c33386d5b3a3ae9d63f",
  "transport": "Real Gateway + authenticated WebSocket RPC + loopback HTTP/OpenAI SDK; provider wire responses scripted; real read-tool filesystem I/O",
  "externalProviderContacted": false,
  "offlineFixtureSeeded": true,
  "gatewayReady": true,
  "authenticatedOwner": true,
  "preconditionArchivedTombstonedMain": true,
  "realGatewayResetSucceeded": true,
  "physicalIdentityRetained": true,
  "exactPriorMessageRetainedViaHistoryReopen": true,
  "newContextResetBoundaryVisible": true,
  "archiveAndTombstoneCleared": true,
  "actualProviderReadToolOffered": true,
  "actualReadReceiptReachedNextProviderRequest": true,
  "freshAuthenticatedTurnProviderFinal": true,
  "passed": true,
  "gatewayStopped": true,
  "providerStopped": true,
  "fixtureRemoved": true,
  "providerRequests": 2
}

Selected fields from its saved authenticated RPC responses follow. Unrelated response fields are omitted; values shown here are copied from the captures. The retained message is byte-for-byte equal to the pre-reset message, including its stored metadata (the harness checks the complete object).

{
  "sessions.describe before reset": {
    "key": "agent:main:main",
    "sessionId": "fc41aae2-e1bd-4b16-9d20-b095b9fee734",
    "archived": true,
    "restartRecoveryStatus": "tombstoned",
    "status": "failed"
  },
  "sessions.describe after reset": {
    "key": "agent:main:main",
    "sessionId": "fc41aae2-e1bd-4b16-9d20-b095b9fee734",
    "archived": false
  },
  "chat.history reopened retained message": {
    "role": "user",
    "content": "SYNTHETIC_RETAINED_HISTORY_3351"
  },
  "chat.history fresh tool result and final": [
    {
      "role": "toolResult",
      "content": [
        {
          "type": "text",
          "text": "SYNTHETIC_READ_RECEIPT_7264"
        }
      ]
    },
    {
      "role": "assistant",
      "content": [
        {
          "type": "text",
          "text": "SYNTHETIC_MAIN_RESET_USABLE_8429"
        }
      ],
      "stopReason": "stop"
    }
  ]
}

@clawsweeper

clawsweeper Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: S labels Oct 18, 2026
@enki
enki marked this pull request as ready for review October 18, 2026 05:14
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 18, 2026
@clawsweeper

clawsweeper Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge.

What this changes

Allows reset of canonical Main when restart recovery both archived and tombstoned it.

Example: An operator resets agent:main:main with archiveReason restart-recovery and a recovery tombstone.

  • Before: Reset refuses the session and recommends a replacement operation that cannot proceed.
  • After: Reset preserves the physical session identity and transcript, clears recovery state, and starts fresh model context.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Focused implementation and supplied Gateway proof support the change; readiness remains capped by the unresolved archive-policy decision.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): Captured authenticated Gateway sessions.reset and history responses on f1c01ba show preserved identity/history and cleared recovery metadata, followed by a completed fresh turn through real SDK transport and filesystem I/O with scripted loopback provider responses; the merged head retains the same eligibility change and supplies fresh owner-suite validation.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Needs a maintainer decision · Fix scope: Partial
User problem: Restart recovery can leave canonical Main unusable while the suggested reset operation refuses its archived state.
Reason: The bounded remedy has clear value, but it deliberately extends an archive policy retained by an earlier merged recovery change; the broader linked report remains only partially addressed.

Merge readiness

⛔ Blocked before merge - 1 item remains

Keep this PR open: it addresses a current recovery failure with a focused patch, but extending the deliberate archived-session reset restriction still needs an owner decision.

Priority: P1
Reviewed head: 794f1dc77381dd1c3bb3306fd22faf7610f69200
Owner decision: Required. See Decision needed.

Decision needed

  • Question: May an authorized reset restore canonical Main when restart recovery both archived and tombstoned it?
  • Recommendation: Allow the narrow reset exception: Accept this PR's canonical Main, restart-recovery archive, and tombstone conjunction through the existing reset owner.
  • Why: The previous recovery change deliberately retained archived-row refusal, and the contributor's verified rationale does not constitute owner approval to extend that policy.

Before merge

  • Resolve maintainer decision - Resolve the maintainer decision shown above before merge.

Findings

None.

Agent review details

How this fits together

Gateway session-reset requests enter the existing lifecycle owner, which checks authorization and session state before cleaning up runtimes and committing a transcript reset boundary.

flowchart TD
A[Operator reset request] --> B[Gateway authorization]
B --> C[Session reset owner]
C --> D[Recovery and archive eligibility]
D --> E[Runtime cleanup]
E --> F[SQLite reset boundary]
F --> G[Fresh authenticated turn]
Loading

Technical review

Best possible solution:

Approve the narrow existing-reset exception, preserving ordinary archive restrictions, transcript history, and fresh authorization.

Do we have a high-confidence way to reproduce the issue?

Current-main eligibility deterministically rejects an archived recovery tombstone; the linked incident and supplied before/after handler evidence corroborate that path, without a new run during this review.

Is this the best way to solve the issue?

The patch is the smallest complete reset remedy: it changes eligibility in the existing lifecycle owner and reuses canonical Main resolution, while leaving broader recovery presentation and successor behavior separate.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 3840d14ad2a3.

Provenance checked

  • Archived tombstone reset eligibility changes intended behavior with a stated reason (aa3fb33: The merged tombstone-fence repair preserved existing Gateway refusal of archived rows while allowing already-authorized replacement of unarchived tombstones.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 4a11f89 adds src/gateway/session-reset-service.ts:842 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 4a11f89e840b; files: src/gateway/session-reset-service.ts)

PR surface

Source +10, Tests +125. Total +135 across 2 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 11 1 +10
Tests 1 125 0 +125
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 136 1 +135

Labels

Label changes:

No label changes.

Label justifications:

  • P1: A reported production Main session cannot accept work, and current source confirms that the prescribed reset remedy rejects its recovery state.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Record the recovery owner's decision on the narrow archived-Main reset exception.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (3 earlier review cycles)
  • reviewed 2026-10-18T05:30:53.847Z sha f1c01ba :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-18T06:18:07.310Z sha f1c01ba :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-18T06:28:31.696Z sha f1c01ba :: blocked before merge. :: none

Reviewed October 18, 2026, 8:25 PM ET / October 19, 2026, 00:25 UTC (Revision 4).

@enki

enki commented Oct 18, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Added real isolated Gateway proof on unchanged head f1c01bab5aee: authenticated sessions.reset preserves Main’s physical identity and exact retained history, clears the restart archive/tombstone, and permits a fresh authenticated turn through the actual embedded runtime, HTTP/OpenAI SDK, and read-tool filesystem I/O. The returned file receipt reaches the second provider request and its correlated final completes. Provider frames are scripted on loopback; no external provider, private user data, or operator Gateway was used. Details and limits are now in the PR body. The narrow reset-policy decision still requires maintainer approval.

@clawsweeper

clawsweeper Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 18, 2026
@enki

enki commented Oct 18, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Addressed the new inspectability request: the body now embeds the captured synthetic run’s terminal output and selected actual authenticated RPC response fields for before/after reset, retained-history reopening, read-tool result, and completed assistant final. These are existing run captures on unchanged f1c01bab5aee, not another replay or a narrative-only claim. All shown identifiers/messages are disposable synthetic fixtures; private endpoints, paths and credentials are excluded. The HTTP/OpenAI SDK transport and real file read are explicit; provider response frames were scripted.

@steipete — the remaining product choice is whether canonical Main with a restart-recovery archive and tombstone should use the existing reset operation in place. Manual archives, non-Main archives and other refusals remain covered. Please review that narrow exception; no owner approval is assumed.

@clawsweeper

clawsweeper Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. labels Oct 18, 2026
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 18, 2026
@enki

enki commented Oct 18, 2026

Copy link
Copy Markdown
Contributor Author

Response to the behavior decision in the current review.

The body now answers the archived-Main reset question against #130196: keep the tombstone fence for ordinary work, while allowing the existing authorized reset owner its narrowly guarded Main exception. It acknowledges that archived-row refusal was deliberate and does not argue for general archive reopening.

Source-linked rationale and remaining choice.

@enki

enki commented Oct 19, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Conflicts are resolved at 794f1dc77381dd1c3bb3306fd22faf7610f69200 against pinned upstream 00575becc9fce53efc73b319a16fa71e6f4123b9. New-head CI is green; the PR body records fresh reset-cleanup tests, owner types, lint, and review, with prior runtime proof kept source-qualified. Please reassess the updated Behavior decision argument and current integration. The canonical-Main reset policy recommendation remains a maintainer decision, not claimed approval.

@clawsweeper

clawsweeper Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 19, 2026
@steipete

Copy link
Copy Markdown
Contributor

Thank you, @enki. Your design and credit are retained in the maintainer rewrite #176675, rebased onto the session-controller cutover. The rewrite route was used because the tooling cannot refresh unsigned incoming heads. Leaving this PR open for the lead's landing/closure decision.

steipete added a commit that referenced this pull request Oct 19, 2026
* fix(sessions): reset Main archived by restart recovery

Preserve the narrow reset policy and regression coverage from #176086 on current main. Extend the existing Gateway recovery boundary proof through recovery archival, explicit reset, and a fresh authenticated turn.

Co-authored-by: Paul Bohm <[email protected]>

* test(sessions): seed internal restart recovery metadata

Use the internal persisted entry contract for the Gateway recovery fixture.

Co-authored-by: Paul Bohm <[email protected]>

---------

Co-authored-by: Paul Bohm <[email protected]>
@steipete

Copy link
Copy Markdown
Contributor

Thank you @enki — this landed as #176675 (squash e522989), a maintainer rewrite of your change onto current main after the session-controller cutover, with you as co-author on the commit. It keeps your fix as written: an authorized reset can recover the canonical Main session after restart recovery archived it. Closing this one as landed via #176675.

@steipete steipete closed this Oct 19, 2026
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 20, 2026
* fix(sessions): reset Main archived by restart recovery

Preserve the narrow reset policy and regression coverage from openclaw#176086 on current main. Extend the existing Gateway recovery boundary proof through recovery archival, explicit reset, and a fresh authenticated turn.

Co-authored-by: Paul Bohm <[email protected]>

* test(sessions): seed internal restart recovery metadata

Use the internal persisted entry contract for the Gateway recovery fixture.

Co-authored-by: Paul Bohm <[email protected]>

---------

Co-authored-by: Paul Bohm <[email protected]>
RomneyDa added a commit that referenced this pull request Oct 22, 2026
* fix(sessions): reset Main archived by restart recovery

Preserve the narrow reset policy and regression coverage from #176086 on current main. Extend the existing Gateway recovery boundary proof through recovery archival, explicit reset, and a fresh authenticated turn.

Co-authored-by: Paul Bohm <[email protected]>

* test(sessions): seed internal restart recovery metadata

Use the internal persisted entry contract for the Gateway recovery fixture.

Co-authored-by: Paul Bohm <[email protected]>

---------

Co-authored-by: Paul Bohm <[email protected]>
(cherry picked from commit e522989)
Co-authored-by: RomneyDa <[email protected]>
RomneyDa pushed a commit that referenced this pull request Oct 27, 2026
* fix(sessions): reset Main archived by restart recovery

Preserve the narrow reset policy and regression coverage from #176086 on current main. Extend the existing Gateway recovery boundary proof through recovery archival, explicit reset, and a fresh authenticated turn.

Co-authored-by: Paul Bohm <[email protected]>

* test(sessions): seed internal restart recovery metadata

Use the internal persisted entry contract for the Gateway recovery fixture.

Co-authored-by: Paul Bohm <[email protected]>

---------

Co-authored-by: Paul Bohm <[email protected]>
(cherry picked from commit e522989)
Co-authored-by: RomneyDa <[email protected]>
(cherry picked from commit 4d61fc8)

Release adaptation: applied the 2026.10.7 adaptation; kept 2026.10.10's embeddedRunMock test import that the 10.7 hunk dropped.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. gateway Gateway runtime P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants