Repository navigation
fix(agent-server): one owner for confirmation_policy, security_analyzer and secrets (base_state.json) - #6764
Conversation
…nd secrets out of meta.json set_confirmation_policy, set_security_analyzer and update_secrets wrote only to ConversationState (base_state.json), while StoredConversation (meta.json) kept its own creation-time copy of all three. On every resume, after an idle eviction or a server restart, EventService.start() re-applied the meta.json copy and silently reverted the changes. Follow the pattern of #4440, which moved `agent` off StoredConversation: the three fields (and `secrets_encrypted`) move from ConversationConfig down to StartConversationRequest, so StoredConversation cannot carry them and there is no second copy to drift. base_state.json is their only owner after creation. - StartConversationRequest: now declares the four fields itself. The REST request body is unchanged. - EventService: takes `confirmation_policy`, `security_analyzer` and `secrets` as init-only fields, like `agent`. start() seeds the policy and analyzer only when no base_state.json exists yet; a resume keeps what the state holds. - ConversationService: passes the three to the EventService on create and no longer splats them into StoredConversation. The CODEX fallback secret goes to the EventService as an argument instead of a temporary patch of `stored.secrets`. apply_resume_secrets stops mirroring into meta.json. - Child conversations inherit the three from the parent's ConversationState, since the parent's StoredConversation no longer has them. - Telemetry reports the conversation's current policy, not the one it was created with. Old meta.json files that still have the keys load fine: they are ignored. Fixes #4810. This is #4813 brought up to date with main: the squash of its agent-server commits (30f79f0, 44eecbc, aa8047d, d800fc2, c402636, d948733, b0c0093, c6d100f, 6494ba1, cca43ac, a4e7a74, 8f3443d, 3ad137e) plus the merge resolutions. The SDK parts of #4813 are in the two PRs this one is stacked on. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com> Co-authored-by: Engel Nyst <engel.nyst@gmail.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013ArwwMuszm1Nt9r2whddpY
…ed is set The analyzer no longer goes through the StoredConversation payload that is validated with the cipher, so with secrets_encrypted=True its nested credentials (e.g. the guardrail LLM api_key) would stay ciphertext for the first session. Validate it with the cipher, like the agent and the secrets (`request_security_analyzer`, next to `request_secrets`). Split out of #4813 (commit 5466de5, as adapted in its merge 77499fb). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013ArwwMuszm1Nt9r2whddpY
…start Drives a real ConversationService through a restart: a confirmation policy, a security analyzer and a secret set after start are still there, none of them is in meta.json, and a fork made after the restart carries all three. Split out of #4813 (commit aedf746). Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013ArwwMuszm1Nt9r2whddpY
…te lock A parent starts a child from inside its own step. The step holds the parent's state lock until the tool call returns, and the tool call returns only when this server answers the start request. Reading the inherited policy, analyzer and secrets under that lock therefore never finished: the launch hung until the tool's timeout. Read the three without the lock, as the agent and the budget already are. Each is replaced on change, never mutated in place (update_secrets now assigns a new registry), so a plain read sees a whole value. The child also gets its own copies of the secret sources, as a fork does. Raised in review on #4813 (#4813 (comment)). The new test holds the parent's lock the way a running step does; it times out without this change. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013ArwwMuszm1Nt9r2whddpY
…pdate_secrets apply_resume_secrets copied the secret registry, updated the copy and assigned it back by hand. That is what LocalConversation.update_secrets does now, so call it. The state lock is still held around the update and the ACP credential restart, as before. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013ArwwMuszm1Nt9r2whddpY
…d payload in one place _create_conversation dumped the request, then popped confirmation_policy, security_analyzer, secrets and secrets_encrypted from the result. The dump already has an exclude set for what StoredConversation does not carry (the agent sources, max_budget_per_run); name the four there. Telemetry reads the policy through the conversation's public `state`. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013ArwwMuszm1Nt9r2whddpY
Before this stack, update_secrets mutated the registry in place, so a conversation created with start-time secrets and not saved since (no message, no other state change) had them in meta.json and nowhere else. With `secrets` gone from StoredConversation, the first resume by the new server would ignore that key and then rewrite meta.json without it: the only copy of the secret, lost on upgrade. On resume, read the legacy `secrets` key from meta.json and add the names base_state.json does not have. base_state.json wins for the names it has, so a saved runtime override is not reverted. Names bound to a runtime credential binding stay scrubbed. The next save_meta drops the key, so this runs once per conversation. The policy and the analyzer need nothing: base_state.json always had them, and its value is the newer one. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013ArwwMuszm1Nt9r2whddpY
…sume The comment said all of them are unused on resume. `secrets` is not: it is added on every start, which is how the CODEX fallback credential reaches a resumed conversation. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013ArwwMuszm1Nt9r2whddpY
…udget's main's budget change keeps `max_budget_per_run` off meta.json through a keyword-only `initial_max_budget_per_run` on EventService. The policy and the analyzer follow the same rule (they seed a new conversation and are ignored on a resume), so they take the same shape: `initial_confirmation_policy` and `initial_security_analyzer`, keyword-only. `secrets` keeps its name because it is not initial-only: it is added on every start. The mock-based test class for these fields is replaced by two tests on a real EventService: a new conversation has its start settings in base_state.json and none in meta.json, and a resume keeps the saved policy and analyzer whatever the EventService was constructed with. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013ArwwMuszm1Nt9r2whddpY
…and secrets An idle conversation is evicted after 20 minutes by default and loaded again on its next use. On main that reload re-applied the creation-time values: a conversation switched to AlwaysConfirm went back to NeverConfirm, and a replaced secret went back to its old value. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013ArwwMuszm1Nt9r2whddpY
… and secrets F08 gains five sub-features: where the three live on disk (in base_state.json, never in meta.json), a runtime policy and analyzer after a restart, a replaced start-time secret after a restart, and an upgrade from the latest release. F10 gains a fork that keeps settings changed after the source was created. The three credential-binding recipes in F12 that read `meta.json`'s `secrets` now read the secret registry in base_state.json, and F31's layout line names the new homes. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013ArwwMuszm1Nt9r2whddpY
Coverage Report •
|
||||||||||||||||||||||||||||||||||||||||
A full replay of F04 on this branch failed two recipes that asserted the old one: `F04.create-settings` expected `secrets_encrypted` in meta.json, and `F04.create-secrets` expected the secret there. They now check that meta.json has neither and that base_state.json holds the secret encrypted. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013ArwwMuszm1Nt9r2whddpY
Brings in the review fixes made on parts 1 and 2: the masked string form of state update events, one copy idiom for what a fork takes over, hook verdicts carried into a fork, and the GraySwan key serializer. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013ArwwMuszm1Nt9r2whddpY # Conflicts: # .agents/skills/verify-agent-server/references/feature-map/F08-confirmation-security-secrets.md
… fork's A deep copy of a secret source fails on one that holds a lock or a client. Use the same dump/validate round trip as for the analyzer, which is what LocalConversation.fork does for both. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013ArwwMuszm1Nt9r2whddpY
…holds the lock arun() holds the parent's state lock on the event-loop thread while it awaits the tool; run() holds it on a worker thread. The lock is reentrant per thread, so the single-case test would still have passed with a lock taken inline on the loop thread. Both cases now block a thread on the launch the way the tool's HTTP request does. The inherited secret sources are read from a snapshot of the registry's mapping. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013ArwwMuszm1Nt9r2whddpY
…d base The agent-server package depends on openhands-sdk without a version bound, so a released agent-server can run on a newer SDK. The released StoredConversation extends ConversationConfig and reads confirmation_policy, security_analyzer and secrets from it. Taking those fields off ConversationConfig made such a server fail every conversation start with AttributeError. ConversationConfig keeps the four fields. The fields a server record may hold move to a new base under it, StoredConversationConfig, and the agent-server's StoredConversation extends that one. The record still cannot carry the four fields, and StartConversationRequest is the same model as on main: the exported OpenAPI document is byte-identical. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013ArwwMuszm1Nt9r2whddpY
…ts are used EventService.secrets is read once, in start(). Bound names were removed from it by the credential scrub and again by a late binding, the second time on a dict nothing reads any more. start() now leaves bound names out when it hands the secrets to the conversation, and both removals go. The tests that looked at that input dict look at the secret registry instead. test_failed_resume_does_not_retain_plaintext_fallback is removed: it guarded the temporary patch of stored.secrets, which no longer exists, and its remaining assertion could not fail. Two comments are corrected: a budget given on a resume does replace the saved one, and secret updates no longer replace the stored record. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013ArwwMuszm1Nt9r2whddpY
…efore the scrub The secrets an older server left in meta.json were read into memory, and written to base_state.json only after the conversation was built. In between, the credential scrub rewrites meta.json without them. A load that failed after the scrub (for example an unusable workspace path) lost them for good. They are now written to base_state.json first, for the names it lacks and that have no credential binding, so the take-over no longer depends on the rest of the load. A meta.json whose secrets cannot be read is reported in the log instead of skipped silently. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013ArwwMuszm1Nt9r2whddpY
A start request for an existing conversation can carry a Codex fallback credential. With secrets_encrypted set, the create path decrypted the request's secrets and the resume path did not, so the cipher text was installed as the credential, on a loaded and on an unloaded conversation. The Docker runtime forwards every start with secrets_encrypted set. The resume path reads the secrets through request_secrets, as create does. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013ArwwMuszm1Nt9r2whddpY
…'s analyzer The request's security analyzer went to the conversation as the same object unless the request was encrypted. Two conversations started from one request object then ran on one analyzer, and an analyzer can keep per-conversation history. Before this stack the analyzer was copied by its trip through the stored record. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013ArwwMuszm1Nt9r2whddpY
… without a cipher Without OH_SECRET_KEY and without a session API key, base_state.json holds no secret values. The loaded conversation is their only copy, where the in-memory stored record used to be a second one for start-time secrets. An ACP agent's provider credential is such a secret. - A conversation that holds secrets is not unloaded when idle. - A fork receives its source's secrets from memory. A sandbox pause still loses them, as a restart does; the README says so. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013ArwwMuszm1Nt9r2whddpY
The stored record has not carried the agent for a while, and a child gets its parent's current secrets, not the ones from the parent's start. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013ArwwMuszm1Nt9r2whddpY
…eps-state' into claude/openhands-sdk-dual-source-truth-qp1x6r-3-single-owner # Conflicts: # .agents/skills/verify-agent-server/references/feature-map/F08-confirmation-security-secrets.md
… conversation Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013ArwwMuszm1Nt9r2whddpY
…eps-state' into claude/openhands-sdk-dual-source-truth-qp1x6r-3-single-owner
… again The take-over of secrets an older server left in meta.json had become a second place where the server parses and rewrites base_state.json by hand. It goes back to LocalConversation.update_secrets after the conversation is built. The one case that needed the early write is kept, where it arises: the credential scrub rewrites meta.json before the load, and only when the conversation has a credential binding. The scrub already rewrites base_state.json at that point, so it now carries along the legacy names that file lacks. Without a binding nothing touches meta.json until the load has succeeded, and a failed load can simply be retried. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013ArwwMuszm1Nt9r2whddpY
…analyzer EventService seeded the request's confirmation policy and analyzer only when base_state.json did not exist. A create that fails after that file is written (a full disk while the start secrets are saved, a kill) leaves it behind, and the retry with the same id then ran with NeverConfirm and no analyzer. main applied the requested values. The seeding now depends on who is calling: only a creating caller passes its agent to the EventService; a resume and a fork pass none. Two tests on a real ConversationService: the retried create, and a child that inherits its parent's current policy, analyzer and secrets. The existing child test runs against a mocked EventService and passed with the seeding removed. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013ArwwMuszm1Nt9r2whddpY
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013ArwwMuszm1Nt9r2whddpY
…under the single owner F08 gains five bullets and richer versions of four: the start-time values after a restart, a cleared analyzer, a fork made right after a restart, a child that inherits the parent's current values, and a reload after a sandbox pause. The policy bullet now also drives the conversation and checks that the action waits. The on-disk bullet tells an absent key from a null one with jq. F10's fork bullet checks that the fork's secret is cipher text. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013ArwwMuszm1Nt9r2whddpY
Each of these was green with part of the change removed: - telemetry reports the conversation's own policy at creation; - a create with secrets_encrypted set decrypts the conversation's secrets, and refuses the request on a server that has no cipher; - a start secret named like a bound credential stays out of the registry; - a legacy meta.json that holds a bound credential next to other secrets: the others are taken over, the bound one is not; - a legacy secrets key this server cannot parse does not block the resume; - a second start request for an existing id leaves its saved policy, analyzer and secrets alone; - a child's inherited secret is its own object. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013ArwwMuszm1Nt9r2whddpY
…eps-state' into claude/openhands-sdk-dual-source-truth-qp1x6r-3-single-owner
…loaded too The guard that keeps a conversation loaded when a reload would lose its secrets looked at the secret registry only. A security analyzer can carry a key of its own (a guardrail LLM, GraySwan). Without a cipher that key is not saved either, and an analyzer without its key rates every action UNKNOWN, which ConfirmRisky(confirm_unknown=False) lets through. main re-applied the analyzer from memory after an idle unload. The guard now asks of the registry and of the analyzer whether a dump without credentials differs from one with them, so a lookup secret with no secret header and an analyzer with no key stay evictable. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013ArwwMuszm1Nt9r2whddpY
…en over A secret an older server left in meta.json reads as unset when the server runs under a key that cannot decrypt it. Taking it over called update_secrets, which saves the state, and that save wrote out everything else the load could not decrypt as unset: after the right key was restored the agent's LLM key was gone. On main such a load does not write base_state.json. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013ArwwMuszm1Nt9r2whddpY
…eft behind - Two tests asserted the secrets kwarg of a mocked EventService; that the secrets reach the conversation is tested on a real service. - The telemetry context test no longer claims to check where the policy is read from: it is an argument now. It keeps what it still shows. - The trajectory zip test scanned for secrets that meta.json cannot hold. - The restart test asserted that two objects loaded from two files differ. - Two tests read the conversation's private state; they use get_state(). Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013ArwwMuszm1Nt9r2whddpY
…eps-state' into claude/openhands-sdk-dual-source-truth-qp1x6r-3-single-owner
…thers The secrets an older server left in meta.json were validated as one mapping, so a single entry this server cannot parse (a secret kind from a plugin that is gone) made the whole key unreadable, and the next write of meta.json dropped all of them. Each entry is now read on its own: the unreadable one is reported by name in the log and left behind, the rest are taken over. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013ArwwMuszm1Nt9r2whddpY
The live before/after results on main and on the three branches, the family replays, the UI run with two screenshots, and the local runs of the checks CI keeps for PRs into main. Temporary, under .pr/. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013ArwwMuszm1Nt9r2whddpY
…eps-state' into claude/openhands-sdk-dual-source-truth-qp1x6r-3-single-owner # Conflicts: # .agents/skills/verify-agent-server/references/feature-map/F08-confirmation-security-secrets.md # .agents/skills/verify-agent-server/references/feature-map/README.md
ConversationService takes one ServerStores since #6702; the two tests that restart a service on an older meta.json still passed secrets_store. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013ArwwMuszm1Nt9r2whddpY
…eps-state' into claude/openhands-sdk-dual-source-truth-qp1x6r-3-single-owner
Taking a secret over saves the conversation state. The check was per entry and only skipped a StaticSecret whose value read as unset, so two loads that cannot decrypt the stored state still saved it: another key with a legacy LookupSecret, and no key at all with a legacy StaticSecret, whose cipher text was then also used as the value. Both wrote the agent's key and the other secrets as missing. The legacy mapping and base_state.json are now searched for a Fernet token this server cannot decrypt, and if there is one nothing is taken over. The warning says that the next write of meta.json drops those secrets. The failed-first-load test now also asserts what the credential scrub did during that load, so it cannot pass without a resolved binding. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013ArwwMuszm1Nt9r2whddpY
…eps-state' into claude/openhands-sdk-dual-source-truth-qp1x6r-3-single-owner
The runs are repeated on main at 91e8b5b and on the final commits of the three parts: the before/after pairs, the whole families next to the same families on main, the Agent Canvas UI, and the checks CI runs only for PRs into main. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013ArwwMuszm1Nt9r2whddpY
…eps-state' into claude/openhands-sdk-dual-source-truth-qp1x6r-3-single-owner # Conflicts: # .agents/skills/verify-agent-server/references/feature-map/F10-fork-navigate-condense-ask.md # .agents/skills/verify-agent-server/references/feature-map/README.md
The proof is repeated on the stack merged with main at 3c66af1 and on that main: the before/after pairs, the whole families on both sides compared bullet by bullet, the SDK maps, and the checks CI runs only for PRs into main. The UI section stays on the commits it was run on. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013ArwwMuszm1Nt9r2whddpY
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013ArwwMuszm1Nt9r2whddpY
Conflicts, all between the single-owner change and work that landed on main since the last merge: - conversation_service.py: main added `initial_sender` to the launch path (#6975); the launch helper now takes it next to the policy, the analyzer and the secrets this branch passes to the event service. - event_service.py: main moved state-lock work onto the state executor (#6554). `apply_resume_secrets` runs its update through `run_state_op` as on main and still writes no secrets to meta.json. - tests: both sides' imports and tests are kept. - feature maps: main's new bullets and counts, plus this branch's single-owner bullets; the bullet that said a load re-applies the creation-time copy from meta.json stays removed. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013ArwwMuszm1Nt9r2whddpY
main replaced the hand-written `{"cipher": ...}` and
`{"expose_secrets": True}` dicts with `cipher_context()` and
`client_context()` (#6779). The three places this branch adds now do the
same; behaviour is unchanged.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013ArwwMuszm1Nt9r2whddpY
…sation main added three tests that build a `ConversationState` with `confirmation_policy=stored.confirmation_policy`. `StoredConversation` no longer has that field on this branch, and none of the three is about the policy, so they now take the state's default, like their siblings. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013ArwwMuszm1Nt9r2whddpY
Agent-server conversation start benchmarkBase
How this is measuredEach create is a Canvas-shaped
A timing is flagged when the 95% CIs do not overlap and the medians differ by at least 50 ms, or when a row with at least 8 samples per side moves by at least 150 ms and 25%. A create stalled the server when its slowest |
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013ArwwMuszm1Nt9r2whddpY
HUMAN:
Engel Nyst asked me to find the fork PR that removes the two sources of truth for a conversation's settings (
meta.jsonin the agent-server andbase_state.jsonin the SDK), which is #4813 by @BSmick6; to put its commits on branches in this repo, split so that each concern can be reviewed on its own; and to open new PRs that credit the author and say that we do the final review and tweaks. Then to review each PR, address what the review finds, and prove that the changes work by running the SDK and the agent-server the way a program or an agent does, with the repo'sverify-sdkandverify-agent-serverskills. The principle behind the request: the agent-server is a REST interface to the SDK. It should not be a different thing, and it should not repeat what the SDK already does, unless a particular case gives a special reason.This is part 3 of 3: the agent-server stops keeping its own copy of
confirmation_policy,security_analyzerandsecrets.base_state.jsonis their only home.AGENT:
I'm Claude (Fable 5.2), an AI agent working for Engel Nyst. I brought #4813 up to date with
main, split it into a stack of three PRs, reviewed each, and verified them against real servers and through the Agent Canvas UI. The design and the core refactor in this PR (commit6c14b62d) are @BSmick6's, from #4813, with one fix from Engel Nyst's follow-ups on that PR (c3d1a02d) and one test (11703e03) split out of a commit an AI agent authored on that PR. The rest was added in the final review and is listed under "Final review".The stack: 1. #6762 (secrets are saved the moment they change) → 2. #6763 (a fork keeps the state) → 3. this PR. It is based on part 2, so its diff shows only its own change. #4813's own commits, merged with
mainat56d559f6, are on the branchclaude/openhands-sdk-dual-source-truth-qp1x6r.Why
A conversation's confirmation policy, security analyzer and secrets were stored twice: by the SDK in
base_state.json, and by the agent-server inmeta.json. The runtime routes (POST .../confirmation_policy,.../security_analyzer,.../secrets) never wrote the second; a secret reached even the first only at the next save of the state, which #6762 fixes. Every load of the conversation, after a restart or after the default 20-minute idle eviction, re-applied the second, the copy from creation time. Onmain:AlwaysConfirmgoes back toNeverConfirmand runs actions unasked (or the other way round);A safety setting that silently reverts is the serious part. The agent-server is meant to be a REST interface to the SDK; for these three values it kept a second copy and let it win.
Summary
StoredConversation(meta.json) can no longer carryconfirmation_policy,security_analyzer,secretsorsecrets_encrypted. Its base class is a newStoredConversationConfig, which has no field for them, the same way fix(agent-server): base_state.json as single source of truth for the agent (end meta.json duplication) #4440 keptagentout of the stored record.ConversationConfigandStartConversationRequestkeep their released shape, so the REST body and the OpenAPI document are unchanged.EventServicereceives the policy and the analyzer as start fields that are applied when a conversation is created; a resume keeps whatbase_state.jsonholds. Secrets reach the conversation through the SDK's ownupdate_secrets.secrets_encryptedis set, since they no longer pass through the stored payload that was validated with the cipher.EventServiceas an argument instead of a temporary patch ofstored.secrets.conversation_createdevent reads the policy from the conversation state, since the stored record no longer has it. As before, that is the policy the conversation starts with; for a fork or a child it is now its source's current policy, not the source's creation-time one.Final review: what was found and changed on top of #4813
meta.json. fix(agent-server): own confirmation_policy, security_analyzer, secrets in ConversationState #4813 ignored that key and then rewrote the file without it. The first load now takes over the namesbase_state.jsonlacks (base_state.jsonwins for the ones it has), through the SDK's ownupdate_secrets. One case needs more. With a credential binding, the credential scrub rewritesmeta.jsonbefore the conversation is loaded. The scrub already rewritesbase_state.jsonas well, so it now writes those secrets there in the same step, and a load that fails right after does not lose them. Two edges. The take-over is decided per load: when this server's key cannot decrypt what the two files hold (another key, or no key at all), nothing is taken over, so the take-over adds no save of the conversation state on a load that could not read it; the legacy secrets are then dropped by the next write ofmeta.json, and the log says so. That is all it guarantees: a conversation with a credential binding still has both files rewritten by the credential scrub on such a load, as onmain, and the regression test covers conversations without a binding. And each legacy entry is read on its own, so one that cannot be parsed (a secret kind this server does not know) is reported in the log and costs only itself. Shown live below with the latest release.openhands-agent-serverdoes not pin the SDK version, and the releasedStoredConversationextendsConversationConfigand reads the three fields from it. Taking them offConversationConfig, as fix(agent-server): own confirmation_policy, security_analyzer, secrets in ConversationState #4813 did, made a released server fail every conversation start withAttributeErroronce it ran on the new SDK. Hence the slim base under an unchangedConversationConfig: the agent-server code of the 1.62.0 release starts conversations on this SDK (result below).base_state.jsondid not exist. A create that fails after that file is written (a full disk, a kill) leaves it behind, and the retry with the same id then ran withNeverConfirmand no analyzer;mainapplied the requested values. The start fields are now applied whenever the caller passes an agent, which only the create path does; whetherbase_state.jsonexists no longer decides it.secrets_encryptedset, the create path decrypted the request's secrets and the resume path did not. It behaves the same onmain; the Docker runtime forwards every start that way. The resume path now reads the secrets the way create does.OH_SECRET_KEYnor a session key) writes no secret values to disk, so the in-memory copy ofmeta.jsonused to be the only thing that brought start-time secrets back after an idle eviction or a fork. An ACP agent's provider credential is such a secret. Without that second copy, the loaded conversation is the only place that has the values, so such a server does not evict an idle conversation that holds secrets or an analyzer with a key of its own, and a fork receives its source's secrets from memory.apply_resume_secretscallsLocalConversation.update_secretsinstead of copying the registry by hand; a child's analyzer and secrets are copied with the helperfork()uses; the four fields are left out of the stored payload through the existing exclude set; the start fields are named likemain'sinitial_max_budget_per_run; bound secret names are left out at the one place the start secrets are used.EventService. Added, each failing without the code it guards: idle eviction keeps the three, a legacymeta.jsonis taken over (also when the first load fails, with a bound credential next to it, and with an unreadable entry next to it), a retried create, a child on a real service inherits the parent's current values and does not wait for its lock, an encrypted create and an encrypted resume are decrypted, one request gives two analyzers, telemetry reports the conversation's policy, a load under another key or none, and the three no-cipher cases.meta.json'ssecretsnow read the registry inbase_state.json.Issue Number
Fixes #4810.
The issue's literal acceptance criteria ask for the runtime routes to write
meta.jsonas well. They are replaced by the decision recorded in the issue thread, that state the conversation owns is written only tobase_state.jsonand read from there: #4810 (comment)How to Test
Regression tests, each run without its change:
test_eviction_keeps_runtime_policy_analyzer_and_secrets(onmain)NeverConfirmafter evictiontest_mutations_survive_a_server_restart_and_a_later_fork(onmain)test_resume_keeps_the_saved_policy_and_analyzer_over_the_start_fields(resume guard removed)NeverConfirmtest_start_child_conversation_does_not_wait_for_parent_state_lock(lock-taking read)TimeoutErrortest_secrets_an_older_server_left_in_meta_json_are_kept(no legacy read)KeyError: 'ONLY_IN_META'test_secrets_from_an_older_meta_json_survive_a_failed_first_load(the scrub does not carry them)AssertionError: assert 'ONLY_IN_META' in {}(base_state.jsonafter the failed load)test_retry_of_a_create_that_failed_halfway_gets_the_requested_settings(seeding by file absence)NeverConfirmtest_child_inherits_what_its_parent_has_now(seeding removed)NeverConfirmtest_resume_decrypts_an_encrypted_fallback, live and cold (also onmain)gAAAAA...test_conversations_started_from_one_request_have_their_own_analyzertest_conversation_whose_secrets_cannot_be_reloaded_is_not_evictedtest_fork_keeps_secret_values_on_a_server_without_a_cipherNone == 'start-value'test_conversation_whose_analyzer_key_cannot_be_reloaded_is_not_evictedtest_legacy_secrets_this_key_cannot_decrypt_do_not_cost_the_agent_its_key, three cases: a static secret under another key, a lookup secret under another key, a static secret with no keybase_state.jsonis rewritten without the agent's keytest_server_without_a_key_does_not_take_legacy_cipher_text_for_a_valuetest_unreadable_legacy_meta_secret_costs_only_itself(the key read as one mapping)Live, with
control-agent-serverEvery attempt is its own freshly launched agent-server; "restart" is a real process restart on the same state directory. Here and below,
mainismainat3c66af1d, the commit this stack is merged with.The bug and the fix, with the repo's "verify an existing fix" loop. The recipes carry a known-bug marker in a copy of
main's map and were replayed against a server launched frommain, then from this branch (--checkout), two attempts each.xfailmeans the bullet failed with exactly the documented failure;xpassmeans that failure no longer reproduces.mainF08.state-on-diskF08.policy-restartF08.analyzer-restartF08.analyzer-clear-restartF08.secrets-override-restartF08.fork-after-restartF08.child-inherits-currentF08.reload-after-pauseWhat
mainshowed in those attempts:meta.jsonheldconfirmation_policy,security_analyzer,secretsandsecrets_encrypted; a conversation switched to another policy at runtime answered with its creation-time policy after the restart; a command got the secret's old value; a fork, a child and a reload after a sandbox pause all started from the creation-time copy.Whole families on this branch's final code (
cac2960d), to look for regressions next to the fix. In this branch's own map the bullets above carry no marker and are part ofF08. The last column is the same family replayed onmainwithmain's own map:main(3c66af1d), its own mapF08confirmation, security, secretsF10fork, navigate, condense, askmain(F10.ask-agent,F10.ask-agent-running)F04conversation lifecyclemainhas too (F04.create-initial-message-run-false)F12runtime and credentialsmainhas too (F12.sandbox-pause-websocket);F12.docker-runtimeblocked (needs a Docker daemon);F12.docker-startup-timeoutblocked (needs a Docker daemon)F31persistence and limitsmainhas too (F31.takeover-keeps-metadata);F31.storage-retentionblocked (needs a Docker daemon)F33PythonRemoteConversation: run, fork, confirmation, secretsF34TypeScript client: create, run, fork/navigate/ask, confirmmain(F34.conversation-branching)S04local conversation (SDK map)S04.factorylabelled blocked in the mapS13security and confirmation (SDK map)S13.llm-analyzer,S13.confirm-wait,S13.confirm-approve-reject) failed in this run and was blocked onmain: see the note below;S13.confirm-approve-reject,S13.llm-analyzerlabelled blocked in the mapEvery bullet that does not pass on this branch does not pass on
maineither (compared bullet by bullet).mainhas five more that do not pass: the bullets its map marks as known bugs, which this stack fixes (F04.create-secrets-get,F08.secrets-visible,F08.secrets-unsaved-restart,F10.fork-keeps-credentials,F10.fork-run-memory). The three failures the two share are recipes about a side question: afterask_agentthe event count is one higher thanF10.ask-agent,F10.ask-agent-runningandF34.conversation-branchingexpect, onmainas here. I left those recipes alone; they are not about this change.The
S13bullet that did not pass is the live-model one (S13.llm-analyzer): it needs DeepSeek to raterm -rf scratchasHIGH, and the model often saysMEDIUM. Repeated alone four times on each side, it passed once, failed twice and was blocked once on this stack's top branch, and exactly the same onmain. The stack does not touch how a model rates a command.F08.upgrade-from-releaseis part of theF08run: conversations are created by the latest released server (1.62.0), which leaves a start-time secret only inmeta.json, and the same state directory is then restarted on this code. The secret, the policy and the analyzer are all there. With the legacy take-over removed, that bullet fails twice (the command gets an empty secret).Through the UI
The full OpenHands UI (Agent Canvas, built from the
OpenHands/OpenHandsrepository) was run with that repository'sverify-openhandsskill (control-openhands launch --sdk-path <checkout>), once onmain's SDK and agent-server (91e8b5b6) and once on this branch's (ae2e835c), with a real model (DeepSeek flash). That is one merge ofmainbefore this branch's current code commit; the source of the four packages is the same in both (git diff ae2e835c..cac2960dis empty for them). The Canvas has no control that changes confirmation mode on an existing conversation, and it only ever sends lookup secrets, so two steps were made through the REST API: that switch, and the replacement of the secret's value. Everything else was typed and clicked in the UI, and each stack was restarted for real.mainAlwaysConfirm, then a backend restart, then a new commandmeta.jsonread back at every stepconfirmation_policy,security_analyzer,secretsin 29 of 29 read-backsOn
mainthe revert is also written back: once the conversation is loaded after the restart,base_state.jsonholds the creation-time policy again. While the Add-secret form is being filled, the typed value is in that masked field; otherwise no secret value appears in the page (text and DOM), in the API events or in the conversation's state directory, on either side, and the screenshots show only lengths. An independent pass recounted every number in this table from the saved read-backs and step logs.Checks that CI runs only for PRs into
mainThis PR is stacked, so those workflows do not run on it yet. Run locally on the code commit
cac2960d(the head adds only the verification record under.pr/):export_agent_server_openapi.py) is byte-identical tomain's.check_agent_server_rest_api_breakage.py, with oasdiff 1.19.1): passes. What it lists against the 1.62.0 release aremain's own additive changes (the reaction events of feat(agent-server): Conversation reactions, the first experimental feature #6609); with an identical OpenAPI document, this branch adds nothing to them.check_persisted_settings_compat.py): passes, the payloads of the 1.62.0 release included.check_sdk_api_breakage.py): no breaking changes in the three packages.make test-server-schema: passes.v1.62.0) starts a conversation on this branch's SDK.The last line is the mixed-version check. With the four fields taken off
ConversationConfig, as in #4813, the same script ends inAttributeError: 'StoredConversation' object has no attribute 'secrets'.GitHub CI on this branch's head (
5c298f9e: the code commitcac2960dplus the verification record under.pr/): all 14 checks that ran are green.Type
Notes
main's.ConversationConfigandStartConversationRequesthave the same fields as onmain, with the same types, defaults and descriptions. The four fields now come afterpromptinstead of mid-list, so the server's own/openapi.jsonlistsStartConversationRequest's properties in a different order; the key-sorted export does not show that. The only name this PR adds to the SDK isStoredConversationConfig(inopenhands.sdk.conversation.request, re-exported fromopenhands.agent_server.models). In the agent-server,launch.request_security_analyzerand threeEventServicefields (initial_confirmation_policy,initial_security_analyzer,secrets) are new.meta.json's policy and analyzer on every load. On ameta.jsonwritten by this code it finds none, applies its defaults (NeverConfirm, no analyzer) and saves them overbase_state.json; the reset then stays after rolling forward. The secrets inbase_state.jsonare left as they are. Two ways to get there:running(the container died mid-run and its lease expired) loads it with its own code, provided it can create the conversation's stored workspace path: always for a worktree conversation, and for the plain/workspacepath only on a host that can create that directory (otherwise the load fails and writes nothing). With an older host and a container on this code, that load resets the policy. With a host on this code and an older container, the host's load drops the fields frommeta.jsonand the container's next load resets it. The default container image islatest-python, which followsmainand not a release, so a released host gets a newer container with its next pull. I reproduced both sequences in-process, with two checkouts on one conversation directory, the kill and the expired lease simulated by editingbase_state.jsonand removing the lease file, and one shared key; no Docker daemon was available here, so the mount, the proxy routing and the per-conversation key are from reading the code.meta.jsonstill gets the live policy and analyzer as a write-only mirror that this code never reads. It protects older readers and keeps a second copy on disk for a while, which is the thing this PR removes. I did not add it. A narrower step that helps only hosts on this code is to have the host's start-up recovery skip Docker-backed conversations, which also removes a second writer thatmainhas today.**********placeholder. Inside a running process, see point 7 above. Two things remain different frommainthere: a sandbox pause loses the values as a restart does, and a fork does not carry the key inside a security analyzer (it never carried the agent's own model key). The README says so.mainand merged into this stack.meta.jsoncopies as seeds. fix(agent-server): re-read meta.json when loading a persisted conversation #5777 changes the same load and reuse path for another reason. Both PRs replace the in-place patch of the catalog record with a parameter passed down toEventService(secretshere,resume_secretsthere), and fix(agent-server): re-read meta.json when loading a persisted conversation #5777 then writes it intostored.secrets, which this PR removes. A trial merge conflicts inconversation_service.pyandevent_service.py; whichever lands second has to redo that plumbing on top of the other.StoredConversationstill duplicates other state:hook_config,max_iterations,stuck_detection,tagsandworkspace. They are follow-up material;hook_configis the one that can drift through the public API today.mainand rebased onto it after the one below merges; that push is what starts themain-only workflows on it.🤖 Generated with Claude Code
https://claude.ai/code/session_013ArwwMuszm1Nt9r2whddpY