惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
V
Visual Studio Blog
IT之家
IT之家
博客园 - 聂微东
The Cloudflare Blog
月光博客
月光博客
阮一峰的网络日志
阮一峰的网络日志
S
SegmentFault 最新的问题
Apple Machine Learning Research
Apple Machine Learning Research
酷 壳 – CoolShell
酷 壳 – CoolShell
爱范儿
爱范儿
H
Help Net Security
博客园 - 叶小钗
V
V2EX
WordPress大学
WordPress大学
J
Java Code Geeks
Hugging Face - Blog
Hugging Face - Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园_首页
C
Check Point Blog
B
Blog
D
DataBreaches.Net
美团技术团队
罗磊的独立博客

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
refactor: route plugin host hook state through accessor (...
jalehman · 2026-06-24 · via Recent Commits to openclaw:main

@@ -6,6 +6,10 @@ import {

66

acquireSessionWriteLock,

77

resolveSessionWriteLockOptions,

88

} from "../../agents/session-write-lock.js";

9+

import {

10+

resolveSessionStoreAgentId,

11+

resolveSessionStoreKey,

12+

} from "../../gateway/session-store-key.js";

913

import { formatErrorMessage } from "../../infra/errors.js";

1014

import { resolveRequiredHomeDir } from "../../infra/home-dir.js";

1115

import { resolveAgentIdFromSessionKey } from "../../routing/session-key.js";

@@ -18,6 +22,7 @@ import { getRuntimeConfig } from "../io.js";

1822

import type { OpenClawConfig } from "../types.openclaw.js";

1923

import { formatSessionArchiveTimestamp } from "./artifacts.js";

2024

import { extractGeneratedTranscriptSessionId } from "./generated-transcript-session-id.js";

25+

import { resolveAgentMainSessionKey } from "./main-session.js";

2126

import {

2227

resolveSessionFilePath,

2328

resolveSessionFilePathOptions,

@@ -68,6 +73,7 @@ import {

6873

type SessionLifecycleArtifactCleanupResult,

6974

type SessionLifecycleStoreTarget,

7075

} from "./store.js";

76+

import { resolveAllAgentSessionStoreTargetsSync, type SessionStoreTarget } from "./targets.js";

7177

import { parseSessionThreadInfo } from "./thread-info.js";

7278

import {

7379

type AppendSessionTranscriptMessageParams,

@@ -124,6 +130,50 @@ export type SessionAccessScope = {

124130

storePath?: string;

125131

};

126132133+

export type LogicalSessionAccessScope = {

134+

/** Runtime config whose session store rules define the logical session owner. */

135+

cfg: OpenClawConfig;

136+

/** Environment override used when resolving configured/discovered agent stores. */

137+

env?: NodeJS.ProcessEnv;

138+

/** Canonical or alias session key for the logical entry being read or written. */

139+

sessionKey: string;

140+

};

141+142+

export type ResolvedSessionEntryAccessTarget = {

143+

/** Agent owner inferred from the canonical session key. */

144+

agentId: string;

145+

/** Canonical session key returned to callers even when an alias row won. */

146+

canonicalKey: string;

147+

/** Freshest matching entry, if any. */

148+

entry?: SessionEntry;

149+

/** Original caller-supplied key after trimming. */

150+

requestedKey: string;

151+

/** Persisted key for the selected row. */

152+

storeKey: string;

153+

};

154+155+

type ResolvedSessionEntryStoreTarget = ResolvedSessionEntryAccessTarget & {

156+

storePath: string;

157+

};

158+159+

export type ResolvedSessionEntryUpdateContext = Omit<ResolvedSessionEntryAccessTarget, "entry"> & {

160+

/** Mutable entry inside the storage operation. */

161+

entry: SessionEntry;

162+

};

163+164+

export type ResolvedSessionEntryUpdateResult<T> =

165+

| {

166+

canonicalKey: string;

167+

found: false;

168+

}

169+

| {

170+

canonicalKey: string;

171+

entry: SessionEntry;

172+

found: true;

173+

result: T;

174+

storeKey: string;

175+

};

176+127177

export type SessionTranscriptAccessScope = Omit<SessionAccessScope, "sessionKey"> & {

128178

/** Explicit transcript file path; bypasses store lookup when already known. */

129179

sessionFile?: string;

@@ -428,6 +478,182 @@ export type DeleteSessionEntryLifecycleParams = {

428478429479

export { clearPluginOwnedSessionState };

430480481+

function isStorePathTemplate(store?: string): boolean {

482+

return typeof store === "string" && store.includes("{agentId}");

483+

}

484+485+

function resolveLogicalSessionStoreCandidates(params: {

486+

agentId: string;

487+

cfg: OpenClawConfig;

488+

env?: NodeJS.ProcessEnv;

489+

}): SessionStoreTarget[] {

490+

const storeConfig = params.cfg.session?.store;

491+

const defaultTarget = {

492+

agentId: params.agentId,

493+

storePath: resolveStorePath(storeConfig, { agentId: params.agentId, env: params.env }),

494+

};

495+

if (!isStorePathTemplate(storeConfig)) {

496+

return [defaultTarget];

497+

}

498+

const targets = new Map<string, SessionStoreTarget>();

499+

targets.set(defaultTarget.storePath, defaultTarget);

500+

for (const target of resolveAllAgentSessionStoreTargetsSync(params.cfg, { env: params.env })) {

501+

if (target.agentId === params.agentId) {

502+

targets.set(target.storePath, target);

503+

}

504+

}

505+

return [...targets.values()];

506+

}

507+508+

function buildLogicalSessionEntryCandidateKeys(params: {

509+

agentId: string;

510+

canonicalKey: string;

511+

cfg: OpenClawConfig;

512+

requestedKey: string;

513+

}): string[] {

514+

const targets = new Set<string>();

515+

if (params.canonicalKey) {

516+

targets.add(params.canonicalKey);

517+

}

518+

if (params.requestedKey && params.requestedKey !== params.canonicalKey) {

519+

targets.add(params.requestedKey);

520+

}

521+

if (params.canonicalKey === "global" || params.canonicalKey === "unknown") {

522+

return [...targets];

523+

}

524+

const agentMainKey = resolveAgentMainSessionKey({

525+

cfg: params.cfg,

526+

agentId: params.agentId,

527+

});

528+

if (params.canonicalKey === agentMainKey) {

529+

targets.add(`agent:${params.agentId}:main`);

530+

}

531+

return [...targets];

532+

}

533+534+

function findFreshestSessionEntryMatch(

535+

entries: SessionEntrySummary[],

536+

candidateKeys: readonly string[],

537+

): SessionEntrySummary | undefined {

538+

let freshest: SessionEntrySummary | undefined;

539+

for (const candidate of candidateKeys) {

540+

const trimmed = candidate.trim();

541+

if (!trimmed) {

542+

continue;

543+

}

544+

const match = entries.find((entry) => entry.sessionKey === trimmed);

545+

if (match && (!freshest || (match.entry.updatedAt ?? 0) >= (freshest.entry.updatedAt ?? 0))) {

546+

freshest = match;

547+

}

548+

}

549+

return freshest;

550+

}

551+552+

/**

553+

* Resolves a logical session key to the freshest matching entry across the

554+

* configured store and discovered same-agent stores.

555+

*/

556+

export function resolveSessionEntryAccessTarget(

557+

scope: LogicalSessionAccessScope,

558+

): ResolvedSessionEntryAccessTarget {

559+

const target = resolveSessionEntryStoreTarget(scope);

560+

return {

561+

agentId: target.agentId,

562+

canonicalKey: target.canonicalKey,

563+

entry: target.entry,

564+

requestedKey: target.requestedKey,

565+

storeKey: target.storeKey,

566+

};

567+

}

568+569+

function resolveSessionEntryStoreTarget(

570+

scope: LogicalSessionAccessScope,

571+

): ResolvedSessionEntryStoreTarget {

572+

const requestedKey = scope.sessionKey.trim();

573+

const canonicalKey = resolveSessionStoreKey({ cfg: scope.cfg, sessionKey: requestedKey });

574+

const agentId = resolveSessionStoreAgentId(scope.cfg, canonicalKey);

575+

const scanTargets = buildLogicalSessionEntryCandidateKeys({

576+

agentId,

577+

canonicalKey,

578+

cfg: scope.cfg,

579+

requestedKey,

580+

});

581+

const candidates = resolveLogicalSessionStoreCandidates({

582+

agentId,

583+

cfg: scope.cfg,

584+

env: scope.env,

585+

});

586+

const fallback = candidates[0] ?? {

587+

agentId,

588+

storePath: resolveStorePath(scope.cfg.session?.store, { agentId, env: scope.env }),

589+

};

590+

let selectedStorePath = fallback.storePath;

591+

let selectedMatch = findFreshestSessionEntryMatch(

592+

listSessionEntries({ storePath: fallback.storePath }),

593+

scanTargets,

594+

);

595+

for (let index = 1; index < candidates.length; index += 1) {

596+

const candidate = candidates[index];

597+

if (!candidate) {

598+

continue;

599+

}

600+

const match = findFreshestSessionEntryMatch(

601+

listSessionEntries({ storePath: candidate.storePath }),

602+

scanTargets,

603+

);

604+

if (

605+

match &&

606+

(!selectedMatch || (match.entry.updatedAt ?? 0) >= (selectedMatch.entry.updatedAt ?? 0))

607+

) {

608+

selectedStorePath = candidate.storePath;

609+

selectedMatch = match;

610+

}

611+

}

612+

return {

613+

agentId,

614+

canonicalKey,

615+

entry: selectedMatch?.entry,

616+

requestedKey,

617+

storeKey: selectedMatch?.sessionKey ?? canonicalKey,

618+

storePath: selectedStorePath,

619+

};

620+

}

621+622+

/**

623+

* Mutates the freshest matching logical session entry without exposing the

624+

* backing store map to callers.

625+

*/

626+

export async function updateResolvedSessionEntry<T>(

627+

scope: LogicalSessionAccessScope,

628+

update: (entry: SessionEntry, context: ResolvedSessionEntryUpdateContext) => Promise<T> | T,

629+

): Promise<ResolvedSessionEntryUpdateResult<T>> {

630+

const target = resolveSessionEntryStoreTarget(scope);

631+

if (!target.entry) {

632+

return { canonicalKey: target.canonicalKey, found: false };

633+

}

634+

return await updateSessionStore(target.storePath, async (store) => {

635+

const entry = store[target.storeKey];

636+

if (!entry) {

637+

return { canonicalKey: target.canonicalKey, found: false };

638+

}

639+

const context: ResolvedSessionEntryUpdateContext = {

640+

agentId: target.agentId,

641+

canonicalKey: target.canonicalKey,

642+

entry,

643+

requestedKey: target.requestedKey,

644+

storeKey: target.storeKey,

645+

};

646+

const result = await update(entry, context);

647+

return {

648+

canonicalKey: target.canonicalKey,

649+

entry: structuredClone(entry),

650+

found: true,

651+

result,

652+

storeKey: target.storeKey,

653+

};

654+

});

655+

}

656+431657

/** Returns the entry for a canonical or alias session key, if one exists. */

432658

export function loadSessionEntry(scope: SessionAccessScope): SessionEntry | undefined {

433659

if (scope.clone === false) {