Repository navigation
feat: add opt-in bounded no-output rate-limit retry #54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| import { createRequire } from 'node:module'; | ||
| import { createHash } from 'node:crypto'; | ||
| import { readFile, writeFile } from 'node:fs/promises'; | ||
| import Ajv2020 from 'ajv/dist/2020.js'; | ||
| import addFormats from 'ajv-formats'; | ||
| import standaloneCode from 'ajv/dist/standalone/index.js'; | ||
| import { COMIC_BUILD_RESULT_CANDIDATE as pin } from '../src/comic-manifest/candidate-contract.js'; | ||
| const require = createRequire(import.meta.url); | ||
| const lock = JSON.parse(await readFile(new URL('../package-lock.json', import.meta.url))); | ||
| for (const [name, version] of Object.entries({ ajv: '8.20.0', 'ajv-formats': '3.0.1' })) { | ||
| if (require(`${name}/package.json`).version !== version || lock.packages[`node_modules/${name}`].version !== version) throw new Error('Validator dependency mismatch'); | ||
| } | ||
| const bytes = await readFile(process.argv[2]); | ||
| if (bytes.length !== pin.byte_size || 'sha256:' + createHash('sha256').update(bytes).digest('hex') !== pin.sha256) throw new Error('Candidate schema identity mismatch'); | ||
| const schema = JSON.parse(bytes); | ||
| if (schema.$id !== pin.schema_id) throw new Error('Candidate schema ID mismatch'); | ||
| const ajv = new Ajv2020({ strict: true, strictRequired: false, strictTypes: false, ownProperties: true, code: { source: true, esm: true, lines: true } }); | ||
| addFormats(ajv); | ||
| ajv.addSchema(schema); | ||
| await writeFile(new URL('../src/comic-manifest/generated/result-v1.1-candidate.js', import.meta.url), | ||
| `// Generated from local ${pin.repository}@${pin.commit}; ${pin.source_path}; ${pin.sha256}; ${pin.byte_size} bytes.\n// Unreleased candidate; rebuild with scripts/generate-comic-result-candidate.mjs.\nimport { createRequire } from 'node:module';\nconst require = createRequire(import.meta.url);\n` + standaloneCode(ajv, { result: schema.$id })); |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| // Local candidate only; not a released contract or production adoption. | ||
| export const COMIC_BUILD_RESULT_CANDIDATE = Object.freeze({ | ||
| "repository": "DefinitelySecureStudio/codex", | ||
| "commit": "780de1c7e3b76e02f43f0a594991e3cf7fe874f8", | ||
| "version": "1.1.0", | ||
| "status": "unreleased-local-candidate", | ||
| "schema_id": "urn:definitely-secure:contract:comic-manifest:1.1.0:comic-build-result", | ||
| "source_path": "schemas/json/comic-manifest/v1.1/comic-build-result.schema.json", | ||
| "byte_size": 32330, | ||
| "sha256": "sha256:aee6887e056ca709717f579c46e98c9da4c5d9214735af7137ec457767ed231d" | ||
| }); |
3,972 changes: 3,972 additions & 0 deletions
3,972
src/comic-manifest/generated/result-v1.1-candidate.js
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| import { createHash } from 'node:crypto'; | ||
| import { canonicalJson } from '../prompt-sdk/canonical-json.js'; | ||
| import { parseComicManifestJson } from './parse-json.js'; | ||
| import { validateLocalSemantics } from './semantics.js'; | ||
| import { buildOutputCompatibility } from './output-compatibility.js'; | ||
| import { validateComicManifest } from './validate.js'; | ||
| import { result as schema } from './generated/result-v1.1-candidate.js'; | ||
| const failure = code => ({ valid: false, diagnostics: [{ stage: 'candidate', code }] }); | ||
| const same = (a, b) => canonicalJson(a) === canonicalJson(b); | ||
|
|
||
| /** Explicit, unreleased local candidate. The stable v1 entry point never selects it. */ | ||
| export function validateComicBuildResultCandidate(source, productionSource) { | ||
| const parsed = parseComicManifestJson(source); | ||
| if (!parsed.valid) return parsed; | ||
| try { | ||
| if (!schema(parsed.value)) return failure('SCHEMA_INVALID'); | ||
| } catch { return failure('SCHEMA_INVALID'); } | ||
| finally { schema.errors = null; } | ||
| const value = parsed.value; | ||
| const noOutput = value.execution.transformations.some(t => t.output_digests.length === 0); | ||
| const code = validateLocalSemantics(value, noOutput); | ||
| if (code) return failure(code); | ||
| const production = validateComicManifest(productionSource); | ||
| if (!production.valid || production.value.kind !== 'comic-production') return failure('PRODUCTION_INVALID'); | ||
| const p = production.value; | ||
| if (!same(value.production, { production_id: p.production_id, revision: p.revision, identity: production.identity }) | ||
| || !same(value.inputs, p.inputs)) return failure('PRODUCTION_LINK'); | ||
| if (['public', 'internal', 'confidential', 'restricted'].indexOf(value.classification) | ||
| < ['public', 'internal', 'confidential', 'restricted'].indexOf(p.classification)) return failure('CLASSIFICATION'); | ||
| if (noOutput && !same(value.execution.transformations[0].input_digests, | ||
| [p.inputs.canon.artifact.sha256, p.inputs.prompts[0].identity.sha256])) return failure('ACTUAL_INPUTS'); | ||
| const compatible = buildOutputCompatibility(production, { value }); | ||
| if (compatible) return compatible; | ||
| const canonical = canonicalJson(value); | ||
| return { valid: true, value, diagnostics: [], identity: { canonicalization: 'studio-json-v1', | ||
| byte_size: Buffer.byteLength(canonical), sha256: 'sha256:' + createHash('sha256').update(canonical).digest('hex') } }; | ||
| } | ||
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Comic Manifest schema permits
inputs.promptsto be empty, so a schema-valid production with no prompt bindings and a no-output transformation containing only the canon digest reaches this expression and throws while readingprompts[0].identity. A validation API should return anACTUAL_INPUTS/production diagnostic for this supported shape rather than crashing; derive the expected inputs without assuming a first prompt.Useful? React with 👍 / 👎.