Skip to content

fix: let the oldest automations read their conversation's memory - #208190

Merged
obviyus merged 1 commit into
mainfrom
fix/cron-legacy-sessionkey-memory
Nov 29, 2026
Merged

obviyus merged 1 commit into
mainfrom
fix/cron-legacy-sessionkey-memory

Conversation

@obviyus

@obviyus obviyus commented Nov 29, 2026

Copy link
Copy Markdown
Collaborator

What Problem This Solves

Follow-up to #208143. Some automations were created before OpenClaw recorded owner. These jobs record their creating conversation only as the job's top-level sessionKey: no owner, no scheduledToolPolicy, no sourceConversation. resolveScheduledPrincipal ignored that field, so it classified the jobs as operator (unlinked-legacy). Their runs got no memory, but they still held legacy owner authority. Every knowledge_* call failed, and the Gateway logged:

memory audience unavailable: root session agent:main:cron:<job>:run:<run> has no durable chat type

A production job hit this on every daily run. It was created by the agent in a Telegram group: sessionTarget: "isolated", agentTurn, toolsAllow includes knowledge_grep/knowledge_record, callerOrigin: unknown.

User Impact

  • A detached (isolated / current) job that names its conversation only by top-level sessionKey now reads that conversation's current memory. fix: let older automations read their conversation's memory #208143 gave key-only jobs the same path:
    • created in a group or channel: only that conversation's memory;
    • created in the owner's direct chat: the owner's private memory.
  • Unchanged for these jobs: placement stays detached, authority stays legacy owner, the automations scope stays self, and board, workspace, sandbox and event target stay the run's own. If the conversation row is gone or archived, the run keeps going as before, with no memory.
  • These jobs are now unbound-parent. As a result, automations bind accepts them, and Doctor lists them under "not bound … recorded by key only" instead of skipping them. This is intended.
  • Unchanged: jobs with a trusted policy, and jobs that run inside a session (main, session:<key>). For these, the top-level sessionKey is the run's own lane, not a creating conversation. The setup-created proactive job (session:<main> + sessionKey) and heartbeat monitors migrated to session:<key> stay operator, so Doctor does not report them as unbound.
  • cron.add --session-key from an operator, for a session that does not exist yet, still stores a top-level sessionKey with no owner or sourceConversation. Such a job now reads that session's memory once the session exists. An authenticated operator linked that session, and the run already holds operator/owner authority, so the memory matches. If the session exists when the job is created, cron.add already captures sourceConversation, and nothing changes.

Accepted edge case: a heartbeat monitor that Doctor migrated with heartbeat.isolatedSession: true is isolated with sessionKey set to the heartbeat session. It now reads that session's memory, and Doctor lists it as unbound. The run already holds legacy owner authority.

Why This Change Was Made

Only one owner changes: resolveScheduledPrincipal (src/cron/execution-context.ts). The key-only fallback now ends with the legacy key: policy.ownerSessionKey ?? owner.sessionKey ?? job.sessionKey. The legacy key is used only when the job runs in its own session, and never with a trusted policy. No new state, flag or source kind.

Readers checked:

  • scheduledParentKeyOf (admission, Doctor access review, development replay) derives the key from resolveScheduledPrincipal, so the runtime, Doctor and the replay read the same row without edits.
  • resolveCronBindParent / cron-bind: these jobs become bindable (unbound-parent). main stays refused.
  • Doctor execution-context-report: these jobs move from no listing to unbound. missingChatType already keys on memory.source === "parent".
  • session-automation-index reads only parent, so it is unchanged.
  • execution-context-projection: no principal-kind branch except ingress.
  • The other job.sessionKey readers (delivery, wake lane, current run keys, visibility) do not change.

Evidence

Tests through the existing real-admission harness. Base 2fca213d312c: 3 failed. Head: all pass.

  • execution-context-memory-audience.test.ts (real admission → registry → embedded and CLI resolvers): a legacy group sessionKey job gets only that group's conversation partition. A legacy owner-direct sessionKey job gets owner-private. trusted policy, sessionTarget: main and session:<key> stay without memory (these pass on base too).
  • execution-context.test.ts: the legacy key gives unbound-parent with detached placement, legacy owner authority and self automations scope. In-session, it stays operator/unlinked-legacy.

Local: the 49 test files that import the changed source, bind-parent, admission, the registry, the projection or the Doctor report all passed (ocx test, 10 shards). Also ran oxfmt and pnpm check:changed (see below).

End to end, on a scratch Gateway from source with plugins.slots.memory: "knowledge" and a real model (openai/gpt-5.5). One real chat.send created a scratch conversation, and its row was set to chatType: "group". A job was created with automations add and edited into the production shape: agentId: main, top-level sessionKey = that conversation, sessionTarget: isolated, the same toolsAllow, toolsAllowProvenance.callerOrigin.kind: unknown, and no owner / scheduledToolPolicy / sourceConversation. It fired from its own at schedule (no forced run).

Base (2fca213d312c):

[agent/embedded] memory audience unavailable: root session agent:main:cron:<job>:run:<run> has no durable chat type
Knowledge access unavailable: "the host granted this session no memory audience"

Head: no memory audience unavailable line in the Gateway log. The run's result:

knowledge_grep("manifestation") returned 0 hits.

Merge danger: two-way door. No schema, stored-row, config or protocol change. A revert restores the previous classification. Blast radius: detached jobs with a top-level sessionKey and no sourceConversation, owner.sessionKey or account-policy key.

…'s memory

Jobs saved before `owner` existed record their creating conversation only as top-level `sessionKey`. resolveScheduledPrincipal ignored it and classified them operator (unlinked-legacy), so their runs got no memory while holding legacy owner authority.

The key-only fallback now ends with the top-level key for jobs that run in their own session (not `main` or `session:<key>`, where that key is the run's own lane), still never with a trusted policy. Those jobs become unbound-parent and read their conversation's memory through the #208143 path; placement, authority and automations scope do not change.

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

clawsweeper Bot commented Nov 29, 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.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation size: S labels Nov 29, 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. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Nov 29, 2026
@obviyus
obviyus merged commit 03cdb2c into main Nov 29, 2026
129 checks passed
@obviyus
obviyus deleted the fix/cron-legacy-sessionkey-memory branch November 29, 2026 09:39
@obviyus

obviyus commented Nov 29, 2026

Copy link
Copy Markdown
Collaborator Author

Landed in 03cdb2c.

  • Bug: automations saved before owner existed record their conversation only as top-level sessionKey. They were classified operator, so every run got no memory (memory audience unavailable … has no durable chat type) while it still held legacy owner authority.
  • Fix: resolveScheduledPrincipal now uses that key as the last key-only fallback for jobs that run in their own session, never with a trusted policy. These jobs read their conversation's memory through the fix: let older automations read their conversation's memory #208143 path. Placement, authority and automations scope are unchanged. main and session:<key> jobs are unchanged.
  • Proof: real-admission tests (3 red on base, green on head), and a scratch Gateway with a real model where a job in the production shape went from a memory denial to a successful knowledge_grep on its group conversation.

tideclaw-bot pushed a commit that referenced this pull request Nov 29, 2026
## What Problem This Solves

Automations created before OpenClaw recorded the creating conversation (every job without `sourceConversation`, i.e. created before #179062) name that conversation only by session key. Their scheduled runs get no memory at all: every `knowledge_*` or memory tool call fails with "the host granted this session no memory audience", and the Gateway logs `memory audience unavailable: root session agent:<agent>:cron:<job>:run:<run> has no durable chat type`. The same runs still hold owner-only tools such as `exec`. A production automation that reads and writes the owner's knowledge vault every week hit this on every run.

## User Impact

- A key-only detached automation (`isolated` / `current`) now reads its conversation's current memory, the same way a bound automation does:
  - created in the owner's direct chat: the owner's private memory;
  - created in a group or channel: only that conversation's memory, never owner-private.
- When the job recorded a requester (profile or channel sender), that requester's owner status is checked at each occurrence first; without one, the run's existing owner bit decides, as it already does for the run's tools.
- If the conversation row is gone, archived or cannot be read, the run proceeds exactly as before (no memory, no pause, no failure).
- Board, workspace, sandbox, event target and the run's tools are unchanged. `main` and `session:<key>` targets are unchanged.
- `automations bind` stays available for the exact-incarnation link but is no longer needed for memory. Docs (`cli/cron` "Binding older jobs", `automation/cron-jobs/payloads`) and Doctor's unbound note say so.

Accepted edge case: a key-only run whose agent sandbox mode is `non-main` or `all` now gets owner-private memory it did not have, when the job was created in the owner's direct chat. The owner created these jobs in their own DM, and the run already holds owner authority.

## Why This Change Was Made

`resolveScheduledPrincipal` classifies these jobs as `unbound-parent` and gives them legacy owner authority, but `buildScheduledExecutionContext` pointed their memory at the cron run row, which never has a chat type, so the memory resolver always denied. The fix stays in the existing owner:

- `admitScheduledOccurrence` (`src/cron/execution-context-admission.ts`): for an `unbound-parent` principal on a detached run, read the key-linked conversation row once. A failed read becomes "no row". No generation lease, workspace binding, sandbox or pause change. A recorded requester is admitted per occurrence through the existing `admitScheduledRequesterGrant`.
- `buildScheduledExecutionContext` (`src/cron/execution-context.ts`): with a live row, memory becomes `{ source: "parent", parent: <current sessionKey/sessionId/lifecycleRevision>, owner }`. Everything else for `unbound-parent` is unchanged.
- The memory resolver (`src/plugins/memory-audience.ts`) does not change: it already maps a direct root + owner to owner-private and direct/group/channel to that conversation's partition, for both the embedded and the CLI runtime.
- `scheduledParentKeyOf` now derives the key from `resolveScheduledPrincipal` itself, so Doctor's access review and the development replay read the same row the runtime does; the replay vector (`execution-context-projection.ts`) already labels the memory gain as intended, so it needed no edit.

Not changed: Doctor auto-bind or any stored-row write, jobs with no parent key, bound jobs with no recorded requester. On current `main`, bound jobs keep following their conversation after a reset (#205887), so no reset-degraded path exists to special-case.

## Evidence

Real-admission tests (red on the merge base `bb5c001bb6fc`, green on this head; 6 tests failed on base, all pass on head):

- `execution-context-memory-audience.test.ts` (real admission → registry → embedded and CLI resolvers): key-only owner-DM job → owner-private; key-only group job → that group's conversation only; key-only job with a revoked recorded requester → conversation only; key-only job whose conversation is gone → no audience, run admitted.
- `execution-context.test.ts`: key-only detached job gets parent memory and nothing else (board/workspace/sandbox stay the run's); archived, removed and in-session (`session:<key>`) cases keep run-session memory.
- `execution-context-admission.test.ts`: key-only read takes no generation lease; a failed read still admits the run with its own memory.
- `isolated-agent/run.bind-parent.test.ts` (real cron service + timer): the unbound job now reaches its conversation's memory, without a run-row receipt.

Local runs: the 27 test files that import the changed sources passed (`ocx test`, 6 shards). `pnpm check:changed`: typecheck, lint, guards all ok; the dead-export scan fails only on files this PR does not touch (`src/agents/command/types.ts`, `src/plugins/native-module-require.ts`, `ui/src/...`, `src/gateway/server-methods/update.test-harness.ts`), same as `main`.

End to end, scratch Gateway from source, `plugins.slots.memory: "knowledge"`, real model (`openai/gpt-5.5`). An owner Control UI direct chat was created by one real `chat.send` (row `chatType: "direct"`). A key-only isolated `agentTurn` job (owner key = that chat, no `sourceConversation`, no recorded requester, no tool policy, `toolsAllow` incl. `knowledge_remember`, `knowledge_grep`, `exec`) fired from its own `at` schedule about two minutes ahead (no forced run).

Base (`bb5c001bb6fc`):

```
[agent/embedded] memory audience unavailable: root session agent:main:cron:<job>:run:<run> has no durable chat type
```
```
knowledge_remember: "Knowledge access unavailable: the host granted this session no memory audience. The Gateway log entry "memory_audience_denied" for this session names the reason and its repair."
knowledge_grep: "Knowledge access unavailable: the host granted this session no memory audience. ..."
```

Head: no `memory audience unavailable` line in the Gateway log; the run's result:

```
knowledge_remember: inserted claim <claim-id>.
knowledge_grep: 1 hit — <claim-id>: "The owner's favorite tea is masala chai."
```

The claim was written under the store's `vault/private/` (owner-private).

Observed, not changed here: a session created only through `openclaw agent --session-key agent:main:main` from the CLI has no `chatType`, so a key-only job linked to such a row still gets no memory (Doctor already lists these under "no stored chat type"). Channel DMs and Control UI chats record `chatType: "direct"`.

Merge danger: two-way door. No schema, stored-row, config or protocol change; a revert restores the previous memory decision. Blast radius: memory audience of detached scheduled runs whose jobs have no `sourceConversation` but an owner/policy session key.

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

(cherry picked from commit 9143f38)

Later same-path commits from the pinned scan (separate behavior unless named as folded/selected below): 00e025a fix: report skipped manual automation runs without timing out (#208453); d4509c4 fix: keep script reports pending after required delivery fails (#208403); 03cdb2c fix: let the oldest automations read their conversation's memory (#208190).
Later PR-number mentions: `03cdb2cef17e` fix: let the oldest automations read their conversation's memory (#208190), `16a2d4b59d75` refactor(ui): lowercase log search text only once (#207383), `21786f65ed93` refactor(ui): stop sending 28 additional unused labels to translators (#207982), `34d4f8f308ba` improve: list Docker streams and flag unconfirmed cleanup in Doctor (#201292), `9cec330df50d` refactor(workboard): group session tiles without rescanning each column (#207380) Later commit-SHA mentions: none

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

Open debug capture after Gateway startup maintenance so outgoing requests and responses use the active database handle.

Worked on by:
- @daniel-lxs

Co-authored-by: daniel-lxs <[email protected]>
OpenClaw-Publication: 7bbacbac-213f-4404-a417-e11b4b3a69c0

(cherry picked from commit 2fca213)

Later same-path commits from the pinned scan (separate behavior unless named as folded/selected below): 974d792 fix: keep update status quiet and app-managed updates honest (#208359); 516166c fix: exit once when gateway run rejects an argument after an update (#208068).
Later PR-number mentions: `16a2d4b59d75` refactor(ui): lowercase log search text only once (#207383), `21786f65ed93` refactor(ui): stop sending 28 additional unused labels to translators (#207982), `34d4f8f308ba` improve: list Docker streams and flag unconfirmed cleanup in Doctor (#201292), `9cec330df50d` refactor(workboard): group session tiles without rescanning each column (#207380) Later commit-SHA mentions: `03cdb2cef17e` fix: let the oldest automations read their conversation's memory (#208190), `16a2d4b59d75` refactor(ui): lowercase log search text only once (#207383), `21786f65ed93` refactor(ui): stop sending 28 additional unused labels to translators (#207982), `34d4f8f308ba` improve: list Docker streams and flag unconfirmed cleanup in Doctor (#201292), `9cec330df50d` refactor(workboard): group session tiles without rescanning each column (#207380)

Co-authored-by: RomneyDa <[email protected]>
tideclaw-bot pushed a commit that referenced this pull request Nov 30, 2026
Automations created before OpenClaw recorded the creating conversation (every job without `sourceConversation`, i.e. created before #179062) name that conversation only by session key. Their scheduled runs get no memory at all: every `knowledge_*` or memory tool call fails with "the host granted this session no memory audience", and the Gateway logs `memory audience unavailable: root session agent:<agent>:cron:<job>:run:<run> has no durable chat type`. The same runs still hold owner-only tools such as `exec`. A production automation that reads and writes the owner's knowledge vault every week hit this on every run.

- A key-only detached automation (`isolated` / `current`) now reads its conversation's current memory, the same way a bound automation does:
  - created in the owner's direct chat: the owner's private memory;
  - created in a group or channel: only that conversation's memory, never owner-private.
- When the job recorded a requester (profile or channel sender), that requester's owner status is checked at each occurrence first; without one, the run's existing owner bit decides, as it already does for the run's tools.
- If the conversation row is gone, archived or cannot be read, the run proceeds exactly as before (no memory, no pause, no failure).
- Board, workspace, sandbox, event target and the run's tools are unchanged. `main` and `session:<key>` targets are unchanged.
- `automations bind` stays available for the exact-incarnation link but is no longer needed for memory. Docs (`cli/cron` "Binding older jobs", `automation/cron-jobs/payloads`) and Doctor's unbound note say so.

Accepted edge case: a key-only run whose agent sandbox mode is `non-main` or `all` now gets owner-private memory it did not have, when the job was created in the owner's direct chat. The owner created these jobs in their own DM, and the run already holds owner authority.

`resolveScheduledPrincipal` classifies these jobs as `unbound-parent` and gives them legacy owner authority, but `buildScheduledExecutionContext` pointed their memory at the cron run row, which never has a chat type, so the memory resolver always denied. The fix stays in the existing owner:

- `admitScheduledOccurrence` (`src/cron/execution-context-admission.ts`): for an `unbound-parent` principal on a detached run, read the key-linked conversation row once. A failed read becomes "no row". No generation lease, workspace binding, sandbox or pause change. A recorded requester is admitted per occurrence through the existing `admitScheduledRequesterGrant`.
- `buildScheduledExecutionContext` (`src/cron/execution-context.ts`): with a live row, memory becomes `{ source: "parent", parent: <current sessionKey/sessionId/lifecycleRevision>, owner }`. Everything else for `unbound-parent` is unchanged.
- The memory resolver (`src/plugins/memory-audience.ts`) does not change: it already maps a direct root + owner to owner-private and direct/group/channel to that conversation's partition, for both the embedded and the CLI runtime.
- `scheduledParentKeyOf` now derives the key from `resolveScheduledPrincipal` itself, so Doctor's access review and the development replay read the same row the runtime does; the replay vector (`execution-context-projection.ts`) already labels the memory gain as intended, so it needed no edit.

Not changed: Doctor auto-bind or any stored-row write, jobs with no parent key, bound jobs with no recorded requester. On current `main`, bound jobs keep following their conversation after a reset (#205887), so no reset-degraded path exists to special-case.

Real-admission tests (red on the merge base `bb5c001bb6fc`, green on this head; 6 tests failed on base, all pass on head):

- `execution-context-memory-audience.test.ts` (real admission → registry → embedded and CLI resolvers): key-only owner-DM job → owner-private; key-only group job → that group's conversation only; key-only job with a revoked recorded requester → conversation only; key-only job whose conversation is gone → no audience, run admitted.
- `execution-context.test.ts`: key-only detached job gets parent memory and nothing else (board/workspace/sandbox stay the run's); archived, removed and in-session (`session:<key>`) cases keep run-session memory.
- `execution-context-admission.test.ts`: key-only read takes no generation lease; a failed read still admits the run with its own memory.
- `isolated-agent/run.bind-parent.test.ts` (real cron service + timer): the unbound job now reaches its conversation's memory, without a run-row receipt.

Local runs: the 27 test files that import the changed sources passed (`ocx test`, 6 shards). `pnpm check:changed`: typecheck, lint, guards all ok; the dead-export scan fails only on files this PR does not touch (`src/agents/command/types.ts`, `src/plugins/native-module-require.ts`, `ui/src/...`, `src/gateway/server-methods/update.test-harness.ts`), same as `main`.

End to end, scratch Gateway from source, `plugins.slots.memory: "knowledge"`, real model (`openai/gpt-5.5`). An owner Control UI direct chat was created by one real `chat.send` (row `chatType: "direct"`). A key-only isolated `agentTurn` job (owner key = that chat, no `sourceConversation`, no recorded requester, no tool policy, `toolsAllow` incl. `knowledge_remember`, `knowledge_grep`, `exec`) fired from its own `at` schedule about two minutes ahead (no forced run).

Base (`bb5c001bb6fc`):

```
[agent/embedded] memory audience unavailable: root session agent:main:cron:<job>:run:<run> has no durable chat type
```
```
knowledge_remember: "Knowledge access unavailable: the host granted this session no memory audience. The Gateway log entry "memory_audience_denied" for this session names the reason and its repair."
knowledge_grep: "Knowledge access unavailable: the host granted this session no memory audience. ..."
```

Head: no `memory audience unavailable` line in the Gateway log; the run's result:

```
knowledge_remember: inserted claim <claim-id>.
knowledge_grep: 1 hit — <claim-id>: "The owner's favorite tea is masala chai."
```

The claim was written under the store's `vault/private/` (owner-private).

Observed, not changed here: a session created only through `openclaw agent --session-key agent:main:main` from the CLI has no `chatType`, so a key-only job linked to such a row still gets no memory (Doctor already lists these under "no stored chat type"). Channel DMs and Control UI chats record `chatType: "direct"`.

Merge danger: two-way door. No schema, stored-row, config or protocol change; a revert restores the previous memory decision. Blast radius: memory audience of detached scheduled runs whose jobs have no `sourceConversation` but an owner/policy session key.

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

Release adaptation: Resolve admission and payload documentation against the stable owners. Read a detached key-only parent once at occurrence admission without changing placement, workspace, sandbox, tools, or run-row receipts. Only an initially verified recorded requester can receive owner-private memory. With no verified requester, use conversation memory only; after a human ownership transfer, keep run-session memory. No new role or ownership rechecks, persisted fields, or config.

Follow-up audit: #208190 (03cdb2c) extends the fix to top-level historical keys and is separately assigned to release lane w5-43; integrate this prerequisite first. #201287 (bf2c75e) changes general owner admission and watcher launch, not the key-only memory fix. #208453 (00e025a) and #208403 (d4509c4) address distinct manual-run and script-delivery behavior. Remaining PR-number hits (#207383, #207982, #201292, #207380) are incidental, with no related cron-memory change.

Co-authored-by: RomneyDa <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 30, 2026
…nclaw#208190)

## What Problem This Solves

Follow-up to openclaw#208143. Some automations were created before OpenClaw recorded `owner`. These jobs record their creating conversation only as the job's top-level `sessionKey`: no `owner`, no `scheduledToolPolicy`, no `sourceConversation`. `resolveScheduledPrincipal` ignored that field, so it classified the jobs as `operator` (`unlinked-legacy`). Their runs got no memory, but they still held legacy owner authority. Every `knowledge_*` call failed, and the Gateway logged:

```
memory audience unavailable: root session agent:main:cron:<job>:run:<run> has no durable chat type
```

A production job hit this on every daily run. It was created by the agent in a Telegram group: `sessionTarget: "isolated"`, `agentTurn`, `toolsAllow` includes `knowledge_grep`/`knowledge_record`, `callerOrigin: unknown`.

## User Impact

- A detached (`isolated` / `current`) job that names its conversation only by top-level `sessionKey` now reads that conversation's current memory. openclaw#208143 gave key-only jobs the same path:
  - created in a group or channel: only that conversation's memory;
  - created in the owner's direct chat: the owner's private memory.
- Unchanged for these jobs: placement stays `detached`, authority stays legacy owner, the automations scope stays `self`, and board, workspace, sandbox and event target stay the run's own. If the conversation row is gone or archived, the run keeps going as before, with no memory.
- These jobs are now `unbound-parent`. As a result, `automations bind` accepts them, and Doctor lists them under "not bound … recorded by key only" instead of skipping them. This is intended.
- Unchanged: jobs with a `trusted` policy, and jobs that run inside a session (`main`, `session:<key>`). For these, the top-level `sessionKey` is the run's own lane, not a creating conversation. The setup-created proactive job (`session:<main>` + `sessionKey`) and heartbeat monitors migrated to `session:<key>` stay `operator`, so Doctor does not report them as unbound.
- `cron.add --session-key` from an operator, for a session that does not exist yet, still stores a top-level `sessionKey` with no `owner` or `sourceConversation`. Such a job now reads that session's memory once the session exists. An authenticated operator linked that session, and the run already holds operator/owner authority, so the memory matches. If the session exists when the job is created, `cron.add` already captures `sourceConversation`, and nothing changes.

Accepted edge case: a heartbeat monitor that Doctor migrated with `heartbeat.isolatedSession: true` is `isolated` with `sessionKey` set to the heartbeat session. It now reads that session's memory, and Doctor lists it as unbound. The run already holds legacy owner authority.

## Why This Change Was Made

Only one owner changes: `resolveScheduledPrincipal` (`src/cron/execution-context.ts`). The key-only fallback now ends with the legacy key: `policy.ownerSessionKey ?? owner.sessionKey ?? job.sessionKey`. The legacy key is used only when the job runs in its own session, and never with a `trusted` policy. No new state, flag or source kind.

Readers checked:
- `scheduledParentKeyOf` (admission, Doctor access review, development replay) derives the key from `resolveScheduledPrincipal`, so the runtime, Doctor and the replay read the same row without edits.
- `resolveCronBindParent` / `cron-bind`: these jobs become bindable (`unbound-parent`). `main` stays refused.
- Doctor `execution-context-report`: these jobs move from no listing to `unbound`. `missingChatType` already keys on `memory.source === "parent"`.
- `session-automation-index` reads only `parent`, so it is unchanged.
- `execution-context-projection`: no principal-kind branch except `ingress`.
- The other `job.sessionKey` readers (delivery, wake lane, `current` run keys, visibility) do not change.

## Evidence

Tests through the existing real-admission harness. Base `6a7c7cb5b70c`: 3 failed. Head: all pass.
- `execution-context-memory-audience.test.ts` (real admission → registry → embedded and CLI resolvers): a legacy group `sessionKey` job gets only that group's conversation partition. A legacy owner-direct `sessionKey` job gets owner-private. `trusted` policy, `sessionTarget: main` and `session:<key>` stay without memory (these pass on base too).
- `execution-context.test.ts`: the legacy key gives `unbound-parent` with `detached` placement, legacy owner authority and `self` automations scope. In-session, it stays `operator`/`unlinked-legacy`.

Local: the 49 test files that import the changed source, bind-parent, admission, the registry, the projection or the Doctor report all passed (`ocx test`, 10 shards). Also ran oxfmt and `pnpm check:changed` (see below).

End to end, on a scratch Gateway from source with `plugins.slots.memory: "knowledge"` and a real model (`openai/gpt-5.5`). One real `chat.send` created a scratch conversation, and its row was set to `chatType: "group"`. A job was created with `automations add` and edited into the production shape: `agentId: main`, top-level `sessionKey` = that conversation, `sessionTarget: isolated`, the same `toolsAllow`, `toolsAllowProvenance.callerOrigin.kind: unknown`, and no `owner` / `scheduledToolPolicy` / `sourceConversation`. It fired from its own `at` schedule (no forced run).

Base (`6a7c7cb5b70c`):
```
[agent/embedded] memory audience unavailable: root session agent:main:cron:<job>:run:<run> has no durable chat type
```
```
Knowledge access unavailable: "the host granted this session no memory audience"
```

Head: no `memory audience unavailable` line in the Gateway log. The run's result:
```
knowledge_grep("manifestation") returned 0 hits.
```

Merge danger: two-way door. No schema, stored-row, config or protocol change. A revert restores the previous classification. Blast radius: detached jobs with a top-level `sessionKey` and no `sourceConversation`, `owner.sessionKey` or account-policy key.

Co-authored-by: Ayaan Zaidi <[email protected]>
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. docs Improvements or additions to documentation impact:auth-provider Auth, provider routing, model choice, or SecretRef resolution may break. P2 Normal backlog priority with limited blast radius. size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant