Skip to content

Commit 896a590

Browse files
wip v28
1 parent 0072df2 commit 896a590

18 files changed

Lines changed: 220 additions & 34 deletions

.env.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ BITCODE_DEBUG_STOP_AFTER_PLAN=false
1111
BITCODE_EXECUTION_DEBUG=false
1212
BITCODE_LLM_MODEL=<default Bitcode LLM model>
1313
BITCODE_LLM_PROVIDER=<default Bitcode LLM provider>
14+
BITCODE_ASSET_PACK_REAL_INFERENCE=false
15+
BITCODE_ENABLE_PIPELINE_HARNESS_API=false
16+
BITCODE_PIPELINE_HARNESS_MAX_RUNTIME_MS=600000
1417
BITCODE_LOG_FULL_PROMPTS=false
1518
BITCODE_LOG_FULL_PROMPTS_CORRELATION_IDS=
1619
BITCODE_LOG_FULL_TRACES=false

BITCODE_SPEC_V28.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,9 @@ Acceptance criteria:
360360
rows are re-embedded and the matching function/schema still agree;
361361
- the Fit result must expose ranking quality, rejection reasons, proof roots,
362362
dedupe/materialization roots where available, and finality/readiness status;
363-
- AssetPack synthesis must be protocol-specified and deterministic; if source
363+
- AssetPack synthesis must be protocol-specified and reproducibly evidenced;
364+
deterministic bring-up branches are regression scaffolds, while
365+
staging-testnet commercial QA must run model-backed PTRR inference. If source
364366
materialization, settlement, BTC fee broadcast, ledger anchor, or BTD range
365367
issuance is not live, the result must state that blocker rather than imply
366368
delivery or minting;
@@ -385,8 +387,8 @@ The active host capability contract is:
385387

386388
- isolated Firecracker microVM execution on Amazon Linux 2023;
387389
- default working directory `/vercel/sandbox`;
388-
- stable documented runtimes `node24`, `node22`, and `python3.13`, with
389-
`node24` as the default Bitcode harness runtime;
390+
- stable documented runtimes `node26`, `node24`, `node22`, and `python3.13`,
391+
with `node24` as the default Bitcode harness runtime;
390392
- `vercel-sandbox` user with sudo available for setup;
391393
- ephemeral filesystem, requiring evidence export before sandbox stop;
392394
- command execution, command log collection, file upload/download, exposed
@@ -441,6 +443,12 @@ Read/Fit result review remains fail-closed:
441443
- `blocked_readiness` is mandatory when source materialization, model/tool
442444
credentials, telemetry persistence, BTC fee, ledger anchor, settlement,
443445
AssetPack range projection, or finality readback is unavailable.
446+
- staging-testnet commercial Read/Fit QA must run model-backed inference.
447+
`BITCODE_ASSET_PACK_REAL_INFERENCE=1` is the deployment-level switch for the
448+
AssetPack pipeline; it forces every PTRR-capable setup, discovery, synthesis,
449+
validation, and Finish agent off deterministic bring-up branches. A run with
450+
any omitted per-agent `*_USE_PTRR` flag is not an acceptable staging posture
451+
unless the global real-inference flag is present.
444452
- manifest-only Deposit supply can satisfy candidate recall but cannot produce
445453
`worthy_fit` unless proof and measurement posture are explicitly visible to
446454
the pipeline input and the downstream readback queries confirm them.
@@ -463,6 +471,10 @@ Read/Fit result review remains fail-closed:
463471
from credential posture, with OpenAI accepted when `OPENAI_API_KEY` is the
464472
only model credential present. A provider pin without a matching forwarded
465473
credential is not an admissible reason to require that provider.
474+
- the deployed staging trigger may use Vercel's automatic Sandbox OIDC, but it
475+
still needs a server-side model credential such as `OPENAI_API_KEY`, real
476+
Supabase admin/service-role credentials for telemetry persistence, and a
477+
runtime budget that is shorter than the enclosing Vercel Function window.
466478

467479
### Gate 4: Terminal AssetPack Range Detail
468480

BITCODE_V28_QA.md

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -710,12 +710,18 @@ NEXT_PUBLIC_MCP_UPGRADES=true
710710
NEXT_PUBLIC_BITCODE_QA_VERBOSE=true
711711
BITCODE_QA_VERBOSE=true
712712

713-
OPENAI_API_KEY=<OpenAI key for non-mocked Terminal/protocol synthesis if enabled>
713+
BITCODE_ENABLE_PIPELINE_HARNESS_API=1
714+
BITCODE_ASSET_PACK_REAL_INFERENCE=1
715+
BITCODE_PIPELINE_HARNESS_MAX_RUNTIME_MS=600000
716+
OPENAI_API_KEY=<OpenAI key for non-mocked Terminal/protocol synthesis>
717+
BITCODE_LLM_PROVIDER=openai
718+
BITCODE_LLM_MODEL=<optional pinned OpenAI generation model>
714719
SENTRY_DSN=<optional V28 alert sink; absence must remain readable blocked readiness>
715720
```
716721
717722
Do not set mock flags true on this deployment.
718723
Do not point the Supabase custom provider token/userinfo URLs at localhost; Supabase cloud must be able to call the deployed Bitcode origin.
724+
Do not deploy staging-testnet Read/Fit QA with `BITCODE_ASSET_PACK_REAL_INFERENCE` unset or false. Per-agent `*_USE_PTRR` flags are only diagnostic overrides; the staging posture is the global real-inference flag plus a real server-side model credential.
719725
720726
## Live Deployment Pass: First-Run Onboarding To Terminal Readiness
721727
@@ -1145,8 +1151,10 @@ evidence must remain QA-only, must report
11451151
and must not be used for source-revision settlement, ledger finality, or a
11461152
commercial `worthy_fit` claim.
11471153
If the heavyweight pipeline exceeds the staging function window, set
1148-
`BITCODE_PIPELINE_HARNESS_MAX_RUNTIME_MS` below that window; the expected result
1149-
is a `PipelineHarnessTimeoutError` artifact with the last execution and stream
1154+
`BITCODE_PIPELINE_HARNESS_MAX_RUNTIME_MS` below that window. The deployed
1155+
streaming route declares an 800 second ceiling, so staging should start with
1156+
`BITCODE_PIPELINE_HARNESS_MAX_RUNTIME_MS=600000`; the expected timeout result is
1157+
a `PipelineHarnessTimeoutError` artifact with the last execution and stream
11501158
events, not a missing artifact.
11511159
11521160
Omit `BITCODE_SANDBOX_DEPOSIT_HAS_PROOF` and
@@ -1160,7 +1168,8 @@ keys by name:
11601168
```bash
11611169
BITCODE_PIPELINE_STREAM_TO_DATABASE=1 \
11621170
BITCODE_PIPELINE_STRUCTURED_DB=1 \
1163-
BITCODE_SANDBOX_ENV_KEYS=SUPABASE_URL,SUPABASE_SERVICE_ROLE_KEY,OPENAI_API_KEY
1171+
BITCODE_ASSET_PACK_REAL_INFERENCE=1 \
1172+
BITCODE_SANDBOX_ENV_KEYS=SUPABASE_URL,SUPABASE_SERVICE_ROLE_KEY,OPENAI_API_KEY,BITCODE_ASSET_PACK_REAL_INFERENCE,BITCODE_PIPELINE_HARNESS_MAX_RUNTIME_MS
11641173
```
11651174
11661175
These Supabase values must be real staging credentials. Placeholder hosts such
@@ -1169,6 +1178,9 @@ sandbox can execute but every stream-event insert fails with transport errors.
11691178
11701179
On Vercel staging/preview, prefer the deployed streaming trigger because it
11711180
uses Vercel automatic OIDC instead of a local Vercel token:
1181+
the deployed route preflight-fails when `BITCODE_ASSET_PACK_REAL_INFERENCE` is
1182+
unset, when `OPENAI_API_KEY` is missing, or when
1183+
`BITCODE_PIPELINE_HARNESS_MAX_RUNTIME_MS` exceeds `600000`.
11721184
11731185
```bash
11741186
curl -N "$BITCODE_UAPI_URL/api/pipeline-harness/asset-pack" \
@@ -1238,6 +1250,9 @@ Pass criteria:
12381250
blocked-readiness.
12391251
- Generation/tool rows appear before any model/tool-mediated Fit quality claim
12401252
can be accepted.
1253+
- For the staging-testnet commercial pass, generation rows must be non-zero
1254+
because `BITCODE_ASSET_PACK_REAL_INFERENCE=1` is required. A completed run
1255+
with zero generation rows is only deterministic bring-up evidence.
12411256
- Parsed/cast generation output is stored when a ThriceifiedGeneration parser
12421257
runs, so operators can compare raw model text with typed Fit/search evidence.
12431258
- Query 03 still shows no AssetPack range, BTC fee, ledger anchor, settlement,
@@ -1276,12 +1291,13 @@ Observed staging-testnet harness evidence on 2026-05-17:
12761291
`deliverable_pipeline_runs.status='completed'`, 603 deliverable pipeline
12771292
events, 12 completed phase rows, 40 completed agent-step rows, and no running
12781293
phase or agent rows for the run.
1279-
- The default harness path uses deterministic setup/discovery/synthesis/
1280-
validation/finish agents unless a phase-specific `*_USE_PTRR=1` flag is set;
1281-
therefore this observed run had zero generation rows and zero tool execution
1282-
rows. A model/tool-mediated commercial Fit claim still requires generation
1283-
and tool rows with prompt, raw response, parsed/cast output, provider/model,
1284-
usage, and phase/agent/step correlation.
1294+
- The default harness path previously used deterministic setup/discovery/
1295+
synthesis/validation/finish branches unless a phase-specific `*_USE_PTRR=1`
1296+
flag was set; therefore this observed run had zero generation rows and zero
1297+
tool execution rows. The V28 staging posture is now
1298+
`BITCODE_ASSET_PACK_REAL_INFERENCE=1`, which forces every PTRR-capable
1299+
AssetPack branch to produce model-generation telemetry or fail with explicit
1300+
blocked-readiness evidence.
12851301
- Ledger readback correctly showed zero BTD range, BTC fee, journal, anchor, and
12861302
crypto telemetry rows, and `btd_supply_state.total_minted=0`, because source
12871303
overlay QA evidence cannot mint BTD, claim BTC fee settlement, or anchor

packages/pipeline-hosts/README.md

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ leaving enough telemetry for SQL readback.
99

1010
- Firecracker microVM isolation on Amazon Linux 2023.
1111
- Default working directory: `/vercel/sandbox`.
12-
- Default runtime: `node24`; documented runtime options are `node24`,
13-
`node22`, and `python3.13`.
12+
- Default runtime: `node24`; documented runtime options are `node26`,
13+
`node24`, `node22`, and `python3.13`.
1414
- The sandbox user is `vercel-sandbox` and can use `sudo`.
1515
- Filesystem state is ephemeral. Evidence must be exported before stop, then
1616
persisted to Bitcode storage or database projections.
@@ -69,13 +69,28 @@ trusted command environment. For local Vercel Sandbox creation, either pull
6969
token tuple `VERCEL_TOKEN`, `VERCEL_TEAM_ID`, and `VERCEL_PROJECT_ID`. Deployed
7070
Vercel code should use automatic OIDC rather than storing a Vercel token when
7171
possible.
72+
Staging-testnet commercial Read/Fit QA must also set
73+
`BITCODE_ASSET_PACK_REAL_INFERENCE=1`. That single flag forces every
74+
PTRR-capable AssetPack setup, discovery, synthesis, validation, and finish
75+
agent off the deterministic bring-up path. The phase-specific
76+
`BITCODE_ASSET_PACK_*_USE_PTRR=1` flags remain available for local bisection,
77+
but they are not sufficient as a staging posture because a missed flag silently
78+
turns part of the run back into deterministic evidence.
7279
`BITCODE_LLM_PROVIDER` and `BITCODE_LLM_MODEL` may pin the generation model.
7380
When they are absent, the commercial runtime chooses OpenAI if `OPENAI_API_KEY`
7481
is the only model credential present. A provider pin is forwarded only when the
7582
matching provider credential is also forwarded; stale pins without credentials
7683
are stripped so staging does not silently require an unavailable model service.
7784
Database streaming requires a real Supabase URL and service-role key; placeholder
7885
`.env.local` values fail preflight before a sandbox is created.
86+
The deployed streaming route declares an 800 second Vercel Function window; keep
87+
`BITCODE_PIPELINE_HARNESS_MAX_RUNTIME_MS` at or below `600000` there so the
88+
route still has time to collect and stream the blocked-readiness artifact if the
89+
sandbox budget expires. Local CLI harness runs can use a larger sandbox budget
90+
when the calling process is not the limiting host. On deployed/runtime
91+
production, the route preflight-fails without
92+
`BITCODE_ASSET_PACK_REAL_INFERENCE=1`, without `OPENAI_API_KEY`, or with a
93+
larger harness runtime budget.
7994

8095
## Live QA
8196

@@ -108,6 +123,8 @@ BITCODE_SANDBOX_SOURCE_COMMIT=31bbc0c5227b6b3aed5d107fd8507d35ec22970a \
108123
BITCODE_SANDBOX_SOURCE_REVISION=31bbc0c5227b6b3aed5d107fd8507d35ec22970a \
109124
BITCODE_SANDBOX_DEPOSIT_HAS_PROOF=1 \
110125
BITCODE_SANDBOX_DEPOSIT_HAS_MEASUREMENT=1 \
126+
BITCODE_ASSET_PACK_REAL_INFERENCE=1 \
127+
BITCODE_PIPELINE_HARNESS_MAX_RUNTIME_MS=600000 \
111128
pnpm -C packages/pipeline-hosts run qa:asset-pack:sandbox
112129
```
113130

packages/pipeline-hosts/src/dev/run-asset-pack-sandbox-harness.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,16 @@ const TRUSTED_SANDBOX_ENV_KEYS = [
2828
'BITCODE_PIPELINE_BTC_NETWORK',
2929
'BITCODE_LLM_PROVIDER',
3030
'BITCODE_LLM_MODEL',
31+
'BITCODE_ASSET_PACK_REAL_INFERENCE',
32+
'BITCODE_ASSET_PACK_SETUP_PLAN_USE_PTRR',
33+
'BITCODE_ASSET_PACK_COMPREHEND_READ_USE_PTRR',
34+
'BITCODE_ASSET_PACK_DANGER_WALL_USE_PTRR',
35+
'BITCODE_ASSET_PACK_DISCOVERY_USE_PTRR',
36+
'BITCODE_ASSET_PACK_SYNTHESIS_USE_PTRR',
37+
'BITCODE_ASSET_PACK_VALIDATION_USE_PTRR',
38+
'BITCODE_ASSET_PACK_READY_TO_INSTRUCT_USE_PTRR',
39+
'BITCODE_ASSET_PACK_VALIDATION_READY_TO_FINISH_USE_PTRR',
40+
'BITCODE_ASSET_PACK_FINISH_DELIVER_USE_PTRR',
3141
'BITCODE_PIPELINE_HARNESS_MAX_RUNTIME_MS',
3242
] as const;
3343

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import {
2+
isAssetPackRealInferenceEnabled,
3+
shouldUseAssetPackPtrr,
4+
shouldUseAssetPackPtrrForAgent,
5+
} from '../runtime-inference-policy';
6+
7+
describe('AssetPack runtime inference policy', () => {
8+
it('keeps deterministic branches disabled by default', () => {
9+
const env = {} as NodeJS.ProcessEnv;
10+
11+
expect(isAssetPackRealInferenceEnabled(env)).toBe(false);
12+
expect(shouldUseAssetPackPtrr('BITCODE_ASSET_PACK_SYNTHESIS_USE_PTRR', env)).toBe(false);
13+
expect(shouldUseAssetPackPtrrForAgent('BITCODE_ASSET_PACK_DISCOVERY_USE_PTRR', 'plan-implementation', env)).toBe(false);
14+
});
15+
16+
it('enables all PTRR-capable branches through the commercial real-inference flag', () => {
17+
const env = { BITCODE_ASSET_PACK_REAL_INFERENCE: '1' } as NodeJS.ProcessEnv;
18+
19+
expect(isAssetPackRealInferenceEnabled(env)).toBe(true);
20+
expect(shouldUseAssetPackPtrr('BITCODE_ASSET_PACK_SYNTHESIS_USE_PTRR', env)).toBe(true);
21+
expect(shouldUseAssetPackPtrrForAgent('BITCODE_ASSET_PACK_DISCOVERY_USE_PTRR', 'plan-implementation', env)).toBe(true);
22+
});
23+
24+
it('keeps existing phase and per-agent PTRR flags for targeted diagnosis', () => {
25+
expect(
26+
shouldUseAssetPackPtrr('BITCODE_ASSET_PACK_READY_TO_INSTRUCT_USE_PTRR', {
27+
BITCODE_ASSET_PACK_READY_TO_INSTRUCT_USE_PTRR: 'true',
28+
} as NodeJS.ProcessEnv)
29+
).toBe(true);
30+
expect(
31+
shouldUseAssetPackPtrrForAgent('BITCODE_ASSET_PACK_VALIDATION_USE_PTRR', 'last', {
32+
BITCODE_ASSET_PACK_VALIDATION_LAST_USE_PTRR: 'yes',
33+
} as NodeJS.ProcessEnv)
34+
).toBe(true);
35+
});
36+
});

packages/pipelines/asset-pack/src/agents/discovery-agents.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
* Discovery Phase Agents for the AssetPack Pipeline
33
*
44
* Discovery agents default to deterministic, source-bound structured evidence
5-
* for live Read/Fit pipeline reliability. The heavyweight PTRR variants remain
6-
* available with BITCODE_ASSET_PACK_DISCOVERY_USE_PTRR=1.
5+
* for bounded local regression reliability. Staging/commercial runs should set
6+
* BITCODE_ASSET_PACK_REAL_INFERENCE=1 to force the heavyweight PTRR variants.
77
*/
88

99
import { factoryAgentWithPTRR } from '@bitcode/agent-generics';
@@ -28,6 +28,7 @@ import {
2828
createAssetPackDiscoveryPhaseAssessComplexityAgentPrompt,
2929
AssetPackDiscoveryPhaseAssessComplexityAgentPromptSteps
3030
} from './prompts/assess-complexity-prompt';
31+
import { shouldUseAssetPackPtrrForAgent } from '../runtime-inference-policy';
3132

3233
// ==================== UNDERSTAND REQUIREMENTS AGENT ====================
3334

@@ -595,10 +596,7 @@ export async function AssetPackDiscoveryPhaseAssessComplexityAgent(
595596
}
596597

597598
function shouldUseDiscoveryPtrr(agent: string): boolean {
598-
return (
599-
process?.env?.BITCODE_ASSET_PACK_DISCOVERY_USE_PTRR === '1' ||
600-
process?.env?.[`BITCODE_ASSET_PACK_DISCOVERY_${agent.toUpperCase().replace(/[^A-Z0-9]+/g, '_')}_USE_PTRR`] === '1'
601-
);
599+
return shouldUseAssetPackPtrrForAgent('BITCODE_ASSET_PACK_DISCOVERY_USE_PTRR', agent);
602600
}
603601

604602
function resolveDiscoveryRead(input: any, execution: any): string {

packages/pipelines/asset-pack/src/agents/finish/deliver-asset-pack-to-destination-agent.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
resolveDeliveryMechanismTemplateFromExecution,
1515
resolveWrittenAssetTypeFromExecution,
1616
} from '../../semantic-resolution';
17+
import { shouldUseAssetPackPtrr } from '../../runtime-inference-policy';
1718

1819
const FinishDeliveryOutputSchema = z.object({
1920
status: z.enum(['delivered','partial']).default('delivered'),
@@ -69,7 +70,7 @@ export default async function deliverAssetPackToDestination(input: any, executio
6970
// Build tool plan via output.useTools using agent PTRR Try step instructions
7071
// when explicitly enabled. The default staging finish path records local
7172
// delivery evidence without claiming a third-party pull request.
72-
const result = process?.env?.BITCODE_ASSET_PACK_FINISH_DELIVER_USE_PTRR === '1'
73+
const result = shouldUseAssetPackPtrr('BITCODE_ASSET_PACK_FINISH_DELIVER_USE_PTRR')
7374
? await AssetPackFinishDeliverAgent(
7475
{
7576
writtenAssetType: dtype,

packages/pipelines/asset-pack/src/agents/implementation/asset-pack-synthesize-artifacts-agent.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { PROMPTPART_SPECIFIC_AGENT_ASSETPACKSYNTHESIZEARTIFACTS_PTRRREFINE_PURPO
1616
import { PROMPTPART_SPECIFIC_AGENT_ASSETPACKSYNTHESIZEARTIFACTS_PTRRRETRY_PURPOSE } from '@bitcode/prompts/raw_promptparts/specific/promptpart_specific_agent_assetpacksynthesizeartifacts_ptrrretry_purpose';
1717
import { z } from 'zod';
1818
import { AssetPackWrittenAssetType } from '../../types/AssetPackWrittenAssetType';
19+
import { shouldUseAssetPackPtrr } from '../../runtime-inference-policy';
1920

2021
const AssetPackSynthesisInputSchema = z.object({
2122
read: z.string().optional(),
@@ -101,7 +102,7 @@ export default async function assetPackSynthesizeArtifacts(input: any, execution
101102
execution?.get?.('pipeline', 'deliveryMechanismTemplate') ??
102103
execution?.findUp?.('pipeline', 'deliveryMechanismTemplate') ??
103104
storedPipelineInput?.deliveryMechanismTemplate;
104-
const result = process?.env?.BITCODE_ASSET_PACK_SYNTHESIS_USE_PTRR === '1'
105+
const result = shouldUseAssetPackPtrr('BITCODE_ASSET_PACK_SYNTHESIS_USE_PTRR')
105106
? await AssetPackSynthesizeArtifactsAgent(
106107
{
107108
...input,

packages/pipelines/asset-pack/src/agents/setup/asset-pack-comprehend-read-agent.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
*/
99

1010
import { bitcodeSetupReadComprehensionAgent } from '@bitcode/generic-agents-read-comprehension';
11+
import { shouldUseAssetPackPtrr } from '../../runtime-inference-policy';
1112

1213
export const AssetPackComprehendReadAgent = bitcodeSetupReadComprehensionAgent;
1314

@@ -27,7 +28,7 @@ export async function runComprehendReadAgent(input: any, execution: any) {
2728
phase: 'setup',
2829
beforeAgent: 'danger-wall'
2930
};
30-
const out = process?.env?.BITCODE_ASSET_PACK_COMPREHEND_READ_USE_PTRR === '1'
31+
const out = shouldUseAssetPackPtrr('BITCODE_ASSET_PACK_COMPREHEND_READ_USE_PTRR')
3132
? await AssetPackComprehendReadAgent(agentInput, execution)
3233
: buildDeterministicReadComprehension(agentInput, execution);
3334
try {

0 commit comments

Comments
 (0)