Skip to content

Commit 7a6ccda

Browse files
wip v28
1 parent 5a9b758 commit 7a6ccda

19 files changed

Lines changed: 1155 additions & 80 deletions

BITCODE_SPEC_V28.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -457,10 +457,15 @@ Read/Fit result review remains fail-closed:
457457
AssetPack range projection, or finality readback is unavailable.
458458
- staging-testnet Read/Fit QA must run model-backed inference.
459459
`BITCODE_ASSET_PACK_REAL_INFERENCE=1` is the deployment-level switch for the
460-
AssetPack pipeline; it forces every PTRR-capable setup, discovery, synthesis,
461-
validation, and Finish agent off deterministic bring-up branches. A run with
462-
any omitted per-agent `*_USE_PTRR` flag is not an acceptable staging posture
463-
unless the global real-inference flag is present.
460+
AssetPack pipeline. Deployed route-streaming runs should use
461+
`BITCODE_ASSET_PACK_REAL_INFERENCE_PROFILE=bounded`: setup, synthesis,
462+
validation, and Finish stay model-backed while deterministic source-bound
463+
depository discovery preserves enough route budget to synthesize, ship, and
464+
read back the AssetPack. `BITCODE_ASSET_PACK_REAL_INFERENCE_PROFILE=full`
465+
is reserved for long-running sandbox audits outside the deployed streaming
466+
route. A run with omitted per-agent `*_USE_PTRR` flags is not an acceptable
467+
staging posture unless the global real-inference flag and explicit profile
468+
are present.
464469
- manifest-only Deposit supply can satisfy candidate recall but cannot produce
465470
`worthy_fit` unless proof and measurement posture are explicitly visible to
466471
the pipeline input and the downstream readback queries confirm them. Boolean

BITCODE_V28_QA.md

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,7 @@ BITCODE_QA_VERBOSE=true
712712

713713
BITCODE_ENABLE_PIPELINE_HARNESS_API=1
714714
BITCODE_ASSET_PACK_REAL_INFERENCE=1
715+
BITCODE_ASSET_PACK_REAL_INFERENCE_PROFILE=bounded
715716
BITCODE_PIPELINE_HARNESS_MAX_RUNTIME_MS=600000
716717
OPENAI_API_KEY=<OpenAI key for non-mocked Terminal/protocol synthesis>
717718
BITCODE_LLM_PROVIDER=openai
@@ -721,7 +722,7 @@ SENTRY_DSN=<optional V28 alert sink; absence must remain readable blocked readin
721722
722723
Do not set mock flags true on this deployment.
723724
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.
725+
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 deployed streaming posture is the global real-inference flag, `BITCODE_ASSET_PACK_REAL_INFERENCE_PROFILE=bounded`, and a real server-side model credential. Use `BITCODE_ASSET_PACK_REAL_INFERENCE_PROFILE=full` only for long-running sandbox audits outside the deployed route.
725726
726727
## Live Deployment Pass: First-Run Onboarding To Terminal Readiness
727728
@@ -1183,7 +1184,8 @@ keys by name:
11831184
BITCODE_PIPELINE_STREAM_TO_DATABASE=1 \
11841185
BITCODE_PIPELINE_STRUCTURED_DB=1 \
11851186
BITCODE_ASSET_PACK_REAL_INFERENCE=1 \
1186-
BITCODE_SANDBOX_ENV_KEYS=SUPABASE_URL,SUPABASE_SERVICE_ROLE_KEY,OPENAI_API_KEY,BITCODE_ASSET_PACK_REAL_INFERENCE,BITCODE_PIPELINE_HARNESS_MAX_RUNTIME_MS
1187+
BITCODE_ASSET_PACK_REAL_INFERENCE_PROFILE=bounded \
1188+
BITCODE_SANDBOX_ENV_KEYS=SUPABASE_URL,SUPABASE_SERVICE_ROLE_KEY,OPENAI_API_KEY,BITCODE_ASSET_PACK_REAL_INFERENCE,BITCODE_ASSET_PACK_REAL_INFERENCE_PROFILE,BITCODE_PIPELINE_HARNESS_MAX_RUNTIME_MS
11871189
```
11881190
11891191
These Supabase values must be real staging credentials. Placeholder hosts such
@@ -1195,6 +1197,8 @@ uses Vercel automatic OIDC instead of a local Vercel token:
11951197
the deployed route preflight-fails when `BITCODE_ASSET_PACK_REAL_INFERENCE` is
11961198
unset, when `OPENAI_API_KEY` is missing, or when
11971199
`BITCODE_PIPELINE_HARNESS_MAX_RUNTIME_MS` exceeds `600000`.
1200+
When no profile is configured, the deployed route injects
1201+
`BITCODE_ASSET_PACK_REAL_INFERENCE_PROFILE=bounded`.
11981202
11991203
```bash
12001204
curl -N "$BITCODE_UAPI_URL/api/pipeline-harness/asset-pack" \
@@ -1321,9 +1325,13 @@ Observed staging-testnet harness evidence on 2026-05-17:
13211325
synthesis/validation/finish branches unless a phase-specific `*_USE_PTRR=1`
13221326
flag was set; therefore this observed run had zero generation rows and zero
13231327
tool execution rows. The V28 staging posture is now
1324-
`BITCODE_ASSET_PACK_REAL_INFERENCE=1`, which forces every PTRR-capable
1325-
AssetPack branch to produce model-generation telemetry or fail with explicit
1326-
blocked-readiness evidence.
1328+
`BITCODE_ASSET_PACK_REAL_INFERENCE=1`. On the deployed streaming route,
1329+
`BITCODE_ASSET_PACK_REAL_INFERENCE_PROFILE=bounded` is now the required
1330+
profile: setup, synthesis, validation, and Finish produce model-generation
1331+
telemetry while deterministic source-bound discovery preserves budget for a
1332+
complete AssetPack run. Full discovery PTRR remains available through
1333+
`BITCODE_ASSET_PACK_REAL_INFERENCE_PROFILE=full` for long-running sandbox
1334+
audits outside the deployed route.
13271335
- Ledger readback correctly showed zero BTD range, BTC fee, journal, anchor, and
13281336
crypto telemetry rows, and `btd_supply_state.total_minted=0`, because source
13291337
overlay QA evidence cannot mint BTD, claim BTC fee settlement, or anchor
@@ -1374,6 +1382,32 @@ Follow-up local Vercel Sandbox overlay evidence on 2026-05-17:
13741382
reconciliation readback roots, or explicit blocked-readiness, before such a
13751383
candidate can become `worthy_fit`.
13761384
1385+
Second local overlay evidence on 2026-05-17:
1386+
1387+
- Vercel Sandbox run `sbx_XO602gYd3F57rYSyc8NzkPsXIDb7` exported artifacts to
1388+
`.bitcode/pipeline-harness-runs/2026-05-17T20-34-37-584Z-sbx_XO602gYd3F57rYSyc8NzkPsXIDb7/`.
1389+
- The run found and ranked the deposited repository candidate with real
1390+
OpenAI-backed setup and discovery telemetry, 3565 stream lines, prompt/context
1391+
input, raw responses, parsed output, usage, phase, agent, step, failsafe, and
1392+
generation correlation.
1393+
- The run failed closed with `PipelineHarnessTimeoutError` after the configured
1394+
1200000 ms harness budget while still in discovery
1395+
(`asset-pack-plan-implementation-agent`). It did not reach synthesis,
1396+
validation, Finish, shipping, or ledger settlement.
1397+
- The root cause is not a source crash; it is a runtime-shape mismatch between
1398+
the deployed streaming route budget and full PTRR discovery. V28 now separates
1399+
route-streaming real inference (`BITCODE_ASSET_PACK_REAL_INFERENCE_PROFILE=bounded`)
1400+
from full PTRR audits (`BITCODE_ASSET_PACK_REAL_INFERENCE_PROFILE=full`) so
1401+
staging can complete the value-producing Read/Fit -> AssetPack -> Finish path
1402+
inside the Vercel Function window.
1403+
- The run also exposed agent-visible tool registry drift: a risk-admission
1404+
generation requested `lexical-depository-search`, but the PTRR tool executor
1405+
reported `Tool not found: lexical-depository-search`. The deterministic
1406+
depository search had already run before setup agents, so the search result
1407+
was present as pipeline context; V28 still needs agent-visible depository
1408+
search/readback tool registration or prompt tightening before full PTRR audits
1409+
can be considered clean.
1410+
13771411
## 2026-05-13 Staging Deployment Readiness Gate
13781412
13791413
Purpose:

packages/pipeline-hosts/README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,12 @@ token tuple `VERCEL_TOKEN`, `VERCEL_TEAM_ID`, and `VERCEL_PROJECT_ID`. Deployed
7878
Vercel code should use automatic OIDC rather than storing a Vercel token when
7979
possible.
8080
Staging-testnet Read/Fit QA must also set
81-
`BITCODE_ASSET_PACK_REAL_INFERENCE=1`. That single flag forces every
82-
PTRR-capable AssetPack setup, discovery, synthesis, validation, and finish
83-
agent off the deterministic bring-up path. The phase-specific
81+
`BITCODE_ASSET_PACK_REAL_INFERENCE=1`. On the deployed streaming route,
82+
`BITCODE_ASSET_PACK_REAL_INFERENCE_PROFILE=bounded` is the expected profile:
83+
setup, synthesis, validation, and finish stay model-backed, while deterministic
84+
source-bound discovery evidence preserves enough budget to ship and read back
85+
the AssetPack. Set `BITCODE_ASSET_PACK_REAL_INFERENCE_PROFILE=full` only for
86+
long-running sandbox audits outside the deployed route. The phase-specific
8487
`BITCODE_ASSET_PACK_*_USE_PTRR=1` flags remain available for local bisection,
8588
but they are not sufficient as a staging posture because a missed flag silently
8689
turns part of the run back into deterministic evidence.
@@ -132,6 +135,7 @@ BITCODE_SANDBOX_SOURCE_REVISION=31bbc0c5227b6b3aed5d107fd8507d35ec22970a \
132135
BITCODE_SANDBOX_DEPOSIT_HAS_PROOF=1 \
133136
BITCODE_SANDBOX_DEPOSIT_HAS_MEASUREMENT=1 \
134137
BITCODE_ASSET_PACK_REAL_INFERENCE=1 \
138+
BITCODE_ASSET_PACK_REAL_INFERENCE_PROFILE=bounded \
135139
BITCODE_PIPELINE_HARNESS_MAX_RUNTIME_MS=600000 \
136140
pnpm -C packages/pipeline-hosts run qa:asset-pack:sandbox
137141
```

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const TRUSTED_SANDBOX_ENV_KEYS = [
2929
'BITCODE_LLM_PROVIDER',
3030
'BITCODE_LLM_MODEL',
3131
'BITCODE_ASSET_PACK_REAL_INFERENCE',
32+
'BITCODE_ASSET_PACK_REAL_INFERENCE_PROFILE',
3233
'BITCODE_ASSET_PACK_SETUP_PLAN_USE_PTRR',
3334
'BITCODE_ASSET_PACK_COMPREHEND_READ_USE_PTRR',
3435
'BITCODE_ASSET_PACK_DANGER_WALL_USE_PTRR',

packages/pipelines/asset-pack/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"@bitcode/generic-agents-file-pick": "workspace:*",
2525
"@bitcode/generic-agents-read-comprehension": "workspace:*",
2626
"@bitcode/generic-agents-danger-wall": "workspace:*",
27+
"@bitcode/generic-tools-editing": "workspace:*",
2728
"@bitcode/llm-generics": "workspace:*",
2829
"@bitcode/logger": "workspace:*",
2930
"@bitcode/prompts": "workspace:*",
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
import { z } from 'zod';
2+
import { runBoundedStructuredInference } from '../bounded-structured-inference';
3+
4+
const ResultSchema = z.object({
5+
summary: z.string(),
6+
accepted: z.boolean(),
7+
});
8+
9+
function makeExecution(llm?: any) {
10+
const stores: Array<{ namespace: string; key: string; value: unknown }> = [];
11+
const execution: any = {
12+
id: 'root',
13+
store(namespace: string, key: string, value: unknown) {
14+
stores.push({ namespace, key, value });
15+
},
16+
getRoot() {
17+
return execution;
18+
},
19+
child(id: string) {
20+
return {
21+
...execution,
22+
id,
23+
parent: execution,
24+
};
25+
},
26+
};
27+
28+
if (llm) {
29+
execution.llms = {
30+
getDefaultLLM: jest.fn(() => llm),
31+
};
32+
}
33+
34+
return { execution, stores };
35+
}
36+
37+
function resetInferenceEnv() {
38+
delete process.env.BITCODE_ASSET_PACK_REAL_INFERENCE;
39+
delete process.env.BITCODE_ASSET_PACK_REAL_INFERENCE_PROFILE;
40+
delete process.env.OPENAI_API_KEY;
41+
delete process.env.BITCODE_LLM_PROVIDER;
42+
delete process.env.BITCODE_LLM_MODEL;
43+
}
44+
45+
describe('runBoundedStructuredInference', () => {
46+
beforeEach(resetInferenceEnv);
47+
afterEach(resetInferenceEnv);
48+
49+
it('keeps deterministic fallback available when real inference is not required', async () => {
50+
const { execution, stores } = makeExecution();
51+
52+
const result = await runBoundedStructuredInference({
53+
agentName: 'test-agent',
54+
phase: 'setup',
55+
step: 'bounded',
56+
systemPrompt: 'Return JSON.',
57+
userPrompt: 'Return a result.',
58+
schema: ResultSchema,
59+
fallback: () => ({ summary: 'fallback', accepted: false }),
60+
execution,
61+
});
62+
63+
expect(result).toEqual({ summary: 'fallback', accepted: false });
64+
expect(stores).toEqual(
65+
expect.arrayContaining([
66+
expect.objectContaining({
67+
namespace: 'bounded-inference',
68+
key: 'status',
69+
value: 'fallback-no-llm',
70+
}),
71+
])
72+
);
73+
});
74+
75+
it('blocks real inference when no LLM can be resolved', async () => {
76+
process.env.BITCODE_ASSET_PACK_REAL_INFERENCE = '1';
77+
process.env.BITCODE_ASSET_PACK_REAL_INFERENCE_PROFILE = 'bounded';
78+
const { execution, stores } = makeExecution();
79+
80+
await expect(
81+
runBoundedStructuredInference({
82+
agentName: 'test-agent',
83+
phase: 'setup',
84+
step: 'bounded',
85+
systemPrompt: 'Return JSON.',
86+
userPrompt: 'Return a result.',
87+
schema: ResultSchema,
88+
fallback: () => ({ summary: 'fallback', accepted: false }),
89+
execution,
90+
})
91+
).rejects.toThrow(/no configured LLM/i);
92+
93+
expect(stores).toEqual(
94+
expect.arrayContaining([
95+
expect.objectContaining({
96+
namespace: 'bounded-inference',
97+
key: 'status',
98+
value: 'blocked-no-llm',
99+
}),
100+
])
101+
);
102+
});
103+
104+
it('uses the execution LLM for real bounded inference and stores parsed output telemetry', async () => {
105+
process.env.BITCODE_ASSET_PACK_REAL_INFERENCE = '1';
106+
process.env.BITCODE_ASSET_PACK_REAL_INFERENCE_PROFILE = 'bounded';
107+
const llm = jest.fn(async () => ({
108+
content: JSON.stringify({ summary: 'model result', accepted: true }),
109+
usage: { inputTokens: 12, outputTokens: 8, totalTokens: 20 },
110+
metadata: { provider: 'test-provider', model: 'test-model' },
111+
}));
112+
const { execution, stores } = makeExecution(llm);
113+
114+
const result = await runBoundedStructuredInference({
115+
agentName: 'test-agent',
116+
phase: 'setup',
117+
step: 'bounded',
118+
systemPrompt: 'Return JSON.',
119+
userPrompt: 'Return a result.',
120+
schema: ResultSchema,
121+
fallback: () => ({ summary: 'fallback', accepted: false }),
122+
execution,
123+
});
124+
125+
expect(result).toEqual({ summary: 'model result', accepted: true });
126+
expect(llm).toHaveBeenCalledWith(
127+
expect.objectContaining({
128+
config: expect.objectContaining({
129+
responseFormat: 'json',
130+
}),
131+
})
132+
);
133+
expect(stores).toEqual(
134+
expect.arrayContaining([
135+
expect.objectContaining({
136+
namespace: 'bounded-inference',
137+
key: 'status',
138+
value: 'success',
139+
}),
140+
expect.objectContaining({
141+
namespace: 'llm',
142+
key: 'parsedOutput',
143+
}),
144+
])
145+
);
146+
});
147+
});
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import { executionContext } from '@bitcode/generic-tools-editing/execution-context';
2+
import { lexicalDepositorySearchTool } from '../tools/AssetPackLexicalDepositorySearchTool';
3+
4+
describe('lexical depository search tool', () => {
5+
it('reads back the authoritative depository search result from execution context', async () => {
6+
const storedResult = {
7+
schema: 'bitcode.asset-pack.depository-search',
8+
resultState: 'worthy_fit',
9+
resultReasons: ['Selected 1 proof-bearing AssetPack candidate for this Read.'],
10+
read: {
11+
prompt: 'Read deposited source evidence.',
12+
targetArtifactKinds: [],
13+
closureCriteria: [],
14+
failureModes: [],
15+
},
16+
thresholds: {
17+
reviewScore: 0.75,
18+
worthyScore: 0.85,
19+
semanticScore: 0.35,
20+
maxSelectedCandidates: 3,
21+
},
22+
searchedAssetCount: 1,
23+
selectedCandidateAssetIds: ['asset-1'],
24+
selectedCandidates: [
25+
{
26+
assetId: 'asset-1',
27+
title: 'Deposited source asset',
28+
useTier: 'settlement-eligible',
29+
selectedUnits: [],
30+
ranking: {
31+
finalScore: 0.91,
32+
semanticScore: 0.9,
33+
},
34+
verification: {
35+
blockers: [],
36+
warnings: [],
37+
},
38+
recall: {
39+
matchedTerms: ['deposit', 'read'],
40+
},
41+
},
42+
],
43+
rejectedCandidates: [],
44+
blockedCandidates: [],
45+
candidateRanking: [],
46+
embeddingPolicy: {
47+
provider: 'openai',
48+
model: 'text-embedding-3-small',
49+
},
50+
queryRoot: 'sha256:query',
51+
rankingRoot: 'sha256:ranking',
52+
createdAt: '2026-05-17T00:00:00.000Z',
53+
};
54+
const execution = {
55+
findUp: jest.fn((namespace: string, key: string) => {
56+
if (namespace === 'depository/search' && key === 'result') return storedResult;
57+
return undefined;
58+
}),
59+
};
60+
61+
const output = await executionContext.run(execution as any, () =>
62+
lexicalDepositorySearchTool.execute({ repositoryFullName: 'engineeredsoftware/ENGI' }),
63+
);
64+
65+
expect(output).toMatchObject({
66+
schema: 'bitcode.asset-pack.lexical-depository-search-tool-result',
67+
readbackSource: 'execution-store',
68+
resultState: 'worthy_fit',
69+
selectedCandidateAssetIds: ['asset-1'],
70+
searchedAssetCount: 1,
71+
queryRoot: 'sha256:query',
72+
rankingRoot: 'sha256:ranking',
73+
fitResult: {
74+
schema: 'bitcode.asset-pack.fit-result',
75+
resultState: 'worthy_fit',
76+
selectedCandidateAssetIds: ['asset-1'],
77+
},
78+
});
79+
});
80+
});

0 commit comments

Comments
 (0)