Try the New Version in Shadow Mode

In Put a New Version Behind a Flag, you left share at 0, so every hiker still gets v5. v7 passed its eval runs, but those cover only the questions you wrote. Hikers will use other words and languages to ask about other huts and days.

In this lesson, you’ll run v7 on copies of real questions without showing its answers or letting it change anything hikers or wardens see. Then you’ll compare its checks with v5’s and price the calls. Start by choosing which questions v7 gets.

Send a Copy of Each Question to v7

v7 needs real questions before any hiker depends on its answers. In shadow mode, the current version answers the hiker as usual. Once the reply is sent, a copy of the question goes to the new version, whose answer is checked and traced but never shown.

A shadow works like a trainee warden drafting replies nobody sends, except that each draft is a model call you pay for.

Add a shadow share to the flag in config/flags.json:

Language: JSON Filename: config/flags.json
{
  "answer": {
    "current": "v5",
    "next": "v7",
    "share": 0,
    "shadow": 25
  }
}

In flags.js, add the field with a default, so older files still pass, and a function that picks the shadow version:

Language: JavaScript Filename: flags.js
const Flag = z.object({ current: z.string(),
  next: z.string(), share: z.int().min(0).max(100),
  shadow: z.int().min(0).max(100).default(0) });

export function shadowOf(flags, name, bucket) {
  const { next, share, shadow } = flags[name];
  const on = bucket !== null && bucket >= share
    && bucket < shadow;
  return on ? next : null;
}

Buckets from share up to shadow are shadowed, since a hiker below share already gets v7. In flag(), after res.locals.bucket = bucket;, add res.locals.shadow = shadowOf(flags, name, bucket);. Setting "shadow": 0 stops the shadow on the next request.

Keep the Shadow’s Effects to Itself

The shadow must run v7’s live code without reaching a hiker, the wardens’ desk, or state that live requests share. So put the live answer’s steps in a function that live requests and shadows can both call. Create answer.js with export async function runVersion({ id, version, question, current, day, deadline, repeat, shadow }), and move into it the lines of /ask from building the request body through outputReason():

  • Build trace as { traceId: id, promptVersion: version.id } for the model calls.
  • Pass shadow to withFallback() as a new last argument.
  • Take deadline, course 3’s time limit, as a parameter.
  • Keep the checks span’s list in failed, which stays null if there was no answer to check.
  • Call repeat() with passed where the code called repeatFailure().
  • Leave the flags lines from Collect Feedback on Every Answer behind, and return what they need: { answer, path, shown, passed, refused, failed, reason }.

Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Locked learning resources

The full lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Become a Member to join the conversation.