Repository navigation
PRD-9772 Report outcome, saved flag and next step on agent writes (#7218) - #43
Merged
Merged
Conversation
…218) * PRD-9772 Answer a batch whose document moved during an earlier flush A batch agent write applies every entry, then waits on each document's save in turn. When an outside rename closed a later document's agent sessions during that wait, the end of the batch read the closed session's document, which is null, and the whole request failed with a 500 (PRD-9773). The batch now keeps each document's written text from right after its edit, so nothing reads a session after the waits. It also marks the pending save of each written document as an agent save at edit time, so the save that runs when the rename closes the document records the refusal for the waiting write, and the entry answers doc-moved with the carried-edit rule instead of reading as written. * PRD-9772 Define the agent write outcome contract in core Every agent write response is to carry three fields: outcome (applied, merged-first, both-kept, refused, projection-held), saved (whether the write's bytes are in the file when the response is sent) and nextStep (retry, re-read, none). The sets are closed and grow only by addition. The wire keeps them as open strings so an older parser never rejects a value a newer server adds, and normalizeAgentWriteOutcome maps an unknown outcome to merged-first or refused by the saved flag, and an unknown next step to re-read, so a tool copy never relays a value it does not know. The agent write, batch, undo, rollback, template, skill and skill-file success schemas gain the fields, and two problem types are registered: both-kept, for a single-document write that landed with both versions of a block kept, and write-replaced, for a write the file on disk replaced because there was no agreed version to merge it with. * PRD-9772 Answer every agent write with its outcome and saved flag Every response from the agent write routes now carries outcome, saved and nextStep, success or not: agent-write, agent-write-md, frontmatter-patch, agent-patch, agent-undo, rollback, lint fix, the template and skill writes, and each entry of the batch write. One module owns the mapping from what happened to the three fields. What changes on the wire: - A write that landed with both versions of a block kept answers 409 urn:ok:error:both-kept (saved, re-read) on the single-document agent routes, so an older tool copy cannot read it as plain success; the routes the app also calls keep their status and gain the fields, and a batch entry stays written. - A write whose own save merged an outside change, or kept both, now says so. Before, only the merge before the write was reported. - A write the file on disk replaced, because there was no agreed version to merge with, answers 409 urn:ok:error:write-replaced instead of 200. - A write whose save or rename carry was still running when the 20 s wait ran out answers 503 save-held (projection-held) instead of a 200 that did not confirm the save. - A write waiting on a rename carry when the server stops answers server-stopped instead of success (review of #7170). - A held save on a document with no agreed version takes the replace rule only when a file is there to take over, and its text says any further write, the agent's own included, triggers the replacement and to tell the user (review of #7120). - The unreleased retryWhen on save-held and nextStep inside the disk-edit-reconciled warning are retired; the top-level nextStep replaces both. Nothing in the app reads either. An outside rename of a document nobody has open no longer leaves a carry record behind (review of #7170). * PRD-9772 Relay the write outcome from the MCP write tools The write, edit, restore_version and lint tools declare outcome, saved and nextStep in their output schemas and return them in structured content on every write result the server answered, success or not. A non-success result now carries structured content that matches the schema, because MCP SDK 1.x clients validate it even on an error result; restore_version's version and preview fields and lint's counts and cwd become optional so a failed write can omit them honestly. A both-kept or projection-held write is reported as an error result whose text opens by saying the write landed and is not to be retried, and a refused write ends with its outcome and next step. A single write puts the fields at the top level; each batch entry and each skill file carries its own. A tool copy that meets an outcome or next step it does not know reports merged-first or refused by the saved flag with a re-read, and never relays the raw value in structured content. An older server that sends none of the fields gets none invented. The write and edit descriptions now say to follow nextStep and never to retry a write that landed, replacing the warnings line (write is at 2,043 of 2,048 characters); the per-outcome meanings live in the output schema descriptions. * PRD-9772 Document write outcomes; drop resolve actions from guidance The MCP reference gains a Write outcomes section: the three fields, the two closed sets, what each outcome means and the move it calls for, how both-kept and projection-held travel as non-success, and that projection-held covers a held local save and a held cloud projection alike. The refusal and held-save paragraphs state each outcome, the no-base hold says any further write, the agent's own included, replaces the document and to tell the user, and the 20 s acknowledgements are described as save-held answers. The bundled skill's conflict reference becomes an outcome table with the move for each, a list of the refusals that need the user, and a Git conflicts section that keeps the git-sync rows as they were. The resolve route, resolve strategies, resolutionOptions and the disk-collision conflict reasons leave the agent-facing docs and skills. A scan in the description contract fails if a served tool, a bundled skill or an agent-facing doc names a resolve action or a disk-collision conflict state outside a Git conflicts section. stale-external-write and pending-conflict, which still exist until the conflict route is retired, are allowed only on the two pages that explain them, and the test fails if either page stops needing them. * PRD-9772 Fix CI reds and the review findings on write outcomes CI: the error-envelope coverage scan found four handlers emitting JSON without successResponse: handleAgentWrite, handleAgentWriteMd, handleFrontmatterPatch and handleAgentPatch. Each now builds its body, answers a both-kept write through respondBothKept (errorResponse, 409) and every other success through successResponse. doc-notice expects the both-kept 409 with its outcome fields. Review, Major: a mistake in the agent's own request (a missing path, malformed frontmatter YAML, frontmatter sent as find and replace, a refused patch value, a reserved name) now answers refused with retry, and its detail keeps the fix hint. One table, REFUSAL_OUTCOMES, maps every refusal type and a test pins it. The meanings no longer ask an agent to wait for a person: none means nothing more to do on this document, and the skill and SKILL.md say to tell the user and carry on. Review, Minors: - The template, skill, skill-file, restore_version and lint fix results open with the landed, do-not-retry line on both-kept and projection-held, like write and edit. - retryWhen on save-held and nextStep inside the disk-edit-reconciled warning shipped in v0.87.4-beta.0 and v0.87.5-beta.1 (not in any stable), so both stay on the wire as deprecated. A response with no outcome now reports none, so a beta save-held is no longer read as refused. - store-refused says to re-read and repeat the edit only if it is missing, matching nextStep. - A rename carry that outlasts the wait, or that the server stops, names the new path and says to re-read there, never to re-create under the old name. - Undo, restore, lint fix, template and skill routes keep their 200 for a save still running at the end of the wait and for a write the file replaced, with the outcome in the fields, so the app's undo does not throw and get repeated. - Mermaid, Excalidraw, text, settings and managed-skill writes carry no outcome until their store reports back, instead of claiming saved. - A templated write with frontmatter still applies the frontmatter when both versions were kept, and says it was not applied when the save is held. - server-factory.conflict-authority: its probes post agent-write-md right after git commits, and under load the save can still be waiting on the Git write hold when the 20 s budget ends, which was a 200 before and is projection-held now; both-kept and write-replaced cannot occur there because nothing changes the file between the read and the probe. The admitted probes now accept 200 applied or 503 projection-held and check the text is in the document; the blocked ones assert refused. Also from the review: link checks and the file index read the text after the save rather than the snapshot, the batch text leads with the landed line and shows each entry's outcome, a both-kept 409 logs at debug, and the docs no longer claim the fields on validation errors, folder, asset and skill-restore results. * PRD-9772 Record the 9.18 MB bundle limit raised by PRD-9771 PRD-9771 (#7203) raised the combined-chunks limit from 9.17 to 9.18 MB without a note in BUNDLE-SIZE.md. Measured on one machine, main alone builds to 9,166,292 B and that branch to 9,175,290 B, against the new 9,180,000 B limit. This branch, rebased onto main, measures 9,175,362 B, so it needs no further raise. * PRD-9772 Fix the official review of the write outcome fields MCP write tools never open a refused result with their success line or report ok: true, whatever the HTTP status: a 200 whose fields say refused (a write the file on disk replaced, on the app-facing routes) is now a failed result, and a refused SKILL.md stops the bundle file writes. A templated write reads its frontmatter patch through the same outcome rules, so a both-kept patch counts as landed. A held batch entry claims no link result and carries the server detail. The normaliser leaves a saved flag or next step the server left out absent. The bundled conflict-resolution reference and mcp.mdx now carry one per-result table of outcome, saved, nextStep and the move, and a scan test checks both against the server mapping and checks that each move is the one its next step asks for. The refused and none meanings say who acts; a deleted or missing file tells the user instead of re-creating the document; a write whose stored bytes diverged answers applied with nextStep re-read. Store-intake records are kept per write: a flush reads the strongest merge whose clock covers its own write without consuming it, and the records are cleared with the document's other state. Skill install keeps its 200 with the fields like the other app-called routes, batch error entries carry the fields once at entry level, agent undo and rollback apply the outside-store omission, and the changeset names the status changes. Its bump is minor under RELEASES.md: four published agent write routes change their status for writes that kept both versions or are still saving. * PRD-9772 Fix the second review of the write outcome fields A templated write whose body landed but whose frontmatter patch failed now reports the body's own outcome as saved, with next step re-read, and its text says to re-read and then patch only the frontmatter. It used to pass on the patch's refused, not saved, retry fields, and a retry would apply the body a second time. A skill install no longer carries outcome fields. The save it waits for flushes pending edits to the skill, not the install, so those fields described another write. Its success schema is strict again. The content-divergence hint now matches next step re-read: the stored text differs from what was sent, so re-read before the next edit. GitOrigin-RevId: 4695845c373d402a844c25dd102a817eba48efc7
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Copybara-translated 1 Inkeep OSS change. Rebase-merge this PR so the prepared commit lands directly on public main.
Linear: this mirror replays a change that already merged upstream, so it must not drive ticket status.
skip PRD-9772