fix(protocol): drop the ineffective video force-full-on-fast-path retry (#145)

forceFullOnFastPath re-issued the NTV2 upload with tryFastUploadCompleted:
false to try to refresh a possibly-expired video resource. Real-machine
testing on a live account + RE of the QQ NT kernel (wrapper.node) proved it
never works:
- the server's fast-path is driven by md5-metadata existence and ignores
  the flag (proton omits a false bool anyway); the retry re-fast-paths
- the kernel itself does no validity check — HandleRspUploadV3 trusts the
  response's fileExist and goes straight to SendUploadSuccFTN

So an expired-but-still-indexed video resource is a platform-level
limitation, not something the upload flow can refresh. Removing the retry
drops two wasted OIDB round-trips per cached-video re-send. The underlying
#145 (receiver '资源已过期' for a server-expired resource) remains a
platform issue, tracked separately.

Tests updated to assert the single-request behaviour.
This commit is contained in:
DrSmoothl committed 2026-06-29 15:32:57 +08:00
1 parent 37f768dd33
commit 053137669a
5 files changed
+29 -162

No files matched your search

+4 -106
View File
@@ -283,112 +283,10 @@ describe('pipeline — runNtv2Upload', () => {
}))).rejects.toThrow(/image fast-upload not available/);
});
// ─────────── forceFullOnFastPath (video stale-resource fallback, #145) ───────────
// Bridge whose sendRawPacket returns a different OIDB response per call,
// so we can model "round 1 fast-paths the main file, round 2 demands the
// bytes after we disable fast-upload".
function makeSequencedBridge(responses: Buffer[]) {
let call = 0;
const sendRawPacket = vi.fn<(cmd: string, body: Uint8Array) => Promise<SendPacketResult>>(
async () => {
const responseData = responses[Math.min(call, responses.length - 1)]!;
call += 1;
return { success: true, gotResponse: true, errorCode: 0, errorMessage: '', responseData };
},
);
return { sendRawPacket };
}
it('forceFullOnFastPath: re-requests with fast-upload disabled when the flagged main file is fast-pathed', async () => {
const bridge = makeSequencedBridge([
// Round 1: server fast-paths the main file (no uKey) but demands nothing.
encodeOidbResponse({ upload: { msgInfo: { msgInfoBody: [], extBizInfo: {} } /* no uKey */ } }),
// Round 2 (fast-upload disabled): server now hands back a uKey.
encodeOidbResponse({
upload: {
uKey: 'fresh-ukey',
ipv4s: [{ ipv4: '1.2.3.4', port: 80 }],
msgInfo: { msgInfoBody: [], extBizInfo: {} },
},
}),
]);
const upload = await runNtv2Upload(baseParams({
bridge,
label: 'video',
uploads: [{
source: 'top',
cmdId: 1003,
bytes: new Uint8Array([1, 2, 3]),
md5: new Uint8Array(16),
sha1: new Uint8Array(20),
forceFullOnFastPath: true,
}],
}));
// Two OIDB requests went out; the second omits tryFastUploadCompleted
// (proton drops `false`), which the server reads as "no fast-upload".
expect(bridge.sendRawPacket).toHaveBeenCalledTimes(2);
const firstReq: any = protobuf_decode<OidbBase<NTV2UploadRichMediaReq>>(bridge.sendRawPacket.mock.calls[0]![1] as Uint8Array);
const secondReq: any = protobuf_decode<OidbBase<NTV2UploadRichMediaReq>>(bridge.sendRawPacket.mock.calls[1]![1] as Uint8Array);
expect(firstReq.body.upload.tryFastUploadCompleted).toBe(true);
expect(secondReq.body.upload.tryFastUploadCompleted ?? false).toBe(false);
// The forced full upload PUT ran, and the returned upload is round 2's.
expect(highway.uploadHighwayHttp).toHaveBeenCalledOnce();
expect(upload.uKey).toBe('fresh-ukey');
});
it('forceFullOnFastPath: no retry when the flagged file gets a uKey on the first try', async () => {
const bridge = makeBridge({
responseData: encodeOidbResponse({
upload: { uKey: 'ukey-1', msgInfo: { msgInfoBody: [], extBizInfo: {} } },
}),
});
await runNtv2Upload(baseParams({
bridge,
uploads: [{
source: 'top', cmdId: 1003, bytes: new Uint8Array([1, 2, 3]),
md5: new Uint8Array(16), sha1: new Uint8Array(20), forceFullOnFastPath: true,
}],
}));
expect(bridge.sendRawPacket).toHaveBeenCalledOnce();
expect(highway.uploadHighwayHttp).toHaveBeenCalledOnce();
});
it('forceFullOnFastPath: no retry for a fast-pathed forward (no bytes to upload)', async () => {
const bridge = makeBridge({
responseData: encodeOidbResponse({ upload: { msgInfo: { msgInfoBody: [], extBizInfo: {} } } }),
});
await runNtv2Upload(baseParams({
bridge,
uploads: [{
source: 'top', cmdId: 1003, bytes: new Uint8Array(0),
md5: new Uint8Array(16), sha1: new Uint8Array(20), forceFullOnFastPath: true,
}],
}));
// bytes.length === 0 → nothing to distrust; the fast-path stands.
expect(bridge.sendRawPacket).toHaveBeenCalledOnce();
expect(highway.uploadHighwayHttp).not.toHaveBeenCalled();
});
it('a fast-pathed sub-file WITHOUT the flag (e.g. thumb) does not trigger a retry', async () => {
const bridge = makeBridge({
responseData: encodeOidbResponse({
// Main fully uploaded (has uKey); thumb fast-pathed (no subFileInfos).
upload: { uKey: 'main-ukey', msgInfo: { msgInfoBody: [], extBizInfo: {} } },
}),
});
await runNtv2Upload(baseParams({
bridge,
uploads: [
{ source: 'top', cmdId: 1001, bytes: new Uint8Array([1]), md5: new Uint8Array(16), sha1: new Uint8Array(20), forceFullOnFastPath: true },
{ source: 0, cmdId: 1002, bytes: new Uint8Array([2]), md5: new Uint8Array(16), sha1: new Uint8Array(20) /* no flag */ },
],
}));
expect(bridge.sendRawPacket).toHaveBeenCalledOnce();
});
// (Removed the forceFullOnFastPath retry tests with the feature itself — real-
// machine testing + kernel RE proved the tryFastUploadCompleted:false retry
// never forces a fresh upload; expired-but-indexed video resources are a
// platform limitation. See #145.)
it('silently skips a sub-file with empty bytes when no fastOnlyError is configured', async () => {
// This mirrors the video-thumb path where bytes are always synthesised
@@ -80,14 +80,14 @@ describe('video-upload', () => {
expect(uploads[1]!.fastOnlyError).toBeUndefined();
});
it('main file distrusts a server fast-path (forceFullOnFastPath); thumb does not (#145)', async () => {
// Group/c2c video resources expire server-side: a fast-path hit can
// reference a stale object the receiver shows as "资源已过期", so the
// main file forces a fresh full upload. The thumb stays fast-path-OK.
it('does NOT set a force-full retry flag on the main file (#145 — proven ineffective)', async () => {
// The old forceFullOnFastPath retry was removed: real-machine + kernel RE
// showed it never forces a fresh upload (the server fast-paths by md5
// metadata regardless of tryFastUploadCompleted). An expired-but-indexed
// video resource is a platform limitation, not an upload-flow fix.
await uploadVideoMsgInfo({} as any, true, 12345, FINGERPRINT);
const uploads = vi.mocked(pipeline.runNtv2Upload).mock.calls[0]![0].uploads;
expect(uploads[0]!.forceFullOnFastPath).toBe(true);
expect(uploads[1]!.forceFullOnFastPath).toBeUndefined();
expect((uploads[0] as unknown as Record<string, unknown>).forceFullOnFastPath).toBeUndefined();
});
it('uploadInfo carries TWO entries (main mp4 + thumb jpg) with subFileType 0 and 100', async () => {
+4 -6
View File
@@ -326,15 +326,13 @@ describe('parseMessage', () => {
}], { bridge, groupId: 123456 });
// The video main file carries real bytes but the server fast-paths it
// (fileExist:true, no uKey) — #145's forceFullOnFastPath re-issues the
// OIDB request with fast-upload disabled, so two packets go out.
expect(bridge.sendRawPacket).toHaveBeenCalledTimes(2);
// (fileExist:true, no uKey). The send trusts that single fast-path
// response — the old forceFullOnFastPath retry was removed (proven
// ineffective, see #145), so exactly ONE OIDB request goes out.
expect(bridge.sendRawPacket).toHaveBeenCalledTimes(1);
expect(bridge.sendRawPacket).toHaveBeenNthCalledWith(1, 'OidbSvcTrpcTcp.0x11ea_100', expect.any(Uint8Array));
expect(bridge.sendRawPacket).toHaveBeenNthCalledWith(2, 'OidbSvcTrpcTcp.0x11ea_100', expect.any(Uint8Array));
const firstReq = protobuf_decode<OidbBase<NTV2UploadRichMediaReq>>(bridge.sendRawPacket.mock.calls[0]![1] as Uint8Array);
const secondReq = protobuf_decode<OidbBase<NTV2UploadRichMediaReq>>(bridge.sendRawPacket.mock.calls[1]![1] as Uint8Array);
expect(firstReq.body.upload.tryFastUploadCompleted).toBe(true);
expect(secondReq.body.upload.tryFastUploadCompleted ?? false).toBe(false);
expect(protoElems).toHaveLength(1);
expect(protoElems[0].commonElem?.serviceType).toBe(48);
expect(protoElems[0].commonElem?.businessType).toBe(21);
+15 -38
View File
@@ -51,16 +51,6 @@ export interface MediaSubFileUpload {
* Omit if the caller guarantees bytes always exist (e.g. video thumb
* always has FALLBACK_THUMB bytes). */
fastOnlyError?: string;
/** When true and the server fast-paths THIS sub-file (returns no uKey)
* even though we hold real bytes for it, `runNtv2Upload` re-issues the
* whole OIDB request with `tryFastUploadCompleted: false` to force a
* fresh full upload. Video sets this on the main file: group/c2c video
* resources expire server-side, so a fast-path hit can reference a
* stale object the receiver renders as "资源已过期". The thumb leaves
* this off — a cached thumb is harmless and not worth re-pushing the
* whole (potentially 100 MB) main video for. Forwarding paths carry no
* bytes (`bytes.length === 0`), so this never fires for them. */
forceFullOnFastPath?: boolean;
}
export interface NtV2UploadParams {
@@ -195,24 +185,18 @@ export async function runNtv2Upload(params: NtV2UploadParams): Promise<NTV2Uploa
return session;
};
// Run whatever PUTs the given `upload` response asks for. Returns true
// when a sub-file flagged `forceFullOnFastPath` was fast-pathed by the
// server (no uKey) while we hold real bytes for it — the caller uses
// that to force a non-fast-upload retry.
const runPuts = async (upload: NTV2UploadRespBody): Promise<boolean> => {
// Run whatever PUTs the given `upload` response asks for.
const runPuts = async (upload: NTV2UploadRespBody): Promise<void> => {
let didPut = false;
let staleFastPath = false;
for (const sub of uploads) {
const target = sub.source === 'top' ? upload : upload.subFileInfos?.[sub.source];
const uKey = target?.uKey ?? '';
// No uKey: the server fast-pathed this sub-file (or msgInfo is absent
// entirely). When we actually hold bytes for it, the server is
// reusing a cached resource — surface it, and flag a stale fast-path
// when the caller asked us to distrust it for this sub-file.
// entirely) — it already holds (or claims to hold) the resource, so
// there are no bytes to push for it.
if (!uKey || !upload.msgInfo) {
if (!uKey && upload.msgInfo && sub.bytes.length > 0) {
log.debug('%s fast-upload hit for sub=%s (server reusing cached resource)', label, String(sub.source));
if (sub.forceFullOnFastPath) staleFastPath = true;
}
continue;
}
@@ -241,26 +225,19 @@ export async function runNtv2Upload(params: NtV2UploadParams): Promise<NTV2Uploa
if (!didPut) {
log.debug('%s fast-upload hit (server already had bytes)', label);
}
return staleFastPath;
};
let upload = await requestUpload(true);
const staleFastPath = await runPuts(upload);
// A flagged sub-file (video main) was fast-pathed to a server resource
// that may have expired. Re-issue without fast-upload so the server
// allocates a fresh resource and demands the bytes, then redo the PUTs
// against that response — the returned `upload` (and its msgInfo) must
// be the one we actually pushed bytes to.
if (staleFastPath) {
log.debug('%s forcing full upload — fast-path resource may be stale/expired', label);
upload = await requestUpload(false);
const stillFastPathed = await runPuts(upload);
if (stillFastPathed) {
log.debug('%s server still fast-pathed after forcing full upload — resource may remain stale', label);
}
}
// NOTE: a previous attempt re-issued the request with
// `tryFastUploadCompleted: false` when the server fast-pathed the main video,
// on the theory it would force a fresh upload of a possibly-expired resource.
// Real-machine testing + kernel RE proved that ineffective — the server's
// fast-path is driven by md5-metadata existence and ignores the flag, and the
// QQ NT kernel itself does no validity check either (HandleRspUploadV3 trusts
// `fileExist` and reports success). An expired-but-still-indexed video
// resource is a platform-level limitation, not something the upload flow can
// refresh. See #145.
const upload = await requestUpload(true);
await runPuts(upload);
return upload;
}
@@ -457,12 +457,6 @@ export async function uploadVideoMsgInfo(
sha1: video.sha1Blocks,
subFileIndex: 0,
fastOnlyError: 'video fast-upload not available (server requires bytes)',
// Distrust a server fast-path for the main video: group/c2c video
// resources expire server-side, so reusing a cached object can show
// "资源已过期" on the receiver even though the send "succeeded".
// When we hold the real bytes, force a fresh full upload instead.
// (Forwarding carries no bytes, so this never fires there.) See #145.
forceFullOnFastPath: true,
},
{
source: 0, // upload.subFileInfos[0]