Skip to content

refactor(admission): drop the replay automationAdmin bit and the R7 source re-check - #205268

Merged
obviyus merged 2 commits into
mainfrom
refactor/oa2-scheduled-scope
Nov 25, 2026
Merged

obviyus merged 2 commits into
mainfrom
refactor/oa2-scheduled-scope

Conversation

@obviyus

@obviyus obviyus commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

OA2 PR 4e (DESIGN §4.7 and §4.12; the two steps #205173 split off). Two places still decided what a running scheduled turn may do outside admission:

  • Replay automationAdmin output. decideOperatorAdmission returned a second owner-like bit for replays: admin scope and a saved Control UI delegation. In-session scheduled runs (runCronSessionTurn) used it to decide whether the run carries its restored operator source and binds command-owner authority. Same admin, different answer depending on which client created the job.
  • R7 mid-run re-check (source_authority_refused). The prepared session target in attempt-session-target.ts re-ran the run's whole source assertion (operator access, policy grants, session-event config) on every transcript and context write during the run, and refused with source_authority_refused (REFUSALS R7, seen on Peanutto). Admission already checked that source once, at start.

Fix

  • automationAdmin is deleted from the admission decision, RestoredGatewayOperatorAuthority, ScheduledSessionAutomation and the participation path. An in-session scheduled run now binds command-owner authority iff its restored grant is owner (grant.owner), the same rule restart and owner continuations already use.
  • createPreparedSessionTargetAssertion no longer calls the run's source. It keeps the selected-target fence (attempt, session identity, target fields), Stop and the run lifetime (assertScopeCurrent), and the session row predicates still reach the writer through composeSessionSourceAssertion.
  • Pre-start session-event config check: no split code needed. The session-event config policy already stops at start(); before start, a config publication that denies the selected model is refused by the start's own model-policy check, before any provider request. The integration test now asserts that refusal instead of probing it through the prepared target.

Decisions (recorded, not asked)

  • Widening (same principal, same answer): an in-session scheduled run whose restored requester is an admin now binds command-owner authority even when the job was created outside the Control UI (remote CLI, TUI, native app). Same rule as refactor(gateway): decide automations rights once, as the turn grant #205173 for grant.automations.
  • Stored rows unchanged: the codec keeps writing/reading automationAdmin/controlUiAdmin on saved sources (no stored-row change); hasAutomationAdminDelegation keeps its two non-admission readers (cron-job-turn-target.ts, the control-edit refresh in cron-operator-source.ts).
  • Cut less: the automations-run-scope.ts trigger fallback stays. Every Gateway occurrence is admitted through admitScheduledOccurrence, but when that admission fails (status: "fail"), bind() binds no context and the run still starts. The fallback is then the only thing that keeps an unadmitted hook/event turn (no sender bit, owner surface) from getting the full automations tool, and a cron turn limited to its own job. Deleting it needs the failed occurrence to carry its scope from admission (or a refused start), which is a separate change. Found while running the pre-push set (the fallback's own suite asserts the unadmitted event case); I removed it on the first head, then restored it: not patched here.
  • Accepted edge (AGENTS.md "a started request may finish"): an operator whose access is revoked mid-run no longer has the run's transcript/context writes refused; Stop and the run lifetime still end it.

Tests

  • Deleted (assert removed behavior): run-attempt-dispatch.owner "policy" case (mid-run access-policy revoke → source_authority_refused); operator-run-recovery.native "preserves legacy browser grants…" (only asserted the deleted automationAdmin output).
  • Changed: run-attempt-dispatch.owner now applies each invalidation directly and asserts the prepared target never calls the run's source (red on base: base calls it once); "source-closed" refuses through the run lifetime (scope_authority_refused). run.operator-continuation and execution-context-owner-authority fixtures now admit occurrences / build the Codex host on the run's admitted context, as the Gateway does, so their scope comes from admission rather than the fallback.

Evidence

  • Production lines (src, non-test): +12 / −38 (net −26).
  • Red on base, green on head: run-attempt-dispatch.owner.test.ts invalidation cases now assert the prepared target never calls the run's source (assertSourceCurrent not called). On base the same case asserted it was called once (toHaveBeenCalledOnce), i.e. the R7 mid-run re-check.
  • Pre-start refusal kept: session-run.session-model-strictness.integration.test.ts "selected-model-denied": a config publication during target preparation that denies the selected model still ends the occurrence with status: "error", executionStarted: false and zero provider requests; the error now names the policy (Scheduled model "primary/model-a" is not allowed by agents.defaults.modelPolicy.allow…).
  • Scheduled scope: run.operator-continuation (36/36, incl. self-removal and next_check) and execution-context-owner-authority (embedded, Codex and CLI surfaces equal) pass with the fixtures admitting occurrences like the Gateway.
  • Pre-push: one ocx test call over 81 files (touched tests + importers of every changed source/test-support + every test constructing cron tools with trigger/jobId): all green on the first head; after restoring the fallback, the fallback's own suite and the affected files rerun green. pnpm tsgo:core and tsgo:test clean (also after rebase on 81d69df5dcea); oxfmt/oxlint clean on changed files.
  • E2E: Q/R/S on the exact head, see follow-up comment.

… source re-check

- Delete the trigger/jobId fallback in automations-run-scope.ts; the admitted
  occurrence context owns a scheduled run's job scope.
- Delete the replay automationAdmin output; an in-session scheduled run binds
  command-owner authority from its restored grant.owner.
- The prepared session target no longer re-runs the run's source mid-run
  (source_authority_refused); target, Stop and run-lifetime fences stay.

Co-authored-by: obviyus <[email protected]>
@clawsweeper

clawsweeper Bot commented Nov 25, 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 scripts Repository scripts agents Agent runtime and tooling size: M labels Nov 25, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. impact:auth-provider Auth, provider routing, model choice, or SecretRef resolution may break. impact:session-state Session, memory, transcript, context, or agent state can drift or corrupt. labels Nov 25, 2026
@obviyus

obviyus commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator Author

E2E on exact head 75ac48d68d24 (one-admission journey, isolated Gateway from source, real model through a byte-forwarding relay):

Case Result
Q. revoke while queued → refused visibly pass
R. revoke while running → run finishes pass
S. Stop → cancels pass

verdict.json:

[{"id":"R.running-turn-finishes","pass":true},{"id":"Q.queued-input-refused-visibly","pass":true},{"id":"S.stop-cancels","pass":true}]

results.jsonl: 28 records (kept with the PR worker proof).

Local review on the same head: complete, "patch is correct", no findings.

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 25, 2026
…scheduled runs

A failed occurrence admission binds no context and the run still starts; the fallback is the only limit for that case until admission carries it.

Co-authored-by: obviyus <[email protected]>
@obviyus obviyus changed the title refactor(admission): scheduled scope from admission only; drop the R7 source re-check refactor(admission): drop the replay automationAdmin bit and the R7 source re-check Nov 25, 2026
@obviyus

obviyus commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator Author

E2E on exact head 4cddd31e0f21 (same journey): Q revoke-while-queued refused visibly: pass; R revoke-while-running finishes: pass; S Stop cancels: pass.

[{"id":"R.running-turn-finishes","pass":true},{"id":"Q.queued-input-refused-visibly","pass":true},{"id":"S.stop-cancels","pass":true}]

Local review on this head: complete, "patch is correct", no findings. This head restores the automations-run-scope.ts trigger fallback (cut less; see the PR body).

@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 25, 2026
@clawsweeper

clawsweeper Bot commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR removes replay-specific administrator classification and stops rechecking requester policy during prepared transcript and context writes.

Example: An admitted scheduled turn loses operator access while generating its response.

  • Before: A subsequent prepared write can fail with source_authority_refused.
  • After: The admitted turn can finish while Stop, run lifetime, and selected-target fences remain enforced.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The patch is focused and source-consistent, with useful live lifecycle evidence and incomplete coverage of the scheduled permission change.
Proof confidence 🦐 gold shrimp (3/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Refactor · Worth it: Yes · Fix scope: Complete
User problem: Scheduled administrator permissions depend on the creating client, and requester-policy changes can interrupt writes belonging to an already admitted turn.
Reason: The maintainer-authored direction matches the repository's start-time admission contract and removes duplicate permission decisions without adding configuration or persistent state.

Merge readiness

✅ Ready for maintainer review

Keep open: this maintainer-directed simplification preserves admission as the permission owner, and no concrete introduced correctness or security defect was found.

Reviewed head: 4cddd31e0f21ac86791e987cef457c23f07a03f4

Before merge

None.

Findings

None.

Tests

  • Low-value test src/agents/embedded-agent-runner/run/run-attempt-dispatch.owner.test.ts: Remove the repeated mock call-count assertion that assertSourceCurrent was not called; retain the table's distinct lifetime, target, Stop, and restart outcomes.
  • Missing end-to-end proof: Show a real Gateway scheduled session turn created by a non-UI administrator retaining owner command authority, with a non-owner control; provide redacted terminal output or logs without credentials, IPs, or non-public endpoints.
Agent review details

How this fits together

Gateway admission restores requester facts into a frozen turn grant; scheduled session turns consume that grant, and prepared write assertions preserve the run's lifetime and destination.

flowchart TD
  A[Saved requester source] --> B[Operator admission]
  B --> C[Frozen turn grant]
  C --> D[Scheduled session turn]
  D --> E[Prepared target and lifetime fences]
  E --> F[Transcript and context writers]
Loading

Technical review

Best possible solution:

Keep admission authoritative, consume grant.owner for scheduled owner binding, and preserve the existing target, storage, cancellation, and occurrence fences.

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

Fetched-main source directly shows both the saved UI-delegation requirement and the repeated source assertion; no target code was executed during this read-only review.

Is this the best way to solve the issue?

The patch is a small, coherent cutover to existing admission and lifetime owners, and retaining the trigger fallback is justified by the documented failed-admission path.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 485c7dcac255.

Provenance checked

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Ayaan Zaidi: Raw commit 5e3065e adds src/gateway/operator-admission.ts:239 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 5e3065e10d09; files: src/gateway/operator-admission.ts)

PR surface

Source -26, Tests -93. Total -119 across 14 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 7 12 38 -26
Tests 7 57 150 -93
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 14 69 188 -119

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Labels

Label changes:

  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rank-up moves

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

  • Supply the scheduled administrator and non-owner behavior evidence described in the proof assessment.

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.

Reviewed November 25, 2026, 5:38 AM ET / 10:38 UTC.

@obviyus
obviyus merged commit ca087d4 into main Nov 25, 2026
147 of 150 checks passed
@obviyus
obviyus deleted the refactor/oa2-scheduled-scope branch November 25, 2026 10:48
@obviyus

obviyus commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator Author

Landed as ca087d4.

  • Removed: the replay automationAdmin decision output (in-session scheduled runs now bind command-owner authority from the restored grant.owner) and the R7 mid-run source re-check in the prepared session target (source_authority_refused).
  • Kept (cut less): the automations-run-scope.ts trigger fallback, because a scheduled run whose occurrence admission fails still starts without a context. Removing it needs the failed occurrence to carry its scope from admission.
  • Proof: CI green on 4cddd31e0f21. Local review is clean on both heads. E2E Q, R and S pass on both heads. The owner dispatch test shows the prepared target no longer calls the run's source.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 26, 2026
…ource re-check (openclaw#205268)

## Problem

OA2 PR 4e (DESIGN §4.7 and §4.12; the two steps openclaw#205173 split off). Two places still decided what a running scheduled turn may do outside admission:

- **Replay `automationAdmin` output.** `decideOperatorAdmission` returned a second owner-like bit for replays: admin scope **and** a saved Control UI delegation. In-session scheduled runs (`runCronSessionTurn`) used it to decide whether the run carries its restored operator source and binds command-owner authority. Same admin, different answer depending on which client created the job.
- **R7 mid-run re-check (`source_authority_refused`).** The prepared session target in `attempt-session-target.ts` re-ran the run's whole source assertion (operator access, policy grants, session-event config) on every transcript and context write during the run, and refused with `source_authority_refused` (REFUSALS R7, seen on Peanutto). Admission already checked that source once, at start.

## Fix

- `automationAdmin` is deleted from the admission decision, `RestoredGatewayOperatorAuthority`, `ScheduledSessionAutomation` and the participation path. An in-session scheduled run now binds command-owner authority iff its restored grant is owner (`grant.owner`), the same rule restart and owner continuations already use.
- `createPreparedSessionTargetAssertion` no longer calls the run's source. It keeps the selected-target fence (attempt, session identity, target fields), Stop and the run lifetime (`assertScopeCurrent`), and the session row predicates still reach the writer through `composeSessionSourceAssertion`.
- **Pre-start session-event config check:** no split code needed. The session-event config policy already stops at `start()`; before start, a config publication that denies the selected model is refused by the start's own model-policy check, before any provider request. The integration test now asserts that refusal instead of probing it through the prepared target.

## Decisions (recorded, not asked)

- **Widening (same principal, same answer):** an in-session scheduled run whose restored requester is an admin now binds command-owner authority even when the job was created outside the Control UI (remote CLI, TUI, native app). Same rule as openclaw#205173 for `grant.automations`.
- **Stored rows unchanged:** the codec keeps writing/reading `automationAdmin`/`controlUiAdmin` on saved sources (no stored-row change); `hasAutomationAdminDelegation` keeps its two non-admission readers (`cron-job-turn-target.ts`, the control-edit refresh in `cron-operator-source.ts`).
- **Cut less: the `automations-run-scope.ts` trigger fallback stays.** Every Gateway occurrence is admitted through `admitScheduledOccurrence`, but when that admission fails (`status: "fail"`), `bind()` binds no context and the run still starts. The fallback is then the only thing that keeps an unadmitted hook/event turn (no sender bit, owner surface) from getting the full automations tool, and a cron turn limited to its own job. Deleting it needs the failed occurrence to carry its scope from admission (or a refused start), which is a separate change. Found while running the pre-push set (the fallback's own suite asserts the unadmitted event case); I removed it on the first head, then restored it: not patched here.
- **Accepted edge (AGENTS.md "a started request may finish"):** an operator whose access is revoked mid-run no longer has the run's transcript/context writes refused; Stop and the run lifetime still end it.

## Tests

- Deleted (assert removed behavior): `run-attempt-dispatch.owner` "policy" case (mid-run access-policy revoke → `source_authority_refused`); `operator-run-recovery.native` "preserves legacy browser grants…" (only asserted the deleted `automationAdmin` output).
- Changed: `run-attempt-dispatch.owner` now applies each invalidation directly and asserts the prepared target never calls the run's source (red on base: base calls it once); "source-closed" refuses through the run lifetime (`scope_authority_refused`). `run.operator-continuation` and `execution-context-owner-authority` fixtures now admit occurrences / build the Codex host on the run's admitted context, as the Gateway does, so their scope comes from admission rather than the fallback.

## Evidence

- **Production lines** (`src`, non-test): +12 / −38 (net −26).
- **Red on base, green on head:** `run-attempt-dispatch.owner.test.ts` invalidation cases now assert the prepared target never calls the run's source (`assertSourceCurrent` not called). On base the same case asserted it was called once (`toHaveBeenCalledOnce`), i.e. the R7 mid-run re-check.
- **Pre-start refusal kept:** `session-run.session-model-strictness.integration.test.ts` "selected-model-denied": a config publication during target preparation that denies the selected model still ends the occurrence with `status: "error"`, `executionStarted: false` and zero provider requests; the error now names the policy (`Scheduled model "primary/model-a" is not allowed by agents.defaults.modelPolicy.allow…`).
- **Scheduled scope:** `run.operator-continuation` (36/36, incl. self-removal and `next_check`) and `execution-context-owner-authority` (embedded, Codex and CLI surfaces equal) pass with the fixtures admitting occurrences like the Gateway.
- **Pre-push:** one `ocx test` call over 81 files (touched tests + importers of every changed source/test-support + every test constructing cron tools with `trigger`/`jobId`): all green on the first head; after restoring the fallback, the fallback's own suite and the affected files rerun green. `pnpm tsgo:core` and `tsgo:test` clean (also after rebase on `5279ca48bbe1`); oxfmt/oxlint clean on changed files.
- **E2E:** Q/R/S pass on both heads (`75ac48d68d24`, `4cddd31e0f21`); see the PR comments.

Co-authored-by: Ayaan Zaidi <[email protected]>
obviyus added a commit that referenced this pull request Nov 29, 2026
…207947)

## Problem

A started cron turn died when someone edited its job. Daily refusal watch, 2026-11-28:

```
[gateway] cron: job updated
[agent/embedded] session target preparation refused reason=scope_authority_refused
lane task error: lane=cron-nested durationMs=36667 error="Session target preparation outlived its attempt | This agent run is no longer active. Start a new turn to retry. | Automation operator source changed"
```

`captureCronJobTurnTarget` (`src/gateway/cron-job-turn-target.ts`) gave the session event target an `assertCurrent` that re-read the job on every fence check. It compared the stored `operatorSource` (or the scheduled requester) with the value captured at start. `cron.update` changes that value, so the next fence check threw. The run's `assertScopeCurrent` turned it into `scope_authority_refused`. The cron notice and failure-repair turns use this target. A repair turn that fixes its own job killed itself.

Root `AGENTS.md` "Decide authority once" does not allow this: authority is checked once, when work starts. The only stop after start is a permission writer stopping a named person's work. Editing a job is neither. This is the same class as R7 `source_authority_refused` (removed in #205268).

## Change

- Remove both job re-reads from `captureCronJobTurnTarget`: the operator-source comparison ("Automation operator source changed") and the scheduled-requester comparison ("Automation requester changed.").
- The edited source applies from the next occurrence. Admission at that start decides it.
- Kept: admission at start, data fences (attempt lifecycle, session identity, target fields), the run abort signal, and the cron remove/disable cancellation (active-job marker → run `AbortController`).
- `scope_authority_refused` stays. The run-registry binding (`source-closed`) still produces it. `scripts/lib/no-operator-permission-read.mjs` lists no removed site.

## What the user sees

A cron notice or repair turn finishes after the job is edited. Before, it failed with "This agent run is no longer active. Start a new turn to retry."

## Evidence

- New test `keeps a started cron turn running when its job is edited` (`src/gateway/operator-run-recovery.effects.test.ts`). It uses the real `CronService`, `captureCronJobTurnTarget` and `prepareSessionEventTargetForHost`, then edits the stored job's `operatorSource`.
  - Base `848732ff`: red, `Error: Automation operator source changed`.
  - Head: green.
- `ocx test` on the four test files that import `cron-job-turn-target.ts`: 35/35 pass.
- `pnpm check:changed`: typecheck, lint, format and guards pass. The dead-export scan fails on base-only entries (`AgentCommandPluginIngressOpts`, `clearNativeRepositorySourceModulesForTest`, `resolveUpdateInstallSurfaceMock`). None of them are in this diff.
- Live Gateway E2E (isolated Gateway, real `openai/gpt-5.5`, scratch state). Steps: the agent creates a cron job from chat with a 3 s timeout. `cron.run` fails, and the failure-repair turn starts in the owner session. The repair turn calls the cron tool to set `timeoutSeconds: 120` (`cron.update`), then runs one more `exec` and replies.
  - Base `848732ff`: the job edit lands, then the repair turn ends `state: error` with `Session target preparation outlived its attempt | This agent run is no longer active. Start a new turn to retry. | Automation operator source changed`. The Gateway log has `scope_authority_refused`. This is the incident.
  - Head `4d50bb57`: the job edit lands and the repair turn ends `state: final`. The log has no `scope_authority_refused`.
- One-admission E2E Q/R/S on head `4d50bb57`: all PASS. Revoking access while work is queued refuses it visibly, revoking access while a turn runs stops it (`access-reduced`), and Stop cancels the turn.

Production: −18/+6 lines. Test: +56/−1.

Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 29, 2026
…penclaw#207947)

## Problem

A started cron turn died when someone edited its job. Daily refusal watch, 2026-11-28:

```
[gateway] cron: job updated
[agent/embedded] session target preparation refused reason=scope_authority_refused
lane task error: lane=cron-nested durationMs=36667 error="Session target preparation outlived its attempt | This agent run is no longer active. Start a new turn to retry. | Automation operator source changed"
```

`captureCronJobTurnTarget` (`src/gateway/cron-job-turn-target.ts`) gave the session event target an `assertCurrent` that re-read the job on every fence check. It compared the stored `operatorSource` (or the scheduled requester) with the value captured at start. `cron.update` changes that value, so the next fence check threw. The run's `assertScopeCurrent` turned it into `scope_authority_refused`. The cron notice and failure-repair turns use this target. A repair turn that fixes its own job killed itself.

Root `AGENTS.md` "Decide authority once" does not allow this: authority is checked once, when work starts. The only stop after start is a permission writer stopping a named person's work. Editing a job is neither. This is the same class as R7 `source_authority_refused` (removed in openclaw#205268).

## Change

- Remove both job re-reads from `captureCronJobTurnTarget`: the operator-source comparison ("Automation operator source changed") and the scheduled-requester comparison ("Automation requester changed.").
- The edited source applies from the next occurrence. Admission at that start decides it.
- Kept: admission at start, data fences (attempt lifecycle, session identity, target fields), the run abort signal, and the cron remove/disable cancellation (active-job marker → run `AbortController`).
- `scope_authority_refused` stays. The run-registry binding (`source-closed`) still produces it. `scripts/lib/no-operator-permission-read.mjs` lists no removed site.

## What the user sees

A cron notice or repair turn finishes after the job is edited. Before, it failed with "This agent run is no longer active. Start a new turn to retry."

## Evidence

- New test `keeps a started cron turn running when its job is edited` (`src/gateway/operator-run-recovery.effects.test.ts`). It uses the real `CronService`, `captureCronJobTurnTarget` and `prepareSessionEventTargetForHost`, then edits the stored job's `operatorSource`.
  - Base `9e839f97`: red, `Error: Automation operator source changed`.
  - Head: green.
- `ocx test` on the four test files that import `cron-job-turn-target.ts`: 35/35 pass.
- `pnpm check:changed`: typecheck, lint, format and guards pass. The dead-export scan fails on base-only entries (`AgentCommandPluginIngressOpts`, `clearNativeRepositorySourceModulesForTest`, `resolveUpdateInstallSurfaceMock`). None of them are in this diff.
- Live Gateway E2E (isolated Gateway, real `openai/gpt-5.5`, scratch state). Steps: the agent creates a cron job from chat with a 3 s timeout. `cron.run` fails, and the failure-repair turn starts in the owner session. The repair turn calls the cron tool to set `timeoutSeconds: 120` (`cron.update`), then runs one more `exec` and replies.
  - Base `9e839f97`: the job edit lands, then the repair turn ends `state: error` with `Session target preparation outlived its attempt | This agent run is no longer active. Start a new turn to retry. | Automation operator source changed`. The Gateway log has `scope_authority_refused`. This is the incident.
  - Head `4d50bb57`: the job edit lands and the repair turn ends `state: final`. The log has no `scope_authority_refused`.
- One-admission E2E Q/R/S on head `4d50bb57`: all PASS. Revoking access while work is queued refuses it visibly, revoking access while a turn runs stops it (`access-reduced`), and Stop cancels the turn.

Production: −18/+6 lines. Test: +56/−1.

Co-authored-by: Ayaan Zaidi <[email protected]>
tideclaw-bot pushed a commit that referenced this pull request Nov 29, 2026
…207947)

## Problem

A started cron turn died when someone edited its job. Daily refusal watch, 2026-11-28:

```
[gateway] cron: job updated
[agent/embedded] session target preparation refused reason=scope_authority_refused
lane task error: lane=cron-nested durationMs=36667 error="Session target preparation outlived its attempt | This agent run is no longer active. Start a new turn to retry. | Automation operator source changed"
```

`captureCronJobTurnTarget` (`src/gateway/cron-job-turn-target.ts`) gave the session event target an `assertCurrent` that re-read the job on every fence check. It compared the stored `operatorSource` (or the scheduled requester) with the value captured at start. `cron.update` changes that value, so the next fence check threw. The run's `assertScopeCurrent` turned it into `scope_authority_refused`. The cron notice and failure-repair turns use this target. A repair turn that fixes its own job killed itself.

Root `AGENTS.md` "Decide authority once" does not allow this: authority is checked once, when work starts. The only stop after start is a permission writer stopping a named person's work. Editing a job is neither. This is the same class as R7 `source_authority_refused` (removed in #205268).

## Change

- Remove both job re-reads from `captureCronJobTurnTarget`: the operator-source comparison ("Automation operator source changed") and the scheduled-requester comparison ("Automation requester changed.").
- The edited source applies from the next occurrence. Admission at that start decides it.
- Kept: admission at start, data fences (attempt lifecycle, session identity, target fields), the run abort signal, and the cron remove/disable cancellation (active-job marker → run `AbortController`).
- `scope_authority_refused` stays. The run-registry binding (`source-closed`) still produces it. `scripts/lib/no-operator-permission-read.mjs` lists no removed site.

## What the user sees

A cron notice or repair turn finishes after the job is edited. Before, it failed with "This agent run is no longer active. Start a new turn to retry."

## Evidence

- New test `keeps a started cron turn running when its job is edited` (`src/gateway/operator-run-recovery.effects.test.ts`). It uses the real `CronService`, `captureCronJobTurnTarget` and `prepareSessionEventTargetForHost`, then edits the stored job's `operatorSource`.
  - Base `848732ff`: red, `Error: Automation operator source changed`.
  - Head: green.
- `ocx test` on the four test files that import `cron-job-turn-target.ts`: 35/35 pass.
- `pnpm check:changed`: typecheck, lint, format and guards pass. The dead-export scan fails on base-only entries (`AgentCommandPluginIngressOpts`, `clearNativeRepositorySourceModulesForTest`, `resolveUpdateInstallSurfaceMock`). None of them are in this diff.
- Live Gateway E2E (isolated Gateway, real `openai/gpt-5.5`, scratch state). Steps: the agent creates a cron job from chat with a 3 s timeout. `cron.run` fails, and the failure-repair turn starts in the owner session. The repair turn calls the cron tool to set `timeoutSeconds: 120` (`cron.update`), then runs one more `exec` and replies.
  - Base `848732ff`: the job edit lands, then the repair turn ends `state: error` with `Session target preparation outlived its attempt | This agent run is no longer active. Start a new turn to retry. | Automation operator source changed`. The Gateway log has `scope_authority_refused`. This is the incident.
  - Head `4d50bb57`: the job edit lands and the repair turn ends `state: final`. The log has no `scope_authority_refused`.
- One-admission E2E Q/R/S on head `4d50bb57`: all PASS. Revoking access while work is queued refuses it visibly, revoking access while a turn runs stops it (`access-reduced`), and Stop cancels the turn.

Production: −18/+6 lines. Test: +56/−1.

Co-authored-by: Ayaan Zaidi <[email protected]>

(cherry picked from commit 7895017)

Release adaptation: Remove the mutable job-source assertions while retaining beta.2 requesterOwner and delegated ownerContinuation option shapes; preserve the existing source-conversation fence.

Co-authored-by: RomneyDa <[email protected]>
tideclaw-bot pushed a commit that referenced this pull request Nov 30, 2026
…chiving (#205026)

* fix(sessions): keep inactive chats eligible for cold storage after archiving

* test(sessions): align archive fixtures and identity baseline

* test(sessions): create a private cold backup restore target

(cherry picked from commit 81d69df)

Follow-ups: 7cb8975 fix: keep forked Claude chats separate after a Gateway crash (#208048) [separately ordered lane row]; ece7a74 improve(workboard): apply the Control UI glossary and style to Workboard copy [not selected for this narrow backport]; b616036 refactor(subagents): simplify ACP spawn relay ownership (#207023) [not selected for this narrow backport]; 93ca762 improve: reduce allocations when preparing session rows (#207109) [not selected for this narrow backport]; 9993328 refactor(subagents): simplify kill claim and ownership handling (#207025) [not selected for this narrow backport]; 97815bd refactor(subagents): consolidate registry cleanup and publication guards (#207064) [not selected for this narrow backport]; e94f799 refactor(subagents): centralize requester turn matching (#206584) [not selected for this narrow backport]; ea77ca3 refactor: report update failures from recorded runs (#206700) [not selected for this narrow backport]; 4d7e00b fix: let started participant runs and requests finish after an access change (#206747) [not selected for this narrow backport]; f89ae43 refactor(subagents): use cleanup and terminal owners in sweeps (#206533) [not selected for this narrow backport]; a882e0f fix(agents): preserve task answers when sessions are reused (#126263) [not selected for this narrow backport]; 81fc833 refactor(subagents): own dormant child Stop decisions (#206479) [not selected for this narrow backport]; 91d4912 fix(update): stop using foreign recovery records as admission (#206295) [not selected for this narrow backport]; be3c73e fix(subagents): finish claimed stops after session rotation (#206405) [not selected for this narrow backport]; ed8b883 fix(update): settle after plugins and share one completion summary (#205987) [not selected for this narrow backport]; 1de306e fix: pause interrupted shell turns when their result is unknown (#205859) [separately ordered lane row]; 16a6aa4 fix(memory): keep a child's memory audience after its parent resets (#205887) [not selected for this narrow backport]; 50a7368 feat: let agents snooze a conversation after replying [not selected for this narrow backport]; 40f3903 fix(ci): remove unused role and workflow exports (#205720) [not selected for this narrow backport]; e43debf refactor(state): migrate in place and remove copy-and-swap (#205165) [not selected for this narrow backport]; 8027293 refactor(plugins): plugin tools take the turn's owner bit; delete the requester-owner continuation (OA2 PR 6j) (#205483) [not selected for this narrow backport]; 13e2ec3 feat: let participants publish through the session's shared GitHub account (#204914) [not selected for this narrow backport]; 5434992 fix: use the configured runtime when switching model providers (#203973) [not selected for this narrow backport]; 5271519 fix(feishu): honor the filename override on sent attachments (#205287) [not selected for this narrow backport]; ca087d4 refactor(admission): drop the replay automationAdmin bit and the R7 source re-check (#205268) [not selected for this narrow backport]

Co-authored-by: RomneyDa <[email protected]>
tideclaw-bot pushed a commit that referenced this pull request Nov 30, 2026
…207947)

A started cron turn died when someone edited its job. Daily refusal watch, 2026-11-28:

```
[gateway] cron: job updated
[agent/embedded] session target preparation refused reason=scope_authority_refused
lane task error: lane=cron-nested durationMs=36667 error="Session target preparation outlived its attempt | This agent run is no longer active. Start a new turn to retry. | Automation operator source changed"
```

`captureCronJobTurnTarget` (`src/gateway/cron-job-turn-target.ts`) gave the session event target an `assertCurrent` that re-read the job on every fence check. It compared the stored `operatorSource` (or the scheduled requester) with the value captured at start. `cron.update` changes that value, so the next fence check threw. The run's `assertScopeCurrent` turned it into `scope_authority_refused`. The cron notice and failure-repair turns use this target. A repair turn that fixes its own job killed itself.

Root `AGENTS.md` "Decide authority once" does not allow this: authority is checked once, when work starts. The only stop after start is a permission writer stopping a named person's work. Editing a job is neither. This is the same class as R7 `source_authority_refused` (removed in #205268).

- Remove both job re-reads from `captureCronJobTurnTarget`: the operator-source comparison ("Automation operator source changed") and the scheduled-requester comparison ("Automation requester changed.").
- The edited source applies from the next occurrence. Admission at that start decides it.
- Kept: admission at start, data fences (attempt lifecycle, session identity, target fields), the run abort signal, and the cron remove/disable cancellation (active-job marker → run `AbortController`).
- `scope_authority_refused` stays. The run-registry binding (`source-closed`) still produces it. `scripts/lib/no-operator-permission-read.mjs` lists no removed site.

A cron notice or repair turn finishes after the job is edited. Before, it failed with "This agent run is no longer active. Start a new turn to retry."

- New test `keeps a started cron turn running when its job is edited` (`src/gateway/operator-run-recovery.effects.test.ts`). It uses the real `CronService`, `captureCronJobTurnTarget` and `prepareSessionEventTargetForHost`, then edits the stored job's `operatorSource`.
  - Base `848732ff`: red, `Error: Automation operator source changed`.
  - Head: green.
- `ocx test` on the four test files that import `cron-job-turn-target.ts`: 35/35 pass.
- `pnpm check:changed`: typecheck, lint, format and guards pass. The dead-export scan fails on base-only entries (`AgentCommandPluginIngressOpts`, `clearNativeRepositorySourceModulesForTest`, `resolveUpdateInstallSurfaceMock`). None of them are in this diff.
- Live Gateway E2E (isolated Gateway, real `openai/gpt-5.5`, scratch state). Steps: the agent creates a cron job from chat with a 3 s timeout. `cron.run` fails, and the failure-repair turn starts in the owner session. The repair turn calls the cron tool to set `timeoutSeconds: 120` (`cron.update`), then runs one more `exec` and replies.
  - Base `848732ff`: the job edit lands, then the repair turn ends `state: error` with `Session target preparation outlived its attempt | This agent run is no longer active. Start a new turn to retry. | Automation operator source changed`. The Gateway log has `scope_authority_refused`. This is the incident.
  - Head `4d50bb57`: the job edit lands and the repair turn ends `state: final`. The log has no `scope_authority_refused`.
- One-admission E2E Q/R/S on head `4d50bb57`: all PASS. Revoking access while work is queued refuses it visibly, revoking access while a turn runs stops it (`access-reduced`), and Stop cancels the turn.

Production: −18/+6 lines. Test: +56/−1.

Co-authored-by: Ayaan Zaidi <[email protected]>
(cherry picked from commit 7895017)

Release adaptation: Replace the stable restored source snapshot equality assertion with the job-incarnation fence, retaining the revoked-device and profile checks and stable target ownership. Prove edits and removal against admitted repair target and authority.

Companion audit: 213f9b9 applied immediately before this source; no other required companions.

Co-authored-by: RomneyDa <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling gateway Gateway runtime impact:auth-provider Auth, provider routing, model choice, or SecretRef resolution may break. impact:session-state Session, memory, transcript, context, or agent state can drift or corrupt. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. scripts Repository scripts size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant