Skip to content

[SD-03] Add atomic draft and private-source authoring - #9

Merged
FlyOverCoderKY merged 2 commits into
mainfrom
claude/sd-03-atomic-provenance
Nov 8, 2026
Merged

FlyOverCoderKY merged 2 commits into
mainfrom
claude/sd-03-atomic-provenance

Conversation

@FlyOverCoderKY

@FlyOverCoderKY FlyOverCoderKY commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

A resolved-ticket learning worker must save derived draft content with its intended private sources. Separate draft and provenance commands leave an interruption window where new text can retain empty or stale source bindings.

Adds optional sourceReferences to direct application createDraft and updateDraft. Supplied references require draft-write and provenance-write authority, bounded validation, and per-reference source access on retries, receipt replay, and postcommit checks. Content and current provenance commit in one existing article transaction. Omitted fields preserve legacy behavior; older publication provenance stays separate. Exact array order participates in command identity, and unknown outcomes retry the original prepared input.

New writes reject malformed/reference URL forms, while historical snapshots retain their original structural and hash verification rules plus current source eligibility gates. Upgrade tests use an exact dev-only registry 0.1.1 application alias to write real old data. The five-operation agent interface keeps its current consent/scopes, omits the new privileged field from public input types, and rejects it through dispatcher, HTTP, and SDK MCP schemas before mutation.

Prepares synchronized candidate 0.1.2 and reconciles verified 0.1.1 publication receipts. Four candidate runtime packages remain exact 0.1.2; Agent Access protocol proof remains exact registry 0.1.1. Reviewed merge, signed-tag publication, and strict released-consumer verification precede SD-03 consumption. Actual host/client/privacy/pilot acceptance stays open.

Validation:

  • Frozen install, formatting, types, synthetic composition, four-package clean-consumer pack/import, and authenticated SDK proof passed locally on Node 24.18.0. Independent source/test/docs review is clean.
  • All 12 changed/upgrade cases passed across real memory/Azurite/D1. Full initial local run passed 429/430; one unchanged D1 retrieval-bound case hit Windows connect EADDRINUSE, then passed on all three backends in isolation.
  • Initial-head CI passed all 430 runtime and all 128 release tests on both Node lanes. Current-head CI must pass all 439 runtime and 128 release cases before merge.
  • Local release regressions passed 125 with 3 Windows symlink skips; Linux CI must execute all 128. UTF-8/control audit passed for all 28 changed/new files.

@github-actions

github-actions Bot commented Nov 8, 2026 •

Copy link
Copy Markdown

OpenRouter review posted (clean). #9 (review)

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
🔒 Security Review ✅ Completed 2026-11-08T01:43:46.633908Z 639da5e Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Copy link
Copy Markdown
Contributor Author

@codex security review

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review

Security review completed. No security issues were found in this pull request.

Reviewed commit: 54073e4db1

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OpenRouter pull-request review

Verdict: issues
Scope: full-pr (full-pr)
Mode: initial
Commit: 54073e4db13a1cd5c13696f79b4616ee4c89fc76
Judge: openai/gpt-5.6-luna
Cost: $0.3250 (lanes $0.3227 + judge $0.0023)

Lanes

  • meta/muse-spark-1.2: ok (3 finding(s), 63.7s, 239489+5669 tokens (63812 cached), 4 tool round(s), via Meta, $0.25)
  • z-ai/glm-5.3-flash: ok (4 finding(s), 339.8s, 1670262+44971 tokens (1465984 cached), 22 tool round(s), via Wafer, $0.0694)

Findings

🟠 Issue 1 — Source-set fingerprint is order-sensitive

packages/application/src/articles.ts:349 · risk · identified by meta/muse-spark-1.2

Failure scenario: two privileged host calls supply the same logical nonempty set of sourceReferences in different orders (e.g., [A,B] vs [B,A]). Because packages/application/src/articles.ts includes sourceReferences verbatim in the command fingerprint payload, the repository treats them as different semantic commands.

Evidence: execute() builds payload from Object.entries(request.input) without sorting/normalizing sourceReferences, then fingerprint(payload). validateReferences() only checks id uniqueness, not canonical order, and sourceSnapshot() preserves input order. Retry/replay therefore diverges instead of coalescing.

Impact is duplicate provenance/revision/audit/job rows, extra generation churn, and non-idempotent replay for the same ticket set. Documentation says the host must supply the "complete" set but does not state order is part of identity.

Checked current callers/tests: tests/atomic-draft-sources.test.ts always uses [firstSource, secondSource] in fixed order; no test asserts order-insensitivity. No normalization in sourceSnapshot or validateReferences.

🔵 Issue 2 — Restricted Omit type for recheck helper masks divergence

packages/application/src/articles.ts:308 · nit · identified by meta/muse-spark-1.2

Failure scenario: a future change adds a field to UpdateDraftInput that CreateDraftInput does not have (or vice-versa). recheckDraftSources(command: Pick<CreateDraftInput, "articleId" | "sourceReferences">) will still type-check for the updateDraft call site while silently dropping any new field from type checking.

Evidence: both createDraft and updateDraft pass recheckDraftSources as recheckCommand with T bound to their respective input types, but the helper is explicitly typed to CreateDraftInput only. The implementation only reads articleId and sourceReferences, so today it is compatible, but the narrowing hides divergence.

Fix is to type it as Pick<CreateDraftInput | UpdateDraftInput, "articleId" | "sourceReferences"> or generic Pick<T, ...>.

Checked callers: createDraft at line ~393 and updateDraft at ~431 both supply the same helper; packages/application/src/types.ts defines the two inputs separately.

🔵 Issue 3 — URL check rejects only :// substring

packages/application/src/articles.ts:197 · nit · identified by meta/muse-spark-1.2

Failure scenario: a caller supplies an opaque identifier that looks like a URL but avoids the :// substring, e.g., https:/evil or data:text/plain,secret, or a protocol-relative //host/path. validateReferences() uses value.includes("://") after boundedText, so such values pass and are stored as PrivateSourceReference fields.

Evidence: packages/application/src/articles.ts validateReferences() loop at line ~200 checks if (value.includes("://")) throw. Tests in tests/atomic-draft-sources.test.ts only assert rejection for https://fictional.invalid/private and do not cover other URL shapes. The doc contract says references must be "opaque identifiers" with no URL/source body.

Risk is persistence of URL-like identifiers that downstream hosts might later interpret as fetchable URLs, widening SSRF/phishing surface despite canRead gating.

No counterevidence found in current validators; requireIdentifier does not forbid : or / beyond boundedText.

🔵 Issue 4 — Explicit sourceReferences: undefined input throws TypeError instead of the documented legacy omission behavior

packages/application/src/types.ts:275 · nit · identified by z-ai/glm-5.3-flash

A plain-JavaScript host (or any caller that builds inputs by spreading, e.g. createDraft(ctx, { ...base, sourceReferences: maybeSources }) where maybeSources is undefined) gets TypeError: Expected bounded JSON data properties from commandSnapshot's canonicalJson(input) instead of the legacy draft-only behavior that the PR text, packages/application/README.md, and docs/COLLECTIONS.md all promise for "omission".

🔵 Issue 5 — Non-array sourceReferences is misclassified as RepositoryCapacityError("source_references") rather than a type error

packages/application/src/articles.ts:173 · nit · identified by z-ai/glm-5.3-flash

A host that sends sourceReferences: null, a string, or a plain object instead of an array receives RepositoryCapacityError("source_references") — the error class that signals a resource-limit condition — rather than a TypeError for malformed input.

🔵 Issue 6 — Docs list recheck points but omit the post-commit source recheck that can reject an already-committed command

docs/COLLECTIONS.md:172 · nit · identified by z-ai/glm-5.3-flash

A host integrator reading docs/COLLECTIONS.md, docs/HOST_COMPOSITION.md, or packages/application/README.md is told the per-reference canRead checks run "on the initial attempt, CAS retry, and exact replay" — but not that the repository also re-runs recheck after a successful commit (packages/application/src/repository.ts calls recheck(latest) after records.transact commits).

🔵 Issue 7 — Re-supplying an unchanged source set on every SD-03 update churns provenance generations, hashes, and immutable rows

packages/application/src/articles.ts:445 · nit · identified by z-ai/glm-5.3-flash

An SD-03-compliant host is instructed to "always supply the complete nonempty set" on each createDraft/updateDraft. When the source set is unchanged between updates, updateDraft still computes stored.provenance.generation + 1 and writes a new immutable provenance:<n> row — there is no short-circuit when the supplied set equals the current snapshot.

Workflow run

Comment thread packages/application/src/articles.ts Resolved
readonly collectionId: string;
readonly draft: ArticleDraft;
/** Supplied references are committed with content and require provenanceWrite. */
readonly sourceReferences?: readonly PrivateSourceReference[];

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Explicit sourceReferences: undefined input throws TypeError instead of the documented legacy omission behavior (nit)

A plain-JavaScript host (or any caller that builds inputs by spreading, e.g. createDraft(ctx, { ...base, sourceReferences: maybeSources }) where maybeSources is undefined) gets TypeError: Expected bounded JSON data properties from commandSnapshot's canonicalJson(input) instead of the legacy draft-only behavior that the PR text, packages/application/README.md, and docs/COLLECTIONS.md all promise for "omission".

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r1-4: Omission means the property is absent from the command object. Explicit undefined is not JSON data and is deliberately rejected by the shared canonical command-snapshot boundary, as with other command fields. We will preserve that boundary rather than silently discard one field before fingerprinting. JavaScript callers should omit it, for example with a conditional spread. We are making this explicit in the API docs and adding a no-mutation regression; this is documentation clarification, not a change to the runtime omission contract.

Comment thread docs/COLLECTIONS.md Resolved
context: { ...governance.context, actorId: caller.principalId },
});
return { next: { ...withoutPendingReview(stored), article } };
const provenance =

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Re-supplying an unchanged source set on every SD-03 update churns provenance generations, hashes, and immutable rows (nit)

An SD-03-compliant host is instructed to "always supply the complete nonempty set" on each createDraft/updateDraft. When the source set is unchanged between updates, updateDraft still computes stored.provenance.generation + 1 and writes a new immutable provenance:<n> row — there is no short-circuit when the supplied set equals the current snapshot.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r1-7: This is intentional and matches setProvenance: explicitly supplying references records a fresh current source snapshot for a NEW accepted mutation, even when its values are unchanged. An exact command replay appends no snapshot/history/Audit/jobs; omission preserves current provenance. The caller's expected application generation fences new commands, and normal history/row/byte admission bounds retained work. Local-agent edits omit this privileged field. SD-03 delivery will persist and retry one exact prepared operation, so duplicate worker delivery does not repeatedly advance generations. We will clarify the explicit-snapshot contract and test replay/omission behavior; semantic source deduplication is a separate optimization, not required for atomic or idempotent delivery.

Copy link
Copy Markdown
Contributor Author

Body-only r1-1 triage: sourceReferences is an ordered array in the exact semantic command payload and source snapshot. Identical retry means the same command ID, original expected generation, and exact payload, including that array order. Reordering the array under the SAME command ID produces RepositoryConflictError before any writes; it cannot append duplicate revision/provenance/Audit/job rows. A different command ID is a separately authorized mutation, with current-generation and capacity gates. There is no order-insensitive-set normalization promise, and changing fingerprint normalization would hide a changed request. The SD-03 worker must durably retain its exact prepared source array before calling KB. We are documenting that and adding create/update regressions for reversed-order conflict, zero mutation, and original exact replay.

The actionable input-hygiene/error-classification and postcommit-recheck documentation findings are being fixed on this same branch.

Copy link
Copy Markdown
Contributor Author

Body-only fixes in 639da5e:

  • r1-3: Newly supplied references reject protocol-relative prefixes and common navigable URL schemes, including malformed https:/ and data: forms. Opaque namespace keys remain supported. The KB never fetches submitted references; trusted source resolvers still establish their meaning and authority.
  • r1-5: Non-array input now produces TypeError; an actual array above the reference limit retains RepositoryCapacityError.

Final compatibility review caught and fixed reuse of the stronger write rule during historical snapshot verification. Historical snapshots retain the original structural rules and exact hash checks; source currentness/publication gates remain mandatory. An exact dev-only alias to the published 0.1.1 application writes real legacy data for upgrade tests. The candidate then reviews/publishes that data, rejects withdrawn eligibility, and rejects those URL-like forms in new writes. No historic rows or old implementation are synthesized/copied.

All 12 changed cases passed on real memory/Azurite/D1; types, formatting, four-package clean pack/import, and authenticated SDK proof passed. New-head CI must run the full 439 runtime and 128 release cases. Intentional exact-order, absent-property, and explicit-snapshot semantics retain their earlier written justifications.

Copy link
Copy Markdown
Contributor Author

@codex security review

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OpenRouter pull-request review

Verdict: clean
Scope: latest-commit (commit-range)
Mode: verify
Commit: 639da5edec3fcae50911c40bac55b4764b0b330c
Judge: openai/gpt-5.6-luna
Cost: $0.1357 (lanes $0.1356 + judge $0.0001)

Lanes

  • meta/muse-spark-1.2: ok (0 finding(s), 33.8s, 70640+3113 tokens (339 cached), 2 tool round(s), via Meta, $0.10)
  • z-ai/glm-5.3-flash: ok (0 finding(s), 177.7s, 365774+31294 tokens (300864 cached), 9 tool round(s), via Together, $0.0344)

Round 2 resolution

  • 🤝 r1-1 disputed — Source-set fingerprint is order-sensitive: Agent rebuttal is justified and is now codified: sourceReferences is defined as an exact ordered array participating in both command fingerprint and source-snapshot hash. Current code in packages/application/src/articles.ts fingerprints the verbatim payload (no sorting) and sourceSnapshot hashes ordered references; verifySourceSnapshot uses historical lexical rules. Docs updated in `docs/C…
  • 6 nit finding(s) from earlier rounds retired (severity floor for follow-up rounds is risk).
  • Open findings after this round: 0 (0 bug-severity).

No structured findings from the successful lane(s).

Workflow run

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review

Security review completed. No security issues were found in this pull request.

Reviewed commit: 639da5edec

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

Copy link
Copy Markdown
Contributor Author

Final gate record for 639da5e:

  • CI run 42435213374 passed all 439 runtime tests and all 128 release tests on Node 22 and 24, with zero skips. Formatting, types, example, four-package clean consumer checks, and authenticated SDK proof all passed.
  • CodeQL passed. OpenRouter review 5815981027 is clean: both actual lanes succeeded and the decoded ledger has zero OPEN findings. Initial full-PR coverage and the entire untruncated nine-file fix diff are verified. Intentional exact-input identity findings retain written justifications.
  • Independent final source/test/docs review is clean. Current-head security receipt: [SD-03] Add atomic draft and private-source authoring #9 (comment) .
  • Copilot was requested through the actual REST reviewer identity by 01:16:58 UTC and again after the fix push. At 01:47:21 there was still no observable review or work-start across reviews, comments, events, checks, and reviewer requests. Applying the documented bounded silent-reviewer fallback; silence is not a passing review and no cause is inferred.

Source merge only. Protected signed-tag publication and complete registry/signature/provenance verification remain required before consuming the new API. Host/client/privacy/pilot gates remain open.

@FlyOverCoderKY
FlyOverCoderKY merged commit 004044b into main Nov 8, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant