Skip to content
Myr

Take one sentence where a draft's list is asked for, so kimi's drafts decode

Before adoption: this commit came in with the history the project adopted, so no landing records it.

- Live on dev-oscabriel (914): `smoke --loop --draft` failed after three attempts, each spent as `schema` (draft steps 45, 52 and 41 s). Replaying the drafter's call through a scratch Worker's AI binding showed why: `@cf/moonshotai/kimi-k2.7-code` returned valid JSON in 30-55 s, but with `context` and `outOfScope` as strings where `DraftedAsk` wants arrays, with the schema bare under `json_schema` and named alike. Workers AI does not hold a model to the JSON Schema it asks for. - The fallbacks W9-D12 names don't help: `@cf/zai-org/glm-5.3` (200 s) and `@cf/openai/gpt-oss-120b` (157 s) both spent the 12,000-token output cap and sent JSON cut off mid-string (`unparseable`). DRAFT_MODEL stays kimi. - `DraftedReply` (drafted.ts) is `DraftedAsk` whose two lists of sentences also decode from one sentence, as a list of one; the drafter decodes replies with it and still asks for `DraftedAsk`'s JSON Schema. An empty string is still `schema`. - Test (red first by assertion): binding.test.ts "takes one sentence where the schema asks for a list of them, as a list of one".

authored by oscabriel · committed by oscabriel · parent 177ee96 · Browse files · 3 files+59 added−3 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+59 added−3 removed

  • tests:+25 added−0 removed
  • other:+34 added−3 removed

3 files+59 added−3 removed

modified:packages/drafting/src/drafter/binding.ts+3 added-2 removed
modified:packages/drafting/src/drafted.ts+31 added-1 removed
7 unmodified lines
8 */9import { Brand } from "@repo/brand";10import { AtLeastOne } from "@repo/protocol/domain/common";11import { AskId, LandedSha, ProjectName, RepoPath } from "@repo/protocol/ids";12import { Schema } from "effect";12import { Schema, SchemaTransformation } from "effect";1314/** A string the model writes, bounded so no reply fills the Worker. */15const Text = Schema.NonEmptyString.check(Schema.isMaxLength(4000));16
49 unmodified lines
66});6768export type DraftedAsk = typeof DraftedAsk.Type;6970/**71 * Sentences as a model may send them: a list, or one sentence alone, which72 * decodes as a list of one. Workers AI does not hold a model to the JSON73 * Schema it is asked for: kimi-k2.7-code sent `context` and `outOfScope` as74 * strings on every attempt (914, live on dev-oscabriel).75 */76const Sentences = Schema.Union([77 Schema.Array(Text),78 Text.pipe(79 Schema.decodeTo(80 Schema.Array(Text),81 SchemaTransformation.transform({82 decode: (one: string): readonly string[] => [one],83 encode: (all) => all.join("\n"),84 })85 )86 ),87]);8889/**90 * A model's reply, decoded into a `DraftedAsk`: the same fields, but a91 * list of sentences may come as one sentence. The model is still asked for92 * `DraftedAsk`'s JSON Schema.93 */94export const DraftedReply = Schema.Struct({95 ...DraftedAsk.fields,96 context: Schema.optionalKey(Sentences),97 outOfScope: Schema.optionalKey(Sentences),98});99100/** One file the drafter reads, as text. */101export const ContextFile = Schema.Struct({102 content: Schema.String,103 path: RepoPath,
46 unmodified lines
modified:packages/drafting/test/binding.test.ts+25 added
156 unmodified lines
157 })158 );159160 it.effect(161 "takes one sentence where the schema asks for a list of them, as a list of one",162 () =>163 Effect.gen(function* () {164 // kimi-k2.7-code on dev-oscabriel (914) answered every attempt with165 // `context` and `outOfScope` as strings, whatever the JSON Schema said.166 const reply = JSON.stringify({167 ...encoded,168 context: "An ordinal date is YYYY-DDD.",169 outOfScope: "Changing parse.",170 });171172 expect(yield* draftWith(chat(reply))).toStrictEqual({173 ...drafted,174 context: ["An ordinal date is YYYY-DDD."],175 outOfScope: ["Changing parse."],176 });177 expect(178 yield* Effect.flip(179 draftWith(chat(JSON.stringify({ ...encoded, context: "" })))180 )181 ).toStrictEqual(failure("schema"));182 })183 );184185 it.effect(186 "refuses a test path in the config folder or off the tree as `schema`, so model text never lands as config",187 () =>188 Effect.gen(function* () {189 for (const path of [
54 unmodified lines