Repository navigation
agents: report unknown fields in agent manifests - #2093
nveerdixit wants to merge 18 commits into
Conversation
b61e511 to
d07e437
Compare
`validate` and `create --dry-run` accepted any top-level key, so a misspelled field such as `egresss:` or `permisions:` looked valid and was echoed back as if it were applied. The server rejected it only when the session was created. doctl now checks flat-manifest field names against an embedded copy of the schema's key tree, per object: - a key within edit distance 2 of a known key in the same object (and shorter than that key) is an error with a "did you mean" hint, using the same rule as the server; - any other unknown key is a warning, since it may be a newer server field; - open objects (config, labels, env, secrets slots, rule match, skill metadata, tool catalog keys) are not checked, and the existing egress checks keep their own errors. The check also runs on `create --dry-run` and on real `create` / `launch`, before any API call, and through config and trigger create. A new `--strict` flag turns every manifest warning into an error. A test compares the embedded key tree to a copy of the schema so drift fails CI. Refs MARSOHS-2583 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
d07e437 to
3ed6251
Compare
vrindavinod-do
left a comment
There was a problem hiding this comment.
Review
I cloned this branch and ran the code. The quality is good. I have one request before approval.
What I verified
- The code builds.
gofmt -landgo vet ./commands/report no problems. - All tests in
./commands/pass. OnlyTestRegistryLogoutfails. It fails because the test machine has no keychain entry. This failure is not related to this change. The statement in the description is correct. TestManifestKeyTreeMatchesSchemaCopyis complete and strong. It walks the schema, resolves$refpointers, followsoneOf,anyOfandallOfbranches, and compares the keys of each closed object in order.- The code reports an unknown field one time only.
createandlaunchuse the early check, then usevalidateAgentManifestSkippingUnknownKeys.config create,trigger createandvalidateeach run the check one time. - The early check runs before each API call and before each side effect.
- The edge cases are correct. I tested non-string keys (
5: x),${VAR}keys, empty keys, root-level lists, legacyapiVersionenvelopes, and tool catalog entries. All of them behave correctly.
This change cannot break the server. It is a client-side check. It can only stop work on a user machine or in a user pipeline.
Problem 1: A user cannot continue after a false positive (most important)
The near-miss rule makes an error, not a warning. The --strict flag only makes the rule more strict. There is no flag to make the rule less strict.
I wrote a probe to find which new field names cause an error. Singular and plural pairs are the risk:
ERROR (root) "tool" -> suggests "tools"
ERROR (root) "secret" -> suggests "secrets"
ERROR (root) "repo" -> suggests "repos"
ERROR (root) "label" -> suggests "labels"
ERROR (root) "mount" -> suggests "mounts"
ERROR permissions "rule" -> suggests "rules"
ERROR model "defaults" -> suggests "default"
ERROR mounts[] "paths" -> suggests "path"
An API can add a singular or plural form of an existing field. If the server adds such a field, an older doctl stops the user. The user cannot run create. The user must wait for a new doctl release.
The only other method is the deprecated apiVersion envelope, because the check ignores it. This method is not documented, and you plan to remove the envelope.
Please add a flag that changes these errors to warnings. The change is small. It replaces "the user is blocked until a new release" with "the user adds a flag and continues". The rest of doctl keeps the server as the authority. A hard error with no alternative is different from that design.
Problem 2: No check finds drift between the schema copy and the server
The test compares the key tree with the copy in testdata/. The copy has the date 2026-11-02. No CI job reads the live schema. As a result, the copy becomes old and no person sees this.
The copy is new today, so the risk is small now. The risk increases with time. This drift is the cause that changes Problem 1 from a theory into a user problem.
Please add a CI job. The job must compare the committed copy with the published schema.
Problem 3: The description of the near-miss rule is not correct
The description says "(and shorter than that key)". The rule in the code is d < len(candidate). The distance must be less than the length of the candidate. The length of the unknown key is not part of the rule. Please correct the table, because reviewers read it.
Problem 4: Confirm the behavior of the server
This change stops manifests that validate accepted before. This includes keepWarm and other camelCase names. The reason given is that the server rejects these names at create time.
This reason is probable, and it makes the change an improvement. It moves the failure to a point before the API call. But the full change depends on this reason. If the server accepts more names than doctl, doctl now stops correct work.
Please confirm the rule with the owner of the server decoder.
Conclusion
Approve after Problem 1. Problems 2, 3 and 4 are important, but they do not stop the merge.
| best, bestDist := "", -1 | ||
| for _, cand := range known { | ||
| d := editDistance(lower, cand) | ||
| if d > 2 || d >= len([]rune(cand)) { |
There was a problem hiding this comment.
This rule makes an error, not a warning. There is no flag to make it less strict.
Singular and plural pairs are the risk. A future server field named tool, secret, repo, label, mount, rule, defaults or paths is within distance 2 of a key in this tree. An older doctl stops such a manifest. The user cannot run create until a new doctl release.
Please add a flag that changes these errors to warnings.
There was a problem hiding this comment.
Added --allow-unknown-fields in 273fbee. It turns the "did you mean" near-miss errors into warnings, so a field newer than this doctl no longer blocks the command. Other errors are unchanged. It is registered on every command that has --strict (validate, create, launch, config create, trigger create/update). It cannot be combined with --strict or --from-config, and tests cover each of these.
There was a problem hiding this comment.
I missed one gap in my earlier reply: trigger create and update accepted --allow-unknown-fields with --from-config. 5bdf889 now rejects it there, as create does, and a config's stored manifest no longer goes through the near-miss check at all.
| // schema (free-text descriptions are removed; only the structure is compared). | ||
| // Keys for server features doctl does not support yet are left out of both the | ||
| // copy and the tree on purpose: a manifest using one gets the "unknown field" | ||
| // warning, which says it may be a newer field. To refresh the copy, copy the |
There was a problem hiding this comment.
This test compares the tree with the committed copy. It does not compare the copy with the live schema. No CI job reads the live schema.
As a result, the copy becomes old and no person sees this. Please add a CI job that compares the committed copy with the published schema.
There was a problem hiding this comment.
Partly addressed in 4062298. The key tree is now generated from commands/testdata/agent.flat.schema.json (go generate ./commands), so a schema refresh is: replace the copy, run the generator. TestManifestKeyTreeIsGenerated fails if the committed tree is stale, and the existing test still cross-checks the keys with a separate walk of the schema. The generated tree is identical to the hand-written one it replaces.
Still open: nothing compares the schema copy with the live schema. The published URL does not resolve from outside DigitalOcean's network, so a job on doctl's public runners likely cannot read it. The schema is edited in the cthulhu monorepo (contracts/agent.flat.schema.json), so the better home for that check is a cthulhu-side workflow, in the style of the existing plano proto sync, that opens a doctl PR when the schema changes. That needs a deploy key and Vault role, so I would do it as a follow-up and not in this PR.
There was a problem hiding this comment.
There is no published URL to compare against. The $id does not resolve in DNS, and the source (contracts/agent.flat.schema.json in cthulhu) is on GHES, which doctl's runners cannot read. A check by hand did find drift: the copy lacked policy_profile, which the server has accepted since MARSOHS-2158, so validate --strict failed on a valid manifest. 357cfc2 refreshes the copy from cthulhu master and adds the key to the coverage fixture. For an ongoing check, I propose a cthulhu-side job that runs when that file changes. doctl is public, so the job can fetch this copy with no credentials and fail when the key sets differ. I would do that as a follow-up.
A field newer than this doctl that sits within two letters of a known key (for example a singular/plural pair) was a hard error with no way past it short of upgrading. --allow-unknown-fields reports those as warnings instead. It is rejected together with --strict and --from-config. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
Review problem 3 (the near-miss rule in the description): fixed. The table now says the distance must be less than the known key's length, matching |
The key tree was kept by hand next to testdata/agent.flat.schema.json, so a schema refresh meant editing about 100 lines to satisfy a failing test. A generator now builds the tree from the copy (go generate ./commands), and TestManifestKeyTreeIsGenerated fails if the committed tree is stale. The generated tree is identical to the hand-written one it replaces. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
Review problem 4 (does the server reject the same names?): I checked the server code in the cthulhu monorepo. The harness-api owner has not confirmed this yet. What the code shows (
Not verified:
I will leave this thread open until the harness-api owner confirms. |
| return nil, err | ||
| } | ||
| if err := reportAgentManifestValidation(validateAgentManifest(manifest)); err != nil { | ||
| v := validateAgentManifest(manifest) |
There was a problem hiding this comment.
This runs for --from-config too, because the config's stored manifest is passed through the same validator. That conflicts with create, which rejects --strict and --allow-unknown-fields with --from-config because a config's manifest was already validated when it was created. Here the flags are registered and accepted.
The stored manifest is the server's JSON form. Any key the server added, or any key from an older schema, becomes a warning, and --strict turns it into an error you cannot fix by editing. I would either skip the unknown-key pass for --from-config or reject the two flags the same way create does.
There was a problem hiding this comment.
Fixed in 5bdf889. trigger create and update now skip the unknown-field pass for a --from-config manifest, since that is the server's stored copy. They also reject --strict and --allow-unknown-fields with --from-config, through the same helper create now uses. TestRunAgentTriggers_FromConfigSkipsUnknownFields covers both commands. A stored manifest with a server-only key (secret) creates the trigger with no warning, and each flag fails before any API call.
| // doctl does not know). Messages carry the full path, for example | ||
| // permissions.network.<key> or mounts[0].<key>. | ||
| // | ||
| // The warning text must not contain "matches a declared", "looks like a |
There was a problem hiding this comment.
This coupling depends on substring matching: config create promotes any warning containing "matches a declared", "looks like a credential" or "name suggests a credential" to an error, and this comment is the only guard. The unknown-field messages put the user's own key name into the text. A key that contains one of those phrases would be promoted to an error. A later rewording of either side would break it silently.
Can the validation result carry a typed severity or a Promote flag on the warning, instead of matching on text? Then neither side depends on the wording.
There was a problem hiding this comment.
Changed in 836f217. The env credential checks now record their warnings in a Credentials subset as they raise them, the same way near misses are recorded, and config create promotes exactly those. No substring match is left, and the comment is gone. New cases in TestRunAgentsConfigCreate_UnknownKeys create a config with an unknown key named after each phrase, which stays a warning. They also check that real credential warnings are still promoted.
trigger create and update with --from-config copy the Agent Config's stored manifest, which is the server's JSON form. Running the unknown-field pass on it turned any key the server knows but this doctl does not into a warning, or into a near-miss error the user could not fix by editing and could not soften. The trigger path now skips the unknown-field pass for --from-config and rejects --strict and --allow-unknown-fields with --from-config, as create already does. Both commands share one helper for that check. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
config create promoted any manifest warning whose text contained "matches a declared", "looks like a credential" or "name suggests a credential" to an error. Unknown-field warnings quote the user's key, so a key named after one of those phrases was promoted too, and rewording either side would have broken the rule without a failing test. The env credential checks now record their warnings in a Credentials subset when they raise them, the same way near misses are recorded for --allow-unknown-fields, and config create promotes exactly that subset. Both moves share one helper. The comment that asked unknown-field messages to avoid the phrases, and the test that enforced it, are gone. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The schema copy lacked the root key policy_profile, which the server has accepted since MARSOHS-2158. validate warned that the server rejects it, and --strict failed on a valid manifest. The copy now matches cthulhu contracts/agent.flat.schema.json at 968f5d189ba6, with free-text descriptions removed as before. Only one key is new: policy_profile. The other changes are values and constraints, and the key check does not read them: the minimax-code harness, egress "none", a required S3 mount endpoint, and the mount path pattern. valid_full.yaml now uses policy_profile so the fixture-coverage test keeps covering every key. Its dry-run golden was regenerated with the origin/main (b55fb88) binary, which reproduced the old golden byte for byte before the change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The refreshed schema copy requires mount paths to match ^/workspace/[^/] (MARSOHS-2661), so the server would reject the fixture's /data mount. Use /workspace/data instead. The dry-run golden was regenerated the way it was first made: the edited fixture was run through `doctl harness-runtime create --dry-run` built from the PR base (81cef80), which reproduces the old golden byte for byte from the old fixture. The other valid_*.yaml fixtures already pass the schema copy. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`triggers create --session-mode reuse` and `triggers update` without --spec or --from-config accepted --strict and --allow-unknown-fields, then sent the request with no check and no message. Both now fail before any API call and say why: --strict only applies to --session-mode=fresh; a reuse trigger has no manifest to check --strict needs a manifest to check; pass --spec rejectManifestFlags holds the flag list, and the --from-config rejection now calls it with its own reason. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…marsohs-2583-review-fixes
On Windows the checkout gives agents_manifest_keys_tree.go CRLF line endings while the generator emits LF, so TestManifestKeyTreeIsGenerated reported the tree as stale. Normalize the committed side before comparing, as the dry-run golden comparison already does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Review notes.
|
--strict on create --dry-run checked only unknown fields, so a manifest with a credential in env passed it and printed the key. The dry run now runs the same post-expansion validator as a real create, so it fails where create would. Also accept an explicit --strict=false or --allow-unknown-fields=false where those flags are rejected, and highlight the path of a top-level unknown key the way a nested one is. Co-authored-by: Cursor <cursoragent@cursor.com>
The key tree was generated from the schema copy by a separate generator, committed, and guarded by a staleness test plus a second schema walker in the tests. Embed the schema and build the tree once at first use instead: one walker, no generated file, nothing to go stale. The built tree is identical to the generated one it replaces. Building it costs about 0.6 ms, once per process and only on commands that check a manifest; the binary grows by the 24 KB schema. Co-authored-by: Cursor <cursoragent@cursor.com>
|
@sanpj2292 thanks. All five are addressed in 9e16491 and 60be14c.
|
|
Thanks @nveerdixit. I checked the fixes against
Rebased onto current Follow-ups before or alongside merge:
|
|
Please resolve the merge conflicts |
…ixes Co-authored-by: Cursor <cursoragent@cursor.com> # Conflicts: # commands/agents.go
The copy matches the published schema of 2026-11-19 key for key. The comment claimed keys were left out on purpose; none are. Name the two keys added since, system_prompt and secrets.<name>.actor, so the next refresh knows what it should pick up. MARSOHS-3157 tracks a drift check on the schema's side. Co-authored-by: Cursor <cursoragent@cursor.com>
|
@SSharma-10 @sanpj2292 merge conflicts are resolved and the follow-ups are done. Conflicts: merged current Follow-ups:
|
Co-authored-by: Cursor <cursoragent@cursor.com> # Conflicts: # commands/agents.go
|
Merged current main (424f37f, which includes #2111, #2112 and #2157) into this branch with an ordinary merge commit, 9ad0312. No rebase and no force-push. One conflict, in Checks run on the merge: |
What
doctl harness-runtime validateandcreate --dry-runaccepted any top-level key in a flat agent manifest. A misspelled field such asegresss:orpermisions:printed "Manifest looks valid", and--dry-runechoed the key back as if it were applied. The server rejects unknown keys, but only when the session is created.doctl now checks field names locally, against an embedded copy of the manifest schema's key tree, one object at a time.
Behavior
--strict--allow-unknown-fields--strictor--from-config.config,labels,env, secret slot names, rulematch, skillmetadata, tool catalog keys)egressapiVersionenvelope manifestsThe check runs in
validate,create --dry-run, realcreateandlaunch(before any API call, including the GitHub auth offer), and throughconfig createandtrigger create.create --dry-runruns the same validation as a real create, after${VAR}expansion, so it fails exactly where create would and then prints no manifest. With only warnings it prints them on stderr and still prints the manifest.--strictapplies to every warning there too, including a credential inenv.Example:
Notes for reviewers
keepWarm) now fail locally invalidate,create,config createandtrigger create. The server already rejected them at create.create --dry-runnow also fails on any error a real create would reject (for example an unknown adapter, or with--stricta credential inenv), where it used to print the manifest.commands/agent.flat.schema.json) and the key tree is built from it once, at first use, by one walker. A schema refresh is: replace the copy. There is no generated file to go stale. Building the tree costs about 0.6 ms once per process, only on commands that check a manifest; the binary grows by the 24 KB schema. The copy itself is still refreshed by hand; a drift check on the schema's side is tracked in MARSOHS-3157. The copy matches the published schema of 2026-11-19 key for key;system_promptandsecrets.<name>.actor, added since, are not in it yet and warn as newer fields. A sibling-pair test pins the only two keys that sit within edit distance 2 of each other in the same object today (mode/model,min/max).--allow-unknown-fieldslets the user continue without waiting for a release.policy_profile, which the server has accepted since MARSOHS-2158. Before,validate --strictfailed on a valid manifest that used it.--from-config: the unknown-field check is skipped, because that manifest is the server's stored copy and the user cannot edit its field names.--strictand--allow-unknown-fieldsfail with a clear error before any API call when there is no manifest for them to check. That applies with--from-config, withtriggers create --session-mode reuse, and withtriggers updatewithout--spec. An explicit--strict=falseasks for nothing and passes. They still have no effect when launching an existing session.Testing
gofmt -l,go vet ./commands/clean.go test ./commands/passes exceptTestRegistryLogout, which also fails on unmodifiedmainon a machine without a native keychain entry.--stricton every command that has it, dry-run and real-create ordering, exactly-once warnings, and a golden file proving valid manifests print the same output as before.validate/create --dry-runagainst a typo, a nested typo, an unknown key and a valid manifest, andcreate --dry-run --strictagainst a credential inenv(fails, prints nothing).🤖 Generated with Claude Code